2

I want to add custom attribute to quote item called item_delete for example. This attribute it's to know if a a item can or can not be deleted from cart.

I've already created an extension_attributes.xml file with the following.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Quote\Api\Data\CartItemInterface">
    <attribute code="is_delete" type="boolean" />
</extension_attributes>

Also i've a plugin:

/**
 * @param \Magento\Quote\Model\Quote\Item\Repository $subject
 * @param \Magento\Quote\Model\Quote\Item $result
 */
public function afterSave(\Magento\Quote\Model\Quote\Item\Repository $subject, $result){

                $newItem = ObjectManager::getInstance()->get('\Magento\Quote\Api\Data\CartItemInterface');
                $newItem->setQuoteId($cartId);
                $newItem->setQty(1);
                $newItem->setSku($discount);


               $newItem->getExtensionAttributes()->setIsDelete()

}

So i want to add "is delete" attribute to quote item api rest response.

2

1 Answer 1

1

I think you are missing out the interface and its concrete class. Please take a look at this

https://store.fooman.co.nz/blog/an-introduction-to-extension-attributes.html

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.