I'm trying to add an extension attribute to \Magento\Quote\Api\Data\TotalsInterface
. My understanting is, that magento should generate getter/setter
for the new attribute, but that is not happening. (i tried deleting var/generation
var/cache
multiple times)
extension_attributes.xml
<?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\TotalsInterface">
<attribute code="custom_attribute" type="string"/>
</extension_attributes>
</config>
Is my understanding correct, or is this just not possible?
The interface is instantiated using factory in Magento\Quote\Model\Cart\CartTotalRepository
. Could that have an effect?
Any help would be greatly appreciated.
Best Answer
The getters and setters are not added to the
TotalsInterface
itself.Instead they are generated in
Magento\Quote\Api\Data\TotalsExtensionInterface
(which you should find invar/generation
) and you use it like this (forcustom_attribute
):