0

I have facing Below error when I override resource model

Fatal error: Call to undefined method Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Interceptor::getAttributeId() in /home/XXXXXX/Extendfiles/Plugin/Model/ResourceModel/Product/Type/Configurable.php on line 262

i have us this code

public function afterGetAttributeOptions($superAttribute, $productId) 
{ 
$scope = $this->getScopeResolver()->getScope(); 
$select = $this->getConnection()->select()->from( 
['super_attribute' => $this->getTable('catalog_product_super_attribute')], 
[ 
'sku' => 'entity.sku', 
'product_id' => 'product_entity.entity_id', 
'attribute_code' => 'attribute.attribute_code', 
'value_index' => 'entity_value.value', 
'option_title' => $this->getConnection()->getIfNullSql( 
'option_value.value', 
'default_option_value.value' 
), 
'default_title' => 'default_option_value.value', 
] 
)->joinInner( 
['product_entity' => $this->getTable('catalog_product_entity')], 
"product_entity.{$this->getProductEntityLinkField()} = super_attribute.product_id", 
[] 
)->joinInner( 
['product_link' => $this->getTable('catalog_product_super_link')], 
'product_link.parent_id = super_attribute.product_id', 
[] 
)->joinInner( 
['attribute' => $this->getTable('eav_attribute')], 
'attribute.attribute_id = super_attribute.attribute_id', 
[] 
)->joinInner( 
['entity' => $this->getTable('catalog_product_entity')], 
'entity.entity_id = product_link.product_id', 
[] 
)->joinInner( 
['entity_value' => $superAttribute->getBackendTable()], 
implode( 
' AND ', 
[ 
'entity_value.attribute_id = super_attribute.attribute_id', 
'entity_value.store_id = 0', 
"entity_value.{$this->getProductEntityLinkField()} = " 
. "entity.{$this->getProductEntityLinkField()}", 
] 
), 
[] 
)->joinLeft( 
['option_value' => $this->getTable('eav_attribute_option_value')], 
implode( 
' AND ', 
[ 
'option_value.option_id = entity_value.value', 
'option_value.store_id = ' . $scope->getId(), 
] 
), 
[] 
)->joinLeft( 
['default_option_value' => $this->getTable('eav_attribute_option_value')], 
implode( 
' AND ', 
[ 
'default_option_value.option_id = entity_value.value', 
'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, 
] 
), 
[] 
)->where( 
'super_attribute.product_id = ?', 
$productId 
)->where( 
'option_value.value != "N/A"', 
$productId 
)->where( 
'attribute.attribute_id = ?', 
$superAttribute->getAttributeId() 
); 

return $this->getConnection()->fetchAll($select); 
}
i have just add my code at bottom of this function
->where( 
'option_value.value != "N/A"', 
$productId 
)

Di.xml

<type name="Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable"> 
<plugin name="ptgConfigurableProduct" type="Modulename\Extendfiles\Plugin\Model\ResourceModel\Product\Type\Configurable" sortOrder="1" /> 
</type>

If anyone facing and get solution please reply me.

2
  • please share proper log...Extendfiles_Plugin is Seems your created extesnsion
    – Amit Bera
    Aug 9, 2018 at 5:35
  • Also share you full code of /home/XXXXXX/Extendfiles/Plugin/Model/ResourceModel/Product/Type/Configurable.php. Aug 9, 2018 at 7:05

1 Answer 1

0

There are mistakes in your plugin. You have not added the $subject and other function arguments correctly.

Try this

public function afterGetAttributeOptions(
    \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $subject,
    $result,
    \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $superAttribute,
    $productId
) {
    // add your code here
}
3
  • 1 exception(s): Exception #0 (Exception): Strict Notice: Declaration of XXXXXXX\Extendfiles\Plugin\Model\ResourceModel\Product\Type\Configurable\Interceptor::afterGetAttributeOptions() should be compatible with XXXXXXX\Extendfiles\Plugin\Model\ResourceModel\Product\Type\Configurable::afterGetAttributeOptions(Magento\Eav\Model\Entity\Attribute\AbstractAttribute $superAttribute, $productId) in /home/commercestaging/public_html/alpha/oly/var/generation/XXXXXXX/Extendfiles/Plugin/Model/ResourceModel/Product/Type/Configurable/Interceptor.php on line 7
    – Rv Singh
    Aug 9, 2018 at 9:05
  • I have to getting this error
    – Rv Singh
    Aug 9, 2018 at 9:05
  • Remove var/generation folder and try again. Aug 9, 2018 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.