Important

Okay
  Public Ticket #1307647
How to join Seller collection with Product collection
Closed

Comments

  • Harinarayanan started the conversation

    Hello Team,

    I need to get the Seller name along with product list. To accomplish this, I joined the product collection with lof_marketplace_seller table:  Please see my code here : https://magento.stackexchange.com/questions/193822/product-attribute-join-with-custom-table-magento-2-17-how-to-retrieve-custom-t
    But  i'm not able to get the seller_name using $value->getData('seller_name').

    Can you please tell me how to get the seller name along with product list

  •  1,317
    Land of replied

    Hi

    Please change 

    foreach ($collection->getData() as $value) {    $sellerName = $value['seller_name'];    ................
    }


  • Harinarayanan replied

    That works. Thank you very much :)

    I don't know why magneto dev docs not explaining the use of it's inner functions.

  •  1,317
    Land of replied

    Hi

    Yes,If you have any questions, just ask me

    Thanks

  • Harinarayanan replied

    Okay. Thank you.

  • Priti replied

    Hi,

    I have joined product collection with a custom table. From this i am getting product_id, seller_p_id(id of product assigned to seller), seller_id, and few more values.

    Now i want to load customer data using seller_id(it is a customer id) to get customer name. please some tell me how to join these tables. I am very confused with the magento 2 joins.

    here is the snippet of my join code:

    /* Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollection; */

            $collectionData = $productCollection->create();
            $collectionData->addAttributeToSelect('*')->load();   
           
            $joinConditions = 'e.entity_id = marketplace_product.mageproduct_id';
            $collectionData->getSelect()->joinLeft(
                 ['marketplace_product'],
                 $joinConditions,
                 []
                )->columns(array('marketplace_product.mageproduct_id','marketplace_product.seller_id','e.entity_id'));




  •  1,317
    Land of replied

    Hello Priti,

    Have a nice day!

    Please try to use the code:

    /* Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollection; */

    $collectionData = $productCollection->create();
    $collectionData->addAttributeToSelect('*')->load();    

    $joinConditions = 'e.entity_id = marketplace_product.mageproduct_id';
    $collectionData->getSelect()->joinLeft(
         ['marketplace_product'],
         $joinConditions,
         ['marketplace_product.seller_id']
        );


     it will join left to table marketplace_product, then get the columns: seller_id, you can get all columns of the seller table by join left to the marketplace seller table, with join condition is seller_id.