ulvis.paste.net

Paste Search Dynamic
Recent pastes
getProductCollection
  1. protected function _getProductCollection()
  2. {
  3.     if (is_null($this->_productCollection)) {
  4.         $layer = $this->getLayer();
  5.         /* @var $layer Mage_Catalog_Model_Layer */
  6.         if ($this->getShowRootCategory()) {
  7.             $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
  8.         }
  9.  
  10.         // if this is a product view page
  11.         if (Mage::registry('product')) {
  12.             // get collection of categories this product is associated with
  13.             $categories = Mage::registry('product')->getCategoryCollection()
  14.                 ->setPage(1, 1)
  15.                 ->load();
  16.             // if the product is associated with any category
  17.             if ($categories->count()) {
  18.                 // show products from this category
  19.                 $this->setCategoryId(current($categories->getIterator()));
  20.             }
  21.         }
  22.  
  23.         $origCategory = null;
  24.         if ($this->getCategoryId()) {
  25.             $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
  26.             if ($category->getId()) {
  27.                 $origCategory = $layer->getCurrentCategory();
  28.                 $layer->setCurrentCategory($category);
  29.                 $this->addModelTags($category);
  30.             }
  31.         }
  32.         **$this->_productCollection = $layer->getProductCollection()->addAttributeToSort('stock_status', desc);**
  33.  
  34.         $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
  35.  
  36.         if ($origCategory) {
  37.             $layer->setCurrentCategory($origCategory);
  38.         }
  39.     }
  40.  
  41.     return $this->_productCollection;
  42. }
  43.      
  44. $this->_productCollection = $layer->getProductCollection()->addAttributeToSort('stock_status', desc);
  45.      
  46. $this->_productCollection = $layer->getProductCollection()->joinLeft(array('bs'=>'cataloginventory/stock_status'), 'bs.product_id = e.entity_id', array('stock_status' => 'bs.stock_status'))->order("stock_status desc");
Parsed in 0.011 seconds