Ok so this is the configurable product http://v2.bicomplex.md/romanian/usi/kolori-a.html and it is assigned to another configurable product.
But the color swatch does not appear. What do i do wrong?
thank you!
1 answer
To enable color swatch on your product detail, please open this file: ..\app\design\frontend\default\your_themetemplate \catalog\product\view.phtml
After this line:
Code:
<?php $_product = $this->getProduct(); ?>
Insert the following code block:
Code:
<?php if($_product->isConfigurable() && Mage::helper("jmcolorswatch")->get('show')) { $associtates = Mage::helper("jmcolorswatch")->getassociatedproducts($_product->getId()); $attrcode = Mage::getModel('eav/entity_attribute')->load(137)->getAttributeCode(); echo $attrcode; $products_arr_qty = array(); if(is_array($associtates)){ foreach($associtates as $productid){ $product = Mage::getModel('catalog/product')->load($productid); $stocklevel = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productid); $products_arr_qty[$product->getData($attrcode)] = $stocklevel->getQty(); $attribute_arr[$product->getData($attrcode)] = $product->getAttributeText($attrcode); } } //asort($attribute_arr); ?> <script type="text/javascript"> if(<?php echo json_encode($attribute_arr); ?> != null){ jQuery(document).ready(function() { jQuery("div.product-options").jmproductdetail({ attribute:"<?php echo $attrcode; ?>", attributeid:137, mainproduct:<?php echo $_product->getId(); ?>, attribute_qtys:<?php echo json_encode($products_arr_qty); ?>, attribute_arr:<?php echo json_encode($attribute_arr); ?> }); }); } </script> <?php } ?>
Note: "137" value is your attribute’s id.
To add style for this, you can declare as follows:
Code:
#productsize span { border: 1px solid #9D9D9D border-radius: 5px; color: #333333 cursor: pointer; margin-right: 5px; padding: 7px 8px; } #productsize span.active { border: 1px solid #FF4629 color: #FF4629 }
Hope this helps.