Magento Forum

   
Order view product grid
 
joey santiago
Sr. Member
 
Total Posts:  76
Joined:  2009-02-25
 

I’ve been looking for hours for the file that creates the Items Ordered table in the Order view page (http://127.0.0.1/mall/index.php/admin/admin/sales_order/view/order_id/3/)… found out some of the code resides in Mage/Adminhtml/Block/Sales/Order/View/Items.php ..

can anyone explain me why if i add there some code like

$collection $this->getOrder()->getItemsCollection();
       foreach (
$collection as $prod){
        $productIds [] 
$prod->getId();
      
}
      $productCollection 
Mage::getModel('catalog/product')->getCollection()
          ->
addIdFilter($productIds)
          ->
addAttributeToSelect('name')
          ->
addAttributeToSelect('storeowner')
          ->
load();
      
$product $productCollection->getItemById($prod->getId());
          echo 
$product->getName();

makes everything broken and i get an almost blank page?? But if i print_r the product object it works and shows me everything…

please help me out!

 
Magento Community Magento Community
Magento Community
Magento Community
 
joey santiago
Sr. Member
 
Total Posts:  76
Joined:  2009-02-25
 

Grrrr, why if i try to use Mage/Sales/Model/Mysql4/Order/Item/Collection.php ‘s function addIdFilter($item) it doesn’t filter anything???

 
Magento Community Magento Community
Magento Community
Magento Community
 
joey santiago
Sr. Member
 
Total Posts:  76
Joined:  2009-02-25
 

So… i changed my code and looked like working, but it sometimes doesn’t work as expected, even though it looks like the DB queries are right…

$order $this->getOrder();
      foreach (
$order->getAllItems() as $item{
        $productIds[] 
$item->getProductId();
      
}
      $productCollection 
Mage::getModel('catalog/product')->getCollection()
        ->
addIdFilter($productIds)
        ->
addAttributeToSelect('name')
        ->
addAttributeToSelect('storeowner')
        ->
load();
      
$count 0;
      foreach (
$order->getAllItems() as $item{
        $count 
++;
        
$product $productCollection->getItemById($item->getProductId());
        if(
$product->getStoreowner()==$ownerAttVal{
          $prodIdsOk[]
$item->getProductId();//$count;
        
}
      }
    $trick 
Mage::getModel('sales/order_item')->getCollection()->setOrderFilter($this->getOrder())->addFieldToFilter('item_id', array('in'=>$prodIdsOk));
    
print_r($trick);
    return 
$trick;
So this $trick object should be constructed doing a query like:

Array ( [distinct] => [columns] => Array ( [0] => Array ( [0] => main_table [1] => * [2] => ) ) [union] => Array ( ) [from] => Array ( [main_table] => Array ( [joinType] => inner join [schema] => [tableName] => sales_flat_order_item [joinCondition] => ) ) [where] => Array ( [0] => (order_id = ‘2’) [1] => AND (item_id in (’1’)) )

so getting the order number 2 (and it does) and out of the order it should get the item_id 1. Unluckily it just works when the order has the item with id 1 as ONLY ITEM… when i have in an order the items 1 and 2,i get an empty grid.

Please someone help me!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
joey santiago
Sr. Member
 
Total Posts:  76
Joined:  2009-02-25
 

got it. the function addIdFilter doesn’t do what i supposed it to. here’s the right code:

$trick = Mage::getModel(’sales/order_item’)->getCollection()->addFieldToFilter(’product_id’, array(’in’=>$prodIdsOk))->setOrderFilter($this->getOrder());
return $trick;

 
Magento Community Magento Community
Magento Community
Magento Community
 
joey santiago
Sr. Member
 
Total Posts:  76
Joined:  2009-02-25
 

got it. the function addIdFilter doesn’t do what i supposed it to. here’s the right code:

$trick = Mage::getModel(’sales/order_item’)->getCollection()->addFieldToFilter(’product_id’, array(’in’=>$prodIdsOk))->setOrderFilter($this->getOrder());
return $trick;

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top