I would like to override (call the below model file from my custom module called Demo_Customprice
/vendor/magento/module-catalog/Model/Product/Option/Value.php
How could we achieve this?
I would like to override (call the below model file from my custom module called Demo_Customprice
/vendor/magento/module-catalog/Model/Product/Option/Value.php
How could we achieve this?
in you 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\Option\Value" type="Demo\Customprice\Model\Rewrite\Catalog\Product\Option\Value" />
</config>
in your Model file
namespace Demo\Customprice\Model\Rewrite\Catalog\Product\Option;
class Value extends \Magento\Catalog\Model\Product\Option\Value
{
public function __construct()
{
echo "Model Rewrite Working"; die();
}
}
If use any constant value from interface.
namespace Demo\Customprice\Model\Rewrite\Catalog\Product\Option;
use Demo\Customprice\Api\Data\AccountInterface;
class Value extends \Magento\Catalog\Model\Product\Option\Value
{
public function __construct()
{
echo "Model Rewrite Working"; die();
}
}
/**
* {@inheritdoc}
*/
public function getCustomerId() {
return $this->_getData(AccountInterface::CUSTOMER_ID);
}
/**
* {@inheritdoc}
*/
public function setCustomerId($customerId) {
$this->setData(AccountInterface::CUSTOMER_ID, $customerId);
return $this;
}
public function getPrice($flag = false) { echo "Model Rewrite Working"; die(); }
Commented
Feb 15, 2017 at 12:58