Posts Tagged ‘how to’

Sort product list by stock

Posted: February 2, 2015 in How To?, Magento
Tags: ,

Use

$this->_productCollection = $layer->getProductCollection()->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id','is_in_stock>=0', 'left')->setOrder('inventory_in_stock','desc');

If you want to just list Out of Stock products use:

$collection->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id','{{table}}.is_in_stock=0');

Delete Orders and Data

Posted: January 27, 2015 in Extensions, How To?, Magento
Tags: , ,

Want to delete orders in magento including invoices and shipment info?

Use the wyomind extension at http://www.magentocommerce.com/magento-connect/orders-eraser.html

Search in stock products in Magento

Posted: January 17, 2015 in How To?, Magento
Tags:

Want to setup a checkbox in advanced search for in stock products?

  1. Add the checkbox to the advanced search page (name ‘stock’ to the checkbox)
  2. Clone file /app/code/Mage/CatalogSearch/Model/Advance.php to /app/code/local/Mage/CatalogSearch/Model/Advance.php
  3. In the new file add to function prepareProductCollection the following code (before the return $this; statement)
    if (Mage::app()->getRequest()->getParam('stock')) {
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
    }

For the regular search box:

  1. Add the checkbox to the search block (name ‘stock’ to the checkbox)
  2. Clone file /app/code/Mage/CatalogSearch/Model/Layer.php to /app/code/local/Mage/CatalogSearch/Model/Layer.php
  3. In the new file add to function prepareProductCollection the following code (before the return $this; statement)
    if (Mage::app()->getRequest()->getParam('stock')) {
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
    }

Get current store id in magento

Posted: October 30, 2014 in How To?
Tags: ,

Wondering how to get the current store id in php?

<?php echo Mage::app()->getStore()->getStoreId() ?>