1

Magento 1.9.2.2

Hi all

I've got a puzzle I'm stuck on and I know it must be fairly straight forward but it is driving me mad. I'm trying to load the value of a custom attribute (in this case a hex color assigned to the simple product that will be used to change the color of text within a div area) within a configurable product, so when the child is selected, the attribute is used.

You can see an example here: http://www.store2.welcometotheweb.co.uk/index.php/canvas

So when you select the "Purple", it will load the attribute for that product ColorCode which can then be used for the text color of the other input fields. I've been able to use a snippet which will echo a list of the associated attributes associated to the configurable product itself, but obviously not what I want.

Any direction would be greatly appreciated.

UPDATE

I've been able to call in a list of the attributes from the child using the code below, so I know there is no issue with actually accessing the data from the products, but with a limited knowledge of php, am not sure of the correct method to adapt this to be able to call only the current child product data.

<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($col as $simple_product){
     var_dump($simple_product->getData('color_code'));
 } ?>
  • Please provide the PHP code which you are using as well as the attribute code. Also, is that attribute configured to be visible on product page? – benmarks Dec 9 '15 at 16:25
  • At present, the only code I have is the simple <div class="product-image-gallery" style="color:<?php echo $_product->getData("color_code"); ?>;"> which is working as you would expect and returning the code set within the parent product. The code is color_code. I've got this inside the media.phtml at present, but can move elsewhere if needed. – WTTW Dec 9 '15 at 20:29

Your Answer

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

Browse other questions tagged or ask your own question.