1

I am making use of Marketplace extension and wanted to show seller name after product name in Category list page. I have used "catalog_block_product_list_collection" events

<event name="catalog_block_product_list_collection">
    <observer name="add_seller_info_product_list_collection" instance="Vendor\Page\Observer\AddSellerInfoListCollection" />
</event>

And Observer Class


namespace Vendor\Page\Observer;

class AddSellerInfoListCollection 
implements \Magento\Framework\Event\ObserverInterface
{
    protected $_objectManager;
    public function __construct(
        \Magento\Framework\App\Helper\Context $context,
        \Magento\Framework\ObjectManagerInterface $objectManager){
        $this->_objectManager = $objectManager;
    }

    public function execute(\Magento\Framework\Event\Observer $observer){
        $collection = $observer->getCollection();
        $seller = $this->_objectManager->create(
            'Magento\Catalog\Model\ResourceModel\Product\Collection'
        )->getTable('customer_grid_flat');

        $sellerProduct = $this->_objectManager->create(
            'Magento\Catalog\Model\ResourceModel\Product\Collection'
        )->getTable('marketplace_product');

        $sellerProfile = $this->_objectManager->create(
            'Magento\Catalog\Model\ResourceModel\Product\Collection'
        )->getTable('marketplace_userdata');


        $collection->getSelect()->joinLeft(
                $sellerProduct.' as seller_product',
                'e.entity_id = seller_product.mageproduct_id'
            );

        $collection->getSelect()->joinLeft(
                $seller.' as seller',
                'seller_product.seller_id = seller.entity_id',
                array('seller_name'=>'seller.name')
            );

        $collection->getSelect()->joinLeft(
                $sellerProfile.' as sellerprofile',
                'sellerprofile.seller_id = seller.entity_id',
                array('seller_shop_url'=>'sellerprofile.shop_url')
        );       
        return $this;
    }    
}

I get proper results when a product is associated with some seller, but if there is a product not associated with any seller then all product attributes ( like name, url, etc) are not loaded.

enter image description here

0

Your Answer

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

Browse other questions tagged or ask your own question.