php - Magento : Get data from Varien_Data_Collection -


hiho everybody! hope you'll give me clue because i'm still noob magento.

i try display list of products in array. in mage/catalog/block/product/list.php, created new varien_data_collection() in pushed products objects (with ->additem($product)).

then return custom collection , list.php class work display list of products.

when call page in browser, had right number of displayed products , when click on see product page, right page.

however, data (like product name, price, etc) empty. guess methods used list class catch these data fail varien_data_collection object.

to illustrate, here code sample :

// getting particular product $mainproduct = mage::getmodel('catalog/category')->load($currentcat->getid()); $mainproduct = $mainproduct->getproductcollection(); $mainproduct = $mainproduct->addattributetofilter('product_id', $_get['cat_id']);  // creating custom collection              $mycollection = new varien_data_collection();  foreach ($mainproduct $product) {     // getting particular product's related products in array     $related = $product->getrelatedproductids();                     if ($this->array_contains($related, $_get['cat_id'])) {         // if suits me, add in custom collection         $mycollection->additem($product);     } } return $mycollection; 

and in list page :

enter image description here

when var_dump($mycollection), can see ['name'], ['price'], etc fields not referenced. ['product_id'] , many other fields don't care about.

my ultimate question : how can return collection containing these products data list class ? know poorly explained english limited , try best :(

calling ->getproductcollection() against category returns skeleton data each product in created collection. if want full data each of products, need load them, in foreach loop have:

$product = mage::getmodel('catalog/product')->load($product->getid()); 

however way in building collection not best working practice - should never have create own varien_data_collection object, instead should creating product collection follows:

$collection = mage::getmodel('catalog/product')->getcollection(); 

then before load collecion (which foreach loop or calling ->load() against collection 2 examples), can filter collection according requirements. can either using native magento methods, 1 of using (addattributetofilter()) or prefer pull select object collection , apply filtering way:

$select = $collection->getselect(); 

you can run of zend_db_select class methods against select object filter collection.

http://framework.zend.com/manual/1.12/en/zend.db.select.html

when collection has been loaded, products inside contain full product data.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -