The question is specifically about ./Magento/Checkout/Api/Data/ShippingInformationExtension.php
and adding extra columns via extension_attributes.xml
.
Modules:
- Source module:
Vendor_Module
- Overriding/extending module:
Vendor2_Module2
(extending JS / templates etc / Plugins) from Source module.
Issue
I need to use a custom extension_attributes.xml
inside Vendor2_Module2
.
Information
- The source file:
Vendor_Module\etc\extension_attributes.xml
:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Checkout\Api\Data\ShippingInformationInterface">
<attribute code="pickup_store" type="string"/>
<attribute code="pickup_date" type="string"/>
</extension_attributes>
</config>
- Custom module that is overriding/using plugins and other customizations from source
Vendor_Module
module:
Vendor2_Module2\etc\extension_attributes.xml
:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Checkout\Api\Data\ShippingInformationInterface">
<!-- trimmed (other attributes) that will be added here -->
<!-- Custom data for this overridden module -->
<attribute code="custom_shipping_method_title" type="string"/>
</extension_attributes>
</config>
Findings
Running bin/magento setup:upgrade && bin/magento setup:di:compile
does not generate the extra attribute custom_shipping_method_title
in the new overriding module's ShippingInformationExtensionInterface
namespace Magento\Checkout\Api\Data;
/**
* ExtensionInterface class for @see \Magento\Checkout\Api\Data\ShippingInformationInterface
*/
interface ShippingInformationExtensionInterface extends \Magento\Framework\Api\ExtensionAttributesInterface
{
/**
* @return string|null
*/
public function getPickupStore();
/**
* @param string $pickupStore
* @return $this
*/
public function setPickupStore($pickupStore);
/**
* @return string|null
*/
public function getPickupDate();
/**
* @param string $pickupDate
* @return $this
*/
public function setPickupDate($pickupDate);
}
- As indicated in generated/code/ file above, this only contains
getPickupStore()
andgetPickupDate()
(mapped viapickup_store
andpickup_date
respectively).
Question
- It is missing the new custom attribute
custom_shipping_method_title
, eg.getCustomShippingMethodTitle()
entry in the generated code.
How do I override / point Magento 2 to use Vendor2_Module2\etc\extension_attributes.xml
instead of Vendor_Module\
?
I know how to override / use plugins via di.xml
for classes but since this is an XML file to be overridden, what do I do?