3

I am using magento 1.8 and want to generate a list of products which never ordered on our site. Can you please give some idea on it. I am open to use any code as well as any sql which can be directly run on our database.

4

first identify the products ordered:

$orderedItems = Mage::getModel('sales/order_item')->getCollection();
$orderedProductsIds = array(-1); //add a -1 to have at least one element
foreach ($orderedItems as $item) {
    $orderedProductIds[] = $item->getProductId();
}

Then get the product collection excluding the result above.

$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('entity_id', array('nin'=>$orderedProductIds));

Then do what you need with the products that result.
For example, build an array with skus and names: $products = array();

foreach ($collection as $product) {
    $products[$product->getSku()] = $product->getName();
}
//do what you want with `$products`
|improve this answer|||||
  • I am getting $orderedProductsIds but Mage::getModel('catalog/product')->getCollection() is not working for me. – Ram Sharma Sep 9 '14 at 6:43
  • what do you mean by 'not working'? – Marius Sep 9 '14 at 6:44
  • aah, it's my mistake that I did not add addAttributeToSelect beacuse I have configurable products only. Now it's working like charm. – Ram Sharma Sep 9 '14 at 6:49
  • Boy, you save my day. You are so quick and accurate. – Ram Sharma Sep 9 '14 at 6:49

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.