Overriding model file is not working in Magento 2.2.5
Overriding model file is not working in Magento 2.2.5
I tried to override model, but it is not working. I need to override:
MagentoCatalogModelProductAttributeBackendPrice to
PawanCatalogModelRewriteProductAttributeBackendPrice
But it not working.
My di.xml
path Pawan/Catalog/etc/di.xml
:
di.xml
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="MagentoCatalogModelProductAttributeBackendPrice" typr="PawanCatalogModelRewriteProductAttributeBackendPrice" />
</config>
<?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="MagentoCatalogModelProductAttributeBackendPrice" typr="PawanCatalogModelRewriteProductAttributeBackendPrice" />
</config>
My model file:
<?php
namespace PawanCatalogModelRewriteProductAttributeBackend;
class Price extends MagentoCatalogModelProductAttributeBackendPrice
public function afterSave($object)
$writer = new ZendLogWriterStream(BP . '/var/log/importmissingorders.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->info("custom model");
/** @var $attribute MagentoCatalogModelResourceModelEavAttribute */
$attribute = $this->getAttribute();
$attributeCode = $attribute->getAttributeCode();
$value = $object->getData($attributeCode);
// $value may be passed as null to unset the attribute
if ($value === null
It is still executing the core file only.
What am I doing wrong?
What do you mean by "But it working." and "My
di.xml
local Pawan/Catalog/etc/di.xml
"?– Peter Mortensen
Sep 3 at 16:57
di.xml
Pawan/Catalog/etc/di.xml
1 Answer
1
Change typr
,
typr
<preference for="MagentoCatalogModelProductAttributeBackendPrice" typr="PawanCatalogModelRewriteProductAttributeBackendPrice" />
to type
:
type
<preference for="MagentoCatalogModelProductAttributeBackendPrice" type="PawanCatalogModelRewriteProductAttributeBackendPrice" />
yes in server logs i found it typo mistake
– Pawankumar
Sep 3 at 15:30
Thanks for contributing an answer to Magento Stack Exchange!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
did you already clear cache or setup:upgrade or di:compile ?
– mrfizh
Sep 3 at 15:13