andy_1984 Posted February 25, 2011 Share Posted February 25, 2011 been looking high and low for this. as the title says. i would like to be able to re-calculate the price of the product when an attribute is selected without leaving product_info.php so if product is £10 and attribute is selected that costs an additional £10 the price shown would be £20. some sort of java or ajax ? Link to comment Share on other sites More sharing options...
dragonkb Posted February 26, 2011 Share Posted February 26, 2011 ------------------------------------------------------------------------------------------------------------ Manual install instructions (catalog/product_info.php) ------------------------------------------------------------------------------------------------------------ Search for: <link rel="stylesheet" type="text/css" href="stylesheet.css"> After that line add: <!-- Attrib price update //--> <script language="javascript"> <!-- function calcPrice(el) { //el = <select> that is being changed and that contains the price details var currencySymbolLeft = '<?php echo htmlentities($currencies->currencies[DEFAULT_CURRENCY]['symbol_left']); ?>'; var currencySymbolRight = '<?php echo htmlentities($currencies->currencies[DEFAULT_CURRENCY]['symbol_right']); ?>'; var currencyDecimalPoint = '<?php echo htmlentities($currencies->currencies[DEFAULT_CURRENCY]['decimal_point']); ?>'; var currencyThousandsPoint = '<?php echo htmlentities($currencies->currencies[DEFAULT_CURRENCY]['thousands_point']); ?>'; var currencyDecimalPlaces = '<?php echo htmlentities($currencies->currencies[DEFAULT_CURRENCY]['decimal_places']); ?>'; var itemBasePrice = parseFloat(document.getElementById('itemPrice').value); var itemBasePrice1 = parseFloat(document.getElementById('itemPrice1').value); var priceDiff = 0; for(f = 0; f < document.forms.length ; f++) { frm = document.forms[f]; for(e = 0; e < frm.elements.length; e++) { elm = frm.elements[e]; if(elm.type == "select-one" ) { var curSelItemText = elm.options[elm.selectedIndex].text; var posOpenBracket = curSelItemText.indexOf('('); var posCloseBracket = curSelItemText.indexOf(')'); if (posOpenBracket != -1 && posCloseBracket != -1) { priceDiff += parseFloat(curSelItemText.substr(posOpenBracket + 1, posCloseBracket - posOpenBracket - 1).replace(currencySymbolLeft, '').replace(currencySymbolRight, '').replace(currencyThousandsPoint, '')); } } } } var totalPrice = itemBasePrice + priceDiff; var totalPrice1 = itemBasePrice1 + priceDiff; var finalFormattedPrice = currencySymbolLeft + number_format(totalPrice, currencyDecimalPlaces, currencyDecimalPoint, currencyThousandsPoint) + currencySymbolRight; var finalFormattedPrice1 = currencySymbolLeft + number_format(totalPrice1, currencyDecimalPlaces, currencyDecimalPoint, currencyThousandsPoint) + currencySymbolRight; document.getElementById("productNEWprice").innerHTML = finalFormattedPrice; if (document.getElementById("productNEWprice1") != undefined) { document.getElementById("productNEWprice1").innerHTML = finalFormattedPrice1; } } function number_format(number, decimals, dec_point, thousands_sep) { // http://phpjs.org/ number = (number+'').replace(',', '').replace(' ', ''); var n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, dec = (typeof dec_point === 'undefined') ? '.' : dec_point, s = '', toFixedFix = function (n, prec) { var k = Math.pow(10, prec); return '' + Math.round(n * k) / k; }; // Fix for IE parseFloat(0.55).toFixed(0) = 0; s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.'); if (s[0].length > 3) { s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); } if ((s[1] || '').length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec); } //--> </script> <!-- Attrib price update Fin //--> ------------------------------------------------------------------------------------------------------------ Search for: </body> Add the following lines afterwards: <!-- Attrib price update //--> <script language="javascript"> <!-- calcPrice(document.getElementById('selectSize')); //--> </script> <!-- Attrib price update Fin //--> ------------------------------------------------------------------------------------------------------------ Search for: <td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?> Replace it by.: <td class="pageHeading" align="right" valign="top"> <!-- price update attributes begin --> <?php if(tep_has_product_attributes($product_info['products_id'])){ if ($new_price = tep_get_products_special_price($product_info['products_id'])) { ?> <script type="text/javascript">document.write('<s><div id="productNEWprice1"></div>\n</s>');</script> <script type="text/javascript">document.write('<span class="productSpecialPrice"><div id="productNEWprice"></div>\n</span>');</script> <noscript><?php echo $products_price; ?></noscript> <?php } else {?> <script type="text/javascript">document.write('<div id="productNEWprice"></div>\n</span>');</script> <noscript><?php echo $products_price; ?></noscript> <?php } } else { echo $products_price; } ?> </td> <input type="hidden" name="nuPrice" id="itemPrice" value="<?php echo str_replace("$","",$nuPrice); ?>"> <input type="hidden" name="nuPrice1" id="itemPrice1" value="<?php echo str_replace("$","",$nuPrice1); ?>"> <!-- price update attributes end --> ------------------------------------------------------------------------------------------------------------ Search for: $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>'; After add: //Attrib price update $nuPrice1 = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); $nuPrice = $currencies->display_price($new_price, tep_get_tax_rate($product_info_values['products_tax_class_id'])); //Attrib price update Fin ------------------------------------------------------------------------------------------------------------ Search for: $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); } Replace by: //Attrib price update $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); $nuPrice = $products_price; } $nuPrice = str_replace(",", ".", $nuPrice); $nuPrice1 = str_replace(",", ".", $nuPrice1); //Attrib price update Fin ------------------------------------------------------------------------------------------------------------ Search For: <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td> Change to: <!-- Attrib price update //--> <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute, "id="selectSize" onChange='calcPrice(this);'");?></td> <!-- Proyecto Icaro (Fin Modificado) //--> Link to comment Share on other sites More sharing options...
Mastermind2008 Posted February 28, 2011 Share Posted February 28, 2011 <link rel="stylesheet" type="text/css" href="stylesheet.css"> In 2.3.1 where is this at in the product_info file? I used ctrl+f and searched but couldn't find it. Same for the body and others above... Thanks. Link to comment Share on other sites More sharing options...
andy_1984 Posted March 1, 2011 Author Share Posted March 1, 2011 thank you very much for the code. i am getting £0.00 each time i select an attribute. any ideas ? Link to comment Share on other sites More sharing options...
bjeli Posted March 4, 2011 Share Posted March 4, 2011 I resolved the problem writing this in the last line: <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $ProdOpt_ID . ']', $products_options_array, $selected_attribute, 'onChange=calcPrice(this);') ?></td> Link to comment Share on other sites More sharing options...
andy_1984 Posted March 4, 2011 Author Share Posted March 4, 2011 i ended up just writing my own price update code after being unable to figure out why it would keep returning 0. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.