configurable.phtml
pascal
posted: Jun, 8th 2012 | jump to bottom
<?php $_product = $this->getProduct(); $_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); ?> <?php if ($_product->isSaleable() && count($_attributes)):?> <?php $i=1 ?> <dl> <?php foreach($_attributes as $_attribute): ?> <dt><label class="required"><em> * </em><?php echo $_attribute->getLabel() ?></label></dt> <div class="input-box"> <?php $configs = $this->getRegularConfig()?> <?php foreach($configs['attributes'] as $config):?> <ul class="options-list" id="options-<?php echo $_attribute->getAttributeId() ?>-list"> <?php foreach($config['options'] as $value): if ( $config['label'] == $_attribute->getLabel() ): ?> <!-- Check if options not match with label then options not show--> <li > <label class="label-radio-configurable" id="<?php echo (float)$value['price'] //get price value from options?>"> <input type="radio" name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?> id<?php echo $i?>" class="validate-custom-configurable" value="<?php echo $value['id']?>"/> <?php echo $value['label']?> (+ $<?php printf("%.2f", $value['price'])?>) <?php $i++ ?> </label> </li> <?php endif; endforeach;?> </ul> <?php endforeach;?> </div> <?php endforeach; ?> </dl> <?php endif;?> <script type="text/javascript"> var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); document.observe("dom:loaded", function() { var customValidation = false; var priceFormat = <?php echo $this->helper('tax')->getPriceFormat(); ?>; $$('.validate-custom-configurable').each(function(el){ el.observe('click',function(event){ var total_amount = optionsPrice.productPrice; /*variable to keep base product price*/ var sPrice = optionsPrice.productOldPrice; /* variable to keep Regular price*/ var i=0; /* variable to keep total increase price*/ $$('.label-radio-configurable input').each(function(elmn){ if ( elmn.checked == true ) { i+=parseFloat(elmn.parentNode.id); /*when radio-box has checked keep increase price into i*/ } }); total_amount+=i; /*Base price + total increase price*/ sPrice+=i; /*Regular price + total increase price*/ $$('span.price').each(function(elmn){ elmn.update(formatCurrency(parseFloat(total_amount), priceFormat)).innerHTML; /* show update price in tag span class price*/ }); $$('p.old-price span.price').each(function(elm){ /*If product has Regular Price update it too*/ elm.update(formatCurrency(parseFloat(sPrice), priceFormat)).innerHTML; /* show update price in tag span class price*/ }); }); }); Validation.addAllThese([ ['validate-custom-configurable', 'This is a required field.', function(v) { $$('.validate-custom-configurable').each(function(el){ if (el.checked) { customValidation = true; } }); return customValidation; }] ]); }); </script>
1515 views




