Thursday, 24 September 2015

Filtering a Magento product collection by multiple categories and Stock item and filter current product in product detail page


I  Want to create section to get same product of different categories of products with Stock or quantity.

after i want get product of minimum of product quantity 50%.

for that i will join 'cataloginventory/stock_item', and  'catalog/category_product'  get this collection.

this section create in product detail page that why i am filter current product using it product id.

Please Below Code it help to you.

$product_id = Mage::registry('current_product')->getId();
    $category_ids = $_product->getCategoryIds();
$collection = Mage::getModel('catalog/product')->getCollection()
 ->addAttributeToFilter('entity_id', array('neq' => $product_id))
 ->addAttributeToFilter('status', 1)
$conditions = array();
foreach ($category_ids as $categoryId) {
 if (is_numeric($categoryId)) {
  $conditions[] = "{{table}}.category_id = $categoryId";
->joinField('category_id', 'catalog/category_product', null, 'product_id = entity_id', implode(" OR ", $conditions), 'inner');
 foreach ($collection as $_item) {
    //echo $_item->getName()."</br>";
     $product_qty = $_item->getQty();
     $product_qty = round($product_qty);
    $product_qty = $product_qty/100;
    if($product_qty >= 0.5){
        echo $_item->getName()."</br>";

Please Below code it help getting products.

1 comment:

  1. best dividend on stocks? how can we share, show, campnay stock by using extention like itoris ???
    Magento Quick View


Thank You For Comment