dongqijuan3786 2019-05-07 09:14
浏览 92

Magento 2 Widget - 致命错误:允许的内存大小为792723456字节耗尽(尝试分配400560128字节)

I'm trying to make "Best Selling Products" widget.

The widget is showing on the desired location but it contains no data. After I tried to print the output, this error pops up - "Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 400560128 bytes)". After searching I've found out there's memory allocation issue so I tried to allocate some higher amount of memory like 2G, 4G, even 16G but the error is still there. Kindly Help. Here's my code-

<?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;
    }
}  

This method is showing the error -

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

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

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于这个复杂问题的解释说明
    • ¥50 三种调度算法报错 采用的你的方案
    • ¥15 关于#python#的问题,请各位专家解答!
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败