1

I created a new module to create a section in admin panel. This module section has a sub-section "Associated products" where I can add one or more products to each item in that module.

I am able to get the field values using functions like

  • $combo->getName()
  • $combo->getComments()

But I am not able to get the associated products to that item using

$combo->getAssociatedProducts()

What I tried is as follows:

<?php $comboCollection = Mage::getResourceSingleton('combo/combo_collection'); ?>
<?php 
    foreach ($comboCollection as $combo) {
        zend_debug::dump($combo->getAssociatedProducts($combo));  //giving error       
    }
?>

PS: here $combo is not a product, it is just an item in the created module.

Explanation:


enter image description here


1 Answer 1

2

Knowing that you created your module with the Ultimate Module Creator, here is how you can get the associated products of your entity.

$collection = $combo->getSelectedProductsCollection(); //get associated products
$collection->addAttributeToSelect('name'); //add 'name' attribute to collection - you can add others
$collection->addUrlRewrite(); //add the url rewrite to the collection
$collection->getSelect()->order('related.position'); //sort by the position you filled in the admin panel
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); //get only enabled products
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); //get only visible products.
8
  • I tried this.. this is taking a while to load and then showing me a blank page. The tables which created are combo_combo and combo_combo_product. There is also another table which is not related to get the associated product collection i.e combo_combo_store.
    – Mr_Green
    Commented Dec 16, 2013 at 8:04
  • I asked the same question on SO. where I got this reply.. link (not working)
    – Mr_Green
    Commented Dec 16, 2013 at 8:05
  • @Mr_Green. Enable the log and check var/log for errors.
    – Marius
    Commented Dec 16, 2013 at 8:05
  • Got it!! not sure what was the problem though. just refreshed the page :/
    – Mr_Green
    Commented Dec 16, 2013 at 8:11
  • I added a image attribute.. I am trying to get url of the uploaded image. if I do $combo->getImage() I am getting suffix of the url but not complete url. I have seen that there is _getImageUrl() (present in abstract class) in Helper class but I am unable to use it.. I don't know how to use it.. tried different ways.. no use...
    – Mr_Green
    Commented Dec 16, 2013 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.