Does anyone know how to create a plugin for the class Magento\Quote\Model\Cart\Data\CartItemFactory method public function create(array $data): CartItem?
I have tried creating before, after, and around plugins but didn't work. below is the reference code:
di.xml:
<type name="Magento\Quote\Model\Cart\Data\CartItemFactory"> <plugin name="custom_store_qty" type="Vendor\Module\Plugin\Model\Cart\Data\CartItemFactory" sortOrder="1" /> </type> Vendor\Module\Plugin\Model\Cart\Data\CartItemFactory.php:
<?php namespace Vendor\Module\Plugin\Model\Cart\Data; class CartItemFactory { public function aroundCreate(\Magento\Quote\Model\Cart\Data\CartItemFactory $subject, callable $proceed) { //Custom logic //die("--"); } } Note: I need to add a new parameter in the addProductsToCart graphql mutation. ex:
mutation { addProductsToCart( cartId: "jdAxK6pbDHsMCQvHG0Uc98esIRbG2YZy" cartItems: { sku: "product-sku" quantity: 2 test_attribute: "test attribute data as additional option." } } Thank you.