2

How can I hide all products which have 1 seller (I want to show only if it has more than 1 sellers) (My website list products from multiple sellers)

I found that It's possible to add filter at app/code/core/Mage/Catalog/Block/Product/List.php

 protected function _beforeToHtml()
    {
        $toolbar = $this->getToolbarBlock();

        // called prepare sortable parameters
        $collection = $this->_getProductCollection();

        // use sortable parameters
        if ($orders = $this->getAvailableOrders()) {
            $toolbar->setAvailableOrders($orders);
        }
        if ($sort = $this->getSortBy()) {
            $toolbar->setDefaultOrder($sort);
        }
        if ($dir = $this->getDefaultDirection()) {
            $toolbar->setDefaultDirection($dir);
        }
        if ($modes = $this->getModes()) {
            $toolbar->setModes($modes);
        }

        // EDIT HERE - This demo will filter all products without Images    
        $collection->addAttributeToFilter('image', array('neq' => 'no_selection'));
        // EDIT HERE - This demo will filter all products without Images  

        // set collection to toolbar and apply sort
        $toolbar->setCollection($collection);

        $this->setChild('toolbar', $toolbar);
        Mage::dispatchEvent('catalog_block_product_list_collection', array(
            'collection' => $this->_getProductCollection()
        ));

        $this->_getProductCollection()->load();

        return parent::_beforeToHtml();
    }

Filtering by ProductCollection is easy but how can I filter products by the following code? You can see to get sellers list it's not coming from productcollection

$count=0;
$sellers=Mage::getModel('assineproduct/assineproduct')->getSellerList($_product->getId());
foreach($sellers as $seller){
    $coll=Mage::getModel('assineproduct/saleslist')->getCollection();
    $coll->addFieldToFilter('mageproownerid',array('eq'=>$seller['seller_id']));
    $coll->addFieldToFilter('mageproid',array('eq'=>$seller['product_id']));
    $count++;

}
2

What you try to achieve might be a performance problem. Beside of this, would I implement an observer, hook into catalog_block_product_list_collection and add your filters to the collection.

$collection->addAttributeToFilter('entity_id', array('in' => $productList));

This $productList is an array of product Ids which you got before somehow. The alternative is to join (in whatever table) and filter this way.

  • thanks for the help, This case scenario won't be always on I will use it sometimes so performance not an issue, I have narrowed it down to remove all sellers by id $sellerlist=Mage::getModel('assineproduct/assineproduct')->getSellerList($_product->getId()); $sellerlist->addFieldToFilter('seller_id',array('neq'=>'999')); can you help me create a join statement for this? I really can't figure this too damn hard for me I barly got this $sellerslist filter to work – DanyDin May 20 '14 at 18:15
  • $collection->getSelect()->join( array('assineproduct'=>$this->getTable('assineproduct/assineproduct')), 'main_table.entity_id = assineproduct.product_id', array('assineproduct.*'); what I have came up with but it's not working any help? – DanyDin May 20 '14 at 19:48
  • $collection->joinTable( array('asn' => 'assineproduct/assineproduct'), 'product_id=entity_id', array('seller_id' => 'seller_id') ); $collection->addFieldToFilter('seller_id',array('neq'=>'999')); seems to work but this give me an on some of the categories a:5:{i:0;s:71:"Item (Mage_Catalog_Model_Product) with the same id "3353" already exist";i:1;s:4651:"#0 pp/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(265): Varien_Data_Collection->addItem(Object(Mage_Catalog_Model_Product)) – DanyDin May 20 '14 at 20:04
  • you should add it to the question, so it is easier readable. If you get an "same id already exists", this means the query returns the same product two (or more) times, so your query needs to be adjusted (in the worst case with DISTINCT) – Fabian Blechschmidt May 20 '14 at 20:06
  • Yes my table has 2 rows for each product_id so it's duplicate how should I use distinct to remove it? – DanyDin May 20 '14 at 20:43

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.