Magento: How to filter a collection (sales/order) by a certain category? -


i spend lot of hours solve problem, don't :( need selection of ordered items special category. how can filter collection e.g. categoryid '44' ?

here code:

<?php require_once '/home/web/public_html/app/mage.php'; mage::app();  //$_category = mage::getmodel('catalog/category')->load($category_id);  $salescollection = mage::getmodel("sales/order")->getcollection();  echo $salescollection->getselect();  foreach ($salescollection $order) {     $items = $order->getallitems(); ... ?> 

thanks helping me, best, rik

here's 1 (perhaps) not elegant approach doing so...

first grab products in category want

$category_id = 44; $category = mage::getmodel("catalog/category")->load($category_id); $products = mage::getmodel("catalog/product")->getcollection()   ->addcategoryfilter($category); 

next collect product ids can use them

$product_ids = array(); foreach ($products $product)   $product_ids[] = $product->getid(); 

grab order items product id 1 of products our category

$items = mage::getmodel("sales/order_item")->getcollection()   ->addfieldtofilter("product_id", array("in" => $product_ids)); 

now fetch unique orders referenced items

$orders = array(); foreach ($items $item) {   $order_id = $item->getorderid();   if (!isset($orders[$order_id]))     $orders[$order_id] = mage::getmodel("sales/order")->load($order_id); } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -