Magento 2插件适用于/public_html/vendor/magento/module-catalog-inventory/Model/StockStateProvider.php

时间:2018-07-08 18:06:00

标签: php magento magento2

在过去的3-4天里,我尝试使用/创建该功能的插件:./vendor/magento/module-catalog-inventory/Model/StockStateProvider.php中的公共功能checkQuoteItemQty。 我收到以下错误,请帮忙!

  

[2018年7月8日17:41:48 UTC] PHP致命错误:未被捕获的TypeError:传递给MyWebsite \ Mycode \ Model \ StockStateProvider \ Plugin :: aroundcheckQuoteItemQty()的参数3必须是Magento \ CatalogInventory \的实例Model \ StockStateProvider,Magento \ CatalogInventory \ Model \ Stock \ Item的实例,在第135行的/home/rapidpdh/public_html/vendor/magento/framework/Interception/Interceptor.php中调用,并在/ home / rapidpdh / public_html /中定义app / code / MyWebsite / Mycode / Model / StockStateProvider / Plugin.php:39
  堆栈跟踪:
   #0 /home/MyWebsite/public_html/vendor/magento/framework/Interception/Interceptor.php(135):MyWebsite \ Mycode \ Model \ StockStateProvider \ Plugin-> aroundcheckQuoteItemQty(Object(Magento \ CatalogInventory \ Model \ StockStateProvider \ Interceptor),对象(关闭),对象(Magento \ CatalogInventory \ Model \ Stock \ Item),1、1、1)
   #1 /home/MyWebsite/public_html/vendor/magento/framework/Interception/Interceptor.php(153):Magento \ CatalogInventory \ Model \ StockStateProvider \ Interceptor-> Magento \ Framework \ Interception {closure}(Object(Magento \ CatalogInventory \ Model \ Stock \ Item),在第39行的/home/MyWebsite/public_html/app/code/MyWebsite/Mycode/Model/StockStateProvider/Plugin.php中为1、1

这是我的代码:

<?php

namespace MyWebsite\Mycode\Model\StockStateProvider;
use Magento\CatalogInventory\Model\StockStateProvider;
use Magento\Catalog\Model\ProductFactory;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\CatalogInventory\Model\Spi\StockStateProviderInterface;
use Magento\Framework\Locale\FormatInterface;
use Magento\Framework\Math\Division as MathDivision;
use Magento\Framework\DataObject\Factory as ObjectFactory;
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\CatalogInventory\Api\StockStateInterface;
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList;

class Plugin 
{
    protected $mathDivision;
    protected $localeFormat;
    protected $objectFactory;
    protected $productFactory;
    protected $qtyCheckApplicable;

    public function __construct(
        MathDivision $mathDivision,
        FormatInterface $localeFormat,
        ObjectFactory $objectFactory,
        ProductFactory $productFactory,
        $qtyCheckApplicable = true
    ) {
        $this->mathDivision = $mathDivision;
        $this->localeFormat = $localeFormat;
        $this->objectFactory = $objectFactory;
        $this->productFactory = $productFactory;
        $this->qtyCheckApplicable = $qtyCheckApplicable;
    }



    public function aroundcheckQuoteItemQty(\Magento\CatalogInventory\Model\StockStateProvider $subject, \Closure $proceed , \Magento\CatalogInventory\Model\StockStateProvider $stockItem, $qty, $summaryQty, $origQty = 0) 
    {

        // do something 
        // before 


        // this will run the core addProduct function
        $returnValue = $proceed();        

        // below code is executed after product is added to cart
        if ($returnValue) {
            // do something
            // after adding product to cart
            // your code goes here

        }

        return $returnValue;   

    }

}

0 个答案:

没有答案