0

I want to show Tier Price in admin sales order grid. For that, I have the override below file.

Magento\Sales\Block\Adminhtml\Order\Create\Search\Grid.php

When I am adding below code in the collection then it's showing the error, below are the code and error details

$attributes = $this->_catalogConfig->getProductAttributes();
        /* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
        $collection = $this->_productFactory->create()->getCollection();
        $collection->setStore(
            $this->getStore()
        )->addAttributeToSelect(
            $attributes
        )->addAttributeToSelect(
            'sku'
        )->addStoreFilter()->addAttributeToFilter(
            'type_id',
            $this->_salesConfig->getAvailableProductTypes()
        )->addAttributeToSelect(
            'gift_message_available'
        )->addFieldToSelect(
            'tier_price'
        )->addFieldToSelect(
            '*'
        );    

$collection->addAttributeToSelect('price');
     $collection->addPriceData($this->_getCustomerGroupId(), $this->getStore()->getWebsiteId());
    $this->setCollection($collection);

When I am adding this line then it's showing error

$collection->addAttributeToSelect('price');
         $collection->addPriceData($this->_getCustomerGroupId(), $this->getStore()->getWebsiteId());

Error

2 exception(s):
Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'entity_id' in on clause is ambiguous, query was: SELECT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_website` AS `product_website` ON product_website.product_id = e.entity_id AND product_website.website_id = 4
 INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '4' AND price_index.customer_group_id = 7
 INNER JOIN (SELECT MAX(event_id) AS `event_id`, `report_event`.`object_id` FROM `report_event` WHERE (event_type_id = 3) AND (subject_id = 473) AND (subtype = 0) AND (store_id IN(27)) GROUP BY `object_id`) AS `evt` ON entity_id = evt.object_id ORDER BY `evt`.`event_id` DESC

Exception #1 (PDOException): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'entity_id' in on clause is ambiguous

Now I don't know why it's showing this error and how can I solve this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.