Search Results

Search found 1 results on 1 pages for 'abnab'.

Page 1/1 | 1 

  • random products instead of related products in magento

    - by abnab
    BElow is the function that selects related product of a single product. I wanted it to work in such a way that if there are no related products other random products will be added to the array. Random could be other products of the same category and if there is no procut in the same category we could fetch from other categories. protected function _prepareData() { $product = Mage::registry('product'); /* @var $product Mage_Catalog_Model_Product */ $this->_itemCollection = $product->getRelatedProductCollection() ->addAttributeToSelect('required_options') ->addAttributeToSort('position', Varien_Db_Select::SQL_ASC) ->addStoreFilter() ; if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) { Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, Mage::getSingleton('checkout/session')->getQuoteId() ); $this->_addProductAttributesAndPrices($this->_itemCollection); } // Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection); $this->_itemCollection->load(); foreach ($this->_itemCollection as $product) { $product->setDoNotUseCategoryId(true); } return $this; } Thanks Abnab

    Read the article

1