I currently have this Plugin, which is just this at the moment:
di.xm
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Quote\Model\Quote\Item">
<plugin name="weight_override" type="Ibex\Options\Model\Plugin\Weight" sortOrder="1" />
</type>
</config>
Weight.php
namespace Ibex\Options\Model\Plugin;
use Magento\Quote\Model\Quote;
class Weight
{
public function beforeSetProduct(\Magento\Quote\Model\Quote\Item $subject, $product)
{
// logging to test override
$logger = \Magento\Framework\App\ObjectManager::getInstance()->get('\Psr\Log\LoggerInterface');
$logger->debug('Test');
$weight = $product->getWeight();
$logger->debug($weight);
return $product;
}
}
?>
Nothing fancy yet, and the debugging is working. However, it's causing this error at the moment:
PHP Fatal error: Uncaught Error: Call to a member function setStoreId() on null in /pro/vendor/magento/module-quote/Model/Quote/Item.php:425
Stack trace:
#0 /pro/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Quote\Model\Quote\Item->setProduct(NULL, 'cat_p', 'catalog_product', 'product', false, Object(Magento\Catalog\Model\Product\Type\Simple),
Object(Magento\Catalog\Model\Product\Link\Proxy), Array, Object(Magento\Catalog\Model\Product\Url), Array,
Object(Magento\Catalog\Model\Product\OptionFactory), NULL, NULL, true, true, Object(Magento\Catalog\Helper\Product), Object(Magento\Framework\Module\Manager),
Object(Magento\Framework\Data\CollectionFactory), Object(Magento\Catalog\Model\Product\Type\Interceptor), Object(Magento\Catalog\Model\Product\Media\Config),
Object(Magento\Catalog\Model\Product\Attribute\Source\Status\Proxy), Object(Magento\Catalog\Model\Product\Visibility),
Object(Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory),
Object(Magento\Catal in /pro/vendor/magento/module-quote/Model/Quote/Item.php on line 425
And for some context, here's the chunk of the core file that's referenced:
public function setProduct($product)
{
if ($this->getQuote()) {
$product->setStoreId($this->getQuote()->getStoreId());
$product->setCustomerGroupId($this->getQuote()->getCustomerGroupId());
}
$this->setData('product', $product)
->setProductId($product->getId())
->setProductType($product->getTypeId())
->setSku($this->getProduct()->getSku())
->setName($product->getName())
->setWeight($this->getProduct()->getWeight())
->setTaxClassId($product->getTaxClassId())
->setBaseCost($product->getCost());
$stockItem = $product->getExtensionAttributes()->getStockItem();
$this->setIsQtyDecimal($stockItem ? $stockItem->getIsQtyDecimal() : false);
$this->_eventManager->dispatch(
'sales_quote_item_set_product',
['product' => $product, 'quote_item' => $this]
);
return $this;
}
What could be causing this error?