0

I'm trying to join custom table on product listing page,here is the Class and method:-

Class:- vendor/magento/module-catalog/Block/Product/ProductList/Toolbar.php

Method:- setCollection()

Here is the code of this method:-

 public function setCollection($collection)
    {
        $this->_collection = $collection;

       //My Custom Code

         $mpJoinConditions = 'mp.mageproduct_id = e.entity_id';

                       $this->_collection->getSelect()->join(
                ['mp' => $this->_collection->getTable('marketplace_product')],
                $mpJoinConditions,
                []
            )->columns("mp.seller_id");

       // End of My Custom Code

        $this->_collection->setCurPage($this->getCurrentPage());

        // we need to set pagination only if passed value integer and more that 0
        $limit = (int)$this->getLimit();
        if ($limit) {
            $this->_collection->setPageSize($limit);
        }
        if ($this->getCurrentOrder()) {
            $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }
        return $this;
    }

But getting following issue:-

"You cannot define a correlation name 'mp' more than once"

Please help me to resolve the issue!!!

2 Answers 2

0

Used Tablename "marketplace_product" instead of using alias "mp" and it's working fine now.

0

This is very odd, although mp was defined only once, I tried your solution but didn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.