1

When a bundle product is shown, i need to load a specific attribute of the asigned bundle items (which are simple products of course).

The attributes must be loaded in the view.phtml file located in /app/design/frontend/default/default/template/catalog/product/

My magento version is 1.9.2 CE, thanks for your help.

Edit:

Ok let me be more specific. I have a bundle product which consists of serveral simple products. Some of these simple products have an attribute called "length".

I need to calculate the length of the bundle product by adding all the lengths of the assigned simple products. Can anyone tell me please how this can be done?

  • how to you add the attribute value while adding the product in admin panel? – Mujahidh Aug 30 '15 at 12:00
  • The simple products contain the attribute value. I need to get these values. – Reinsch Aug 30 '15 at 12:16
  • does the attribute is created by you self? If yes you can use this code $_product->getMerchant(); i guess your attribute as "merchant".If this is retrieve a value for you let me know to post ass an Answer. – Mujahidh Aug 30 '15 at 12:22
  • Yes, but i need to get the attribute of the simple products, not the bundle one. – Reinsch Sep 1 '15 at 8:28
2

I finally found out myself. I needed to change the select.phtml (and also checkbox.phtml, because i am using dropdowns AND checkboxes)

The files are located in: /app/design/frontend/base/default/template/bundle/catalog/product/view/type/bundle/option/select.phtml

To get the attribute "my_length" i just added the following code:

$product_id = $_selection->getId(); //gets the product id of the option $_resource = Mage::getSingleton('catalog/product')->getResource(); $my_length = $_resource->getAttributeRawValue($product_id, 'my_length', Mage::app()->getStore()); //gets the attribute value if (!my_length) //not really sure if this is needed $my_length=0; ?>

Then i just echoed the length in the class:
<input type="hidden" name="bundle_option[getId() ?>]" value="getSelectionId() ?>" class="mylength<?php echo $my_length; ?>" />

The rest was done with javascript.

It can be necessary to add the code above more than once, depending on the original phtml file. For example in select.phtml is:
if ($this->_showSingle()):
.... this is done when there is only one option.
else
.... this is done when there are more than one option

| improve this answer | |
0

You can retrieve any attribute from the view page by writing this code.

$_product->getAttribute();

Since the attribute created by you is "Attribute".

Ex Your Attribute is "merchant" you can get the value by calling this

$_product->getMerchant();
| improve this answer | |
0

First need to find out simple product id's of bundle item. Then load the product from the id and then call the attribute value.

//here $bundle is an object of bundle item
$bundle_ids = $bundle->getTypeInstance(true)->getChildrenIds($bundle->getId(), false);

$model = Mage::getModel('catalog/product');

$simple_products = $model->getCollection()
                   ->addAttributeToSelect('your_attribute') //change your attribute id/name
                   ->addAttributeToFilter('entity_id', array('in' => $bundle_ids));

foreach($simple_products as $simple){
    echo $simple->getAttributeText('your_attribute')."<br>";
    //or do other stuff
}

Hope this helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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