I am trying to add multiple configurable products to cart using a custom REST API request. For that I call the existing save function for each products. I’m able to add upto product options. But when I try to add extension attributes, it’s is not working as expected. Instead of that, I’m getting error message "Fatal Error: 'Uncaught Error: Cannot instantiate interface Magento\Quote\Api\Data\CartItemExtensionInterface in ../vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:9
Whenever I try to include \Magento\Quote\Api\Data\CartItemExtensionInterface
in constructor, this error message is alone occurs. I am doing like below
use Magento\Quote\Api\Data\CartItemExtensionInterface; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\Api\ExtensionAttributesFactory; use Magento\Quote\Api\Data\CartItemInterface; class MultiItemsCart extends \Magento\Quote\Model\Quote\Item\Repository implements MultiItemsCartInterface { /** * Quote repository. * * @var \Magento\Quote\Api\CartRepositoryInterface */ protected $ quoteRepository; protected $ serviceProcessor; protected $ quoteItemRepository; /** * @var \Magento\Quote\Api\Data\CartItemInterfaceFactory */ public $ cartItem; public $ productOption; public $ extensionAttributes; /** * @param \Magento\Quote\Api\CartRepositoryInterface $ quoteRepository */ public function __construct( \Magento\Quote\Api\CartRepositoryInterface $ quoteRepository, \Magento\Framework\Webapi\ServiceInputProcessor $ serviceProcessor, \Magento\Quote\Model\Quote\Item\Repository $ quoteItemRepository, \Magento\Quote\Api\Data\CartItemInterface $ cartItem, \Magento\Quote\Api\Data\ProductOptionInterface $ productOption, \Magento\Quote\Api\Data\CartItemExtensionInterface $ extensionAttributes, array $ cartItemProcessors = [] ) { $ this->quoteRepository = $ quoteRepository; $ this->serviceProcessor = $ serviceProcessor; $ this->quoteItemRepository =$ quoteItemRepository; $ this->itemDataFactory = $ itemDataFactory; $ this->cartItem = $ cartItem; $ this->productOption = $ productOption; $ this->extensionAttributes = $ extensionAttributes; } /** * Returns greeting message to user * * @api * @param mixed $ cartItems * @return array */ public function multiItemsCart($ cartItems) { foreach($ cartItems as $ cartItem){ $ this->cartItem->setSku($ cartItem['sku']); $ this->cartItem->setQuoteId($ cartItem['quote_id']); $ this->cartItem->setQty($ cartItem['qty']); $ this->cartItem->setProductOption($ this->productOption); //$ this->cartItem->setExtensionAttributes($ this->extensionAttributes); $ this->quoteItemRepository->save($ this->cartItem); } return $ cartItems; } }
I tried to include the same class in some other class also, there also I’m getting same error message. Can any one help on this…