Question

I used this event in Magento 1:- sales_quote_config_get_product_attributes.

In Magento 2 this event is removed, in CHANGELOG.md it's saying, use plugin instead of event.

How can i use this event as plugin in Magento 2?

Was it helpful?

Solution

The event was used to modify the return value of Mage_Sales_Model_Quote_Config::getProductAttributes()

This is now possible with an after plugin.

The class is now Magento\Quote\Model\Quote\Config, the method still getProductAttributes()

Plugins are documented here: http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html

OTHER TIPS

You can see the existing code like

/vendor/magento/module-sales-rule/etc/di.xml

<type name="Magento\Quote\Model\Quote\Config">
    <plugin name="append_sales_rule_keys_to_quote" type="Magento\SalesRule\Model\Plugin\QuoteConfigProductAttributes"/>
</type>

/vendor/magento/module-sales-rule/Model/Plugin/QuoteConfigProductAttributes.php

public function afterGetProductAttributes(\Magento\Quote\Model\Quote\Config $subject, array $attributeKeys)
{
    $attributes = $this->_ruleResource->getActiveAttributes();
    foreach ($attributes as $attribute) {
        $attributeKeys[] = $attribute['attribute_code'];
    }
    return $attributeKeys;
}

You can use like this in Plugin way ( Before, After and Around ) in your module. I hope you know how to create a basic plugin flow.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top