我正在尝试在过去的3-4天内使用/为该函数创建一个around-Plugin:公共函数checkQuoteItemQty位于./vendor/magento/module-catalog-inventory/Model/StockStateProvider.php我收到以下错误, 请帮忙!
[08-Jul-2018 17:41:48 UTC] PHP致命错误:未捕获TypeError:参数3传递给MyWebsite \ Mycode \ Model \ StockStateProvider \ Plugin :: aroundcheckQuoteItemQty()必须是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),Object(Closure),Object(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 \ Fram ework \拦截(对象(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;
}
}