1

How to i can get products from 1 specific category because my products are checked in two parent category. for example (I have product with the name of xyz and my categories name are A & B, Now i want get products from B which products also checked in A) If products is selected in category A & category B then show all of those products. I hope you can understand what i mean. please help me, Thansk in advance. (Magento 1.9.2 - Configurable Products)

<?php
$products = Mage::getModel('catalog/product')->getCollection();
$products->joinField(
    'qty',
    'cataloginventory/stock_item',
    'qty',
    'product_id=entity_id',
    '{{table}}.stock_id=1',
    'left'
);
$products->addAttributeToFilter('qty', array('neq' => 0));
$products->addAttributeToFilter('type_id','configurable');
$products->addAttributeToFilter('status', 1);
$products->addAttributeToFilter('visibility', 4);
$products->addAttributeToSelect('sku');
$products->addAttributeToSelect('name');
$products->addAttributeToSelect('description');
$products->addAttributeToSelect('short_description');
$products->addAttributeToSelect('url');
$products->addAttributeToSelect('image');
$products->addAttributeToFilter('price', array('gt' => 250));
$products->addAttributeToSelect('special_price');
$products->addAttributeToSelect('manufacturer');
$products->joinField('category_id',
    'catalog/category_product',
    'category_id',
    'product_id=entity_id',
    null,
    'left'
);

$products->addAttributeToFilter('category_id', array('in' => array('149','224')));
foreach ($products as $product) {
   echo $product->getName();
   print_r($product);
}
?>
1

You can try using this bit of code and answer is also linked over here

$products = Mage::getModel('catalog/product')->getCollection();
$products->joinField(
    'qty',
    'cataloginventory/stock_item',
    'qty',
    'product_id=entity_id',
    '{{table}}.stock_id=1',
    'left'
);
$products->addAttributeToFilter('qty', array('neq' => 0));
$products->addAttributeToFilter('type_id','simple');
$products->addAttributeToFilter('status', 1);
$products->addAttributeToFilter('visibility', 4);
$products->addAttributeToSelect('sku');
$products->addAttributeToSelect('name');
$products->addAttributeToSelect('description');
$products->addAttributeToSelect('short_description');
$products->addAttributeToSelect('url');
$products->addAttributeToSelect('image');
$products->addAttributeToFilter('price', array('gt' => 250));
$products->addAttributeToSelect('special_price');
$products->addAttributeToSelect('manufacturer');
$products->joinField('category_id',
    'catalog/category_product',
    'category_id',
    'product_id=entity_id',
    null,
    'left'
);
$products->addAttributeToFilter('category_id', array('in' => array(32,5)));
foreach ($products as $product) {

}
  • you are using condition in of both categories in this line ? $products->addAttributeToFilter('category_id', array('in' => array(32,5))); – Wajahat Bashir Aug 28 '17 at 6:45
  • yes they are both category's ids – Riddhish Bhayani Aug 28 '17 at 6:46
  • I have put same code only replace cat id's, but not showing, i think your code is for simple products but i have configurable products ? and which code i'll be write in foreach loop ? – Wajahat Bashir Aug 28 '17 at 6:53
  • Are you getting the product collection. just print the product collection. you must get some product collection. – Riddhish Bhayani Aug 28 '17 at 6:58
  • 1
    It's for products whose price is greater than 250 – Riddhish Bhayani Aug 29 '17 at 8:50

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.