0

On product listing page, I need to show visitor nearest product first.

I've a marketplace site and each product have different seller and there is a custom table having seller_id and product_id column.

Here is the structure screenshot of my custom table:-

enter image description here

So how can i get the seller id of each product on product lsiting page so that i can dispay nearest product first?I'm trying to use joins based on product_id on product collection here:-

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

Method:- setCollection()

But seems,there is some problem in the joining due to which filter is not working.

My Join Code:-

$collection->addAttributeToSelect('*');
$joinType = "inner"; // join type
$where = ""; // put condition
$fields = "*"; // fields
$collection->joinTable(
            ['custom' => 'marketplace_product'],
            'custom.mageproduct_id = e.id', //also tried "entity_id" instead of "id"
            $fields,
            $where,
            $joinType
        );

        echo $collection->getSelect() ; exit;

 Not printing anything on listing page.   

So please let me know the code so that i can use the join and get the seller_id and then i can calculate nearest one.

UPDATE:-

After using like that:-

 $joinConditions = 'ust.mageproduct_id = e.entity_id';

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

Joining is working fine but now I'm getting "You cannot define a correlation name 'ust' more than once" problem so please help me to resolve this problem.

Waiting for your reply!

Thanks!!!

0

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

Your Answer

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

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