cancel
Showing results for 
Search instead for 
Did you mean: 

Collection Products vs Collection Properties

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Collection Products vs Collection Properties

This is for successful json encoding.

if i run: 

$collection = Mage::getResourceModel('catalog/product_collection');
$products = $collection->load()->toArray();

 

I get a lovely array of product properties + nested stockitem also as array of properties and that encodes fine. But if I run

 $simples= Mage::getModel('catalog/product_type_configurable')
                   ->getUsedProducts(null,$product);

I can't run : $simples->load()->toArray(); or just ->toArray(); and I can't json encode it properly. Sort of begs a coupla questions about the difference between the two fetches and what's the best way out without making an elaborate iteration with $item->getData()'s

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Collection Products vs Collection Properties

This works:

 

$collection = Mage::getResourceModel('catalog/product_collection');
foreach($simples as $simple){
   $collection->addItem($simple);
}
$products=$collection->toArray();
return $products;

 

View solution in original post

2 REPLIES 2

Re: Collection Products vs Collection Properties

I do see that 

getUsedProducts()

returns an array not a collection , but an array of product objects, is there a simple way to flip these to nested arrays ? (StockItems nested i mean) ?

Re: Collection Products vs Collection Properties

This works:

 

$collection = Mage::getResourceModel('catalog/product_collection');
foreach($simples as $simple){
   $collection->addItem($simple);
}
$products=$collection->toArray();
return $products;