1

I tried to override model, but it is not working. I need to override:

Magento\Catalog\Model\Product\Attribute\Backend\Price to Pawan\Catalog\Model\Rewrite\Product\Attribute\Backend\Price

But it not working.

My di.xml path Pawan/Catalog/etc/di.xml:

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Model\Product\Attribute\Backend\Price" typr="Pawan\Catalog\Model\Rewrite\Product\Attribute\Backend\Price" /> </config>

My model file:

<?php
    namespace Pawan\Catalog\Model\Rewrite\Product\Attribute\Backend;

    class Price extends \Magento\Catalog\Model\Product\Attribute\Backend\Price
    {
        public function afterSave($object)
        {
            $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/importmissingorders.log');
            $logger = new \Zend\Log\Logger();
            $logger->addWriter($writer);
            $logger->info("custom model");

            /** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
            $attribute = $this->getAttribute();
            $attributeCode = $attribute->getAttributeCode();
            $value = $object->getData($attributeCode);

            // $value may be passed as null to unset the attribute
            if ($value === null || (float)$value > 0) {
                if ($attribute->isScopeWebsite() && $object->getStoreId() != \Magento\Store\Model\Store::DEFAULT_STORE_ID) {
                    if ($this->isUseDefault($object)) {
                        $value = null;
                    }
                    foreach ((array)$object->getWebsiteStoreIds() as $storeId) {
                        $object->addAttributeUpdate($attributeCode, $value, $storeId);
                    }
                }
            }
            return $this;
        }
    }

It is still executing the core file only.

What am I doing wrong?

2
  • did you already clear cache or setup:upgrade or di:compile ?
    – mrfizh
    Sep 3, 2018 at 15:13
  • What do you mean by "But it working." and "My di.xml local Pawan/Catalog/etc/di.xml"? Sep 3, 2018 at 16:57

1 Answer 1

5

Change typr,

<preference for="Magento\Catalog\Model\Product\Attribute\Backend\Price" typr="Pawan\Catalog\Model\Rewrite\Product\Attribute\Backend\Price" />

to type:

<preference for="Magento\Catalog\Model\Product\Attribute\Backend\Price" type="Pawan\Catalog\Model\Rewrite\Product\Attribute\Backend\Price" />
1
  • yes in server logs i found it typo mistake
    – Pawankumar
    Sep 3, 2018 at 15:30

Your Answer

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

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