1

I have added a new column "admin_user" column in catalog_product_entity_tier_price table. This column value needs to come when following method is executed.

$p=$productRepo->get('sample');
$tier=$p->getTierPrices();
foreach ($tier as $t)
{   
    print_r($t->getData())."<br>";
}

But getData() method returns only qty and customer group id.

Array ( [customer_group_id] => 2 [value] => 3.0500 [qty] => 1.0000 )
Array ( [customer_group_id] => 3 [value] => 4.0000 [qty] => 1.0000 )

How do I add "admin_user" value to this getData() method. Any help would be appreciated.

Update 1

I have found that in \Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\GroupPrice\AbstractGroupPrice.php columns are set in this method

public function loadPriceData($productId, $websiteId = null)
    {
        $connection = $this->getConnection();

        $columns = [
            'price_id' => $this->getIdFieldName(),
            'website_id' => 'website_id',
            'all_groups' => 'all_groups',
            'cust_group' => 'customer_group_id',
            'price' => 'value'
           'admin_user'=>'admin_user'            
        ];

How to override this method of the abstract class to include additional table columns in custom module

2 Answers 2

0

for magento2.2, the loadPriceData function changed a little bit.

public function loadPriceData($productId, $websiteId = null)
{
    $select = $this->getSelect($websiteId);
    $productIdFieldName = $this->getProductIdFieldName();
    $select->where("{$productIdFieldName} = ?", $productId);

    $this->_loadPriceDataSelect($select);

    return $this->getConnection()->fetchAll($select);
}

I use plugin to include the additional column.

di.xml

<type name="Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\GroupPrice\AbstractGroupPrice">
    <plugin sortOrder="1" name="PLUGINNAME"
            type="VENDERNAME\MODULENAME\Plugin\Model\ResourceModel\Product\Attribute\Backend\GroupPrice\AbstractGroupPricePlugin"/>
</type>

AbstractGroupPricePlugin.php

<?php
namespace VENDERNAME\MODULENAME\Plugin\Model\ResourceModel\Product\Attribute\Backend\GroupPrice;
class AbstractGroupPricePlugin
{
public function afterGetSelect(\Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\GroupPrice\AbstractGroupPrice $subject, $result)
{
    //add admin_user column to select
    $result->columns('admin_user');
    return $result;
}
}

May need set extension_attribute depend on requirement.

0

So I have the same problem. I have add a new column to tierprices table and I'm trying to get the value from this column from each tierprice to frontend. Can anyone help me how can I do it that? Because now I get Array ( [customer_group_id] => 2 [value] => 3.0500 [qty] => 1.0000 ) Array ( [customer_group_id] => 3 [value] => 4.0000 [qty] => 1.0000 )

and I want to get Array ( [customer_group_id] => 2 [value] => 3.0500 [qty] => 1.0000 [date_to] =>'23-4-2022' ) Array ( [customer_group_id] => 3 [value] => 4.0000 [qty] => 1.0000 [date_to] =>'23-4-2022' )

Magento 2.4

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.