Skip to content

Override `extension_attributes.xml` in extending custom module (which targets ShippingInformationInterface/ShippingInformationExtension)

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_Moduleetcextension_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="MagentoCheckoutApiDataShippingInformationInterface">
          <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_Module2etcextension_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="MagentoCheckoutApiDataShippingInformationInterface">
          <!-- 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 MagentoCheckoutApiData;

/**
 * ExtensionInterface class for @see MagentoCheckoutApiDataShippingInformationInterface
 */
interface ShippingInformationExtensionInterface extends MagentoFrameworkApiExtensionAttributesInterface
{
    /**
     * @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() and getPickupDate() (mapped via pickup_store and pickup_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_Module2etcextension_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?