Magento 2 Widget - Неустранимая ошибка: допустимый объем памяти 792723456 байт исчерпан (попытался выделить 400560128 байт) - PullRequest
0 голосов
/ 07 мая 2019

Я пытаюсь создать виджет "Самые продаваемые товары".

Виджет отображается в нужном месте, но не содержит данных. После того, как я попытался напечатать вывод, появляется эта ошибка - «Неустранимая ошибка: допустимый объем памяти 792723456 байт исчерпан (попытался выделить 400560128 байт)». После поиска я обнаружил, что существует проблема с выделением памяти, поэтому я попытался выделить больший объем памяти, такой как 2G, 4G, даже 16G, но ошибка все еще существует. Пожалуйста, помогите. Вот мой код -

<?php
namespace Aakash\TopSeller\Block\Widget;

class Bestsellerdproduct extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
{
    protected $_template = 'widget/bestsellerdproduct.phtml';

    protected $DEFAULT_PRODUCTS_COUNT = 10;
    protected $DEFAULT_IMAGE_WIDTH = 150;
    protected $DEFAULT_IMAGE_HEIGHT = 150;
    protected $_productsCount;
    protected $httpContext;
    protected $_resourceFactory;
    protected $_catalogProductVisibility;
    protected $_productCollectionFactory;
    protected $_imageHelper;
    protected $_cartHelper;
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Magento\Reports\Model\ResourceModel\Report\Collection\Factory $resourceFactory,
        \Magento\Reports\Model\Grouped\CollectionFactory $collectionFactory,
        \Magento\Reports\Helper\Data $reportsData,
        array $data = []
    ) {
        $this->_resourceFactory = $resourceFactory;
        $this->_collectionFactory = $collectionFactory;
        $this->_reportsData = $reportsData;
        $this->_imageHelper = $context->getImageHelper();
        $this->_cartHelper = $context->getCartHelper();
        parent::__construct($context, $data);
    }

    public function imageHelperObj(){
        return $this->_imageHelper;
    }
    /**
        get featured product collection
    */
    public function getBestsellerProduct(){
        $limit = $this->getProductLimit();

        $resourceCollection = $this->_resourceFactory->create('Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection')->setPageSize($limit);
        return $resourceCollection;
    }

    /**
        Get the configured limit of products
    */
    public function getProductLimit() {
        if($this->getData('productcount')==''){
            return $this->DEFAULT_PRODUCTS_COUNT;
        }
        return $this->getData('productcount');
    }
    public function getProductimagewidth() {
        if($this->getData('imagewidth')==''){
            return $this->DEFAULT_IMAGE_WIDTH;
        }
        return $this->getData('imagewidth');
    }

    public function getProductimageheight() {
        if($this->getData('imageheight')==''){
            return $this->DEFAULT_IMAGE_HEIGHT;
        }
        return $this->getData('imageheight');
    }
    public function getAddToCartUrl($product, $additional = [])
    {
        return $this->_cartHelper->getAddUrl($product, $additional);
    }

    public function getProductPriceHtml(
        \Magento\Catalog\Model\Product $product,
        $priceType = null,
        $renderZone = \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
        array $arguments = []
    ) {
        if (!isset($arguments['zone'])) {
            $arguments['zone'] = $renderZone;
        }
        $arguments['zone'] = isset($arguments['zone'])
        ? $arguments['zone']
        : $renderZone;
        $arguments['price_id'] = isset($arguments['price_id'])
        ? $arguments['price_id']
        : 'old-price-' . $product->getId() . '-' . $priceType;
        $arguments['include_container'] = isset($arguments['include_container'])
        ? $arguments['include_container']
        : true;
        $arguments['display_minimal_price'] = isset($arguments['display_minimal_price'])
        ? $arguments['display_minimal_price']
        : true;

        $priceRender = $this->getLayout()->getBlock('product.price.render.default');

        $price = '';
        if ($priceRender) {
            $price = $priceRender->render(
                \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
                $product,
                $arguments
            );
        }
        return $price;
    }
}  

Этот метод показывает ошибку -

    public function getBestsellerProduct(){
        $limit = $this->getProductLimit();

        $resourceCollection = $this->_resourceFactory->create('Magento\Sales\Model\ResourceModel\Report\Bestsellers\Collection')->setPageSize($limit);
        return $resourceCollection;
    }
...