I am trying to use plugins on the following Magento 2 core methods:
MagentoBundleModelProductType::checkProductBuyState()MagentoBundleModelProductType::getOptionsIds()MagentoCatalogModelProductTypeAbstractType::checkProductBuyState()
Core classes (simplified)
MagentoBundleModelProductType extends MagentoCatalogModelProductTypeAbstractType:
class MagentoBundleModelProductType extends MagentoCatalogModelProductTypeAbstractType
{
public function checkProductBuyState($product)
{
parent::checkProductBuyState($product);
$productOptionIds = $this->getOptionsIds($product);
// ... more logic
return $this;
}
public function getOptionsIds($product)
{
return $this->getOptionsCollection($product)->getAllIds();
}
}
AbstractType itself has its own checkProductBuyState:
abstract class MagentoCatalogModelProductTypeAbstractType
{
public function checkProductBuyState($product)
{
if (!$product->getSkipCheckRequiredOption() && $product->getHasOptions()) {
// ... validate required options
throw new MagentoFrameworkExceptionLocalizedException(
__('The product has required options. Enter the options and try again.')
);
}
return $this;
}
}
My plugins
<type name="MagentoCatalogModelProductTypeAbstractType">
<plugin name="MagePsycho_Catalog_AbstractType::aroundCheckProductBuyState"
type="MagePsychoCatalogPluginModelProductTypeAbstractTypePlugin"
sortOrder="10"/>
</type>
<type name="MagentoBundleModelProductType">
<plugin name="MagePsycho_Catalog_Bundle_Type::aroundCheckProductBuyState"
type="MagePsychoCatalogPluginBundleModelProductTypeAroundCheckProductBuyStatePlugin"
sortOrder="10"/>
<plugin name="MagePsycho_Catalog_Bundle_Type::aroundGetOptionsIds"
type="MagePsychoCatalogPluginBundleModelProductTypeAroundGetOptionsIdsPlugin"
sortOrder="10"/>
</type>
Problem
If I add a plugin around MagentoCatalogModelProductTypeAbstractType::checkProductBuyState(), then my plugins for the bundle product type (getOptionsIds, checkProductBuyState) stop working.
If I remove the plugin on AbstractType::checkProductBuyState(), the bundle plugins work fine.
Question
Why is my plugin on MagentoBundleModelProductType not being executed when I also have a plugin on MagentoCatalogModelProductTypeAbstractType?
-
Is it because
BundleTypeextendsAbstractTypeand the interceptor chain is broken? -
Do I need to handle
$proceeddifferently in theAbstractTypeplugin? -
Or should I move my logic directly to the bundle type instead of the abstract type?
💡 What am I missing here? How can I make both plugins (AbstractType::checkProductBuyState and BundleType::getOptionsIds) work together?