I am trying to override a resource model class Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\TierPrice
to select new columns that I have created in the catalog_product_entity_tier_price table.
However, the new columns are not selected and the model is not getting overridden.
namespace [vendor][module]\Model\ResourceModel\Product\Attribute\Backend;
class TierPrice extends \Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\TierPrice
{
/**
* Add qty column
*
* @param array $columns
* @return array
*/
protected function _loadPriceDataColumns($columns)
{
$columns = parent::_loadPriceDataColumns($columns);
//$columns['price_qty'] = 'qty';
//new columns
$columns['created_by']='created_by';
$columns['price_effective_from']='price_effective_from';
$columns['price_effective_to']='price_effective_to';
$columns['deletion_flag']='deletion_flag';
return $columns;
}
}
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLcation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\TierPrice" type="[vendor]\[module]\Model\ResourceModel\Product\Attribute\Backend\TierPrice" />
</config>
script.php
$p=$productRepo->get('s1');
echo $p->getName();
$tier=$p->getTierPrices();
foreach($tier as $t)
{
print_r($t->getData());
}
returns error Notice: Undefined index: created_by
How to override this class to add additional columns of the tier price table.
Note I have implemented interface for the new columns. So if I directly edit the core resource model, it works.
[vendor]\[module]
in yourdi.xml
?