Ropardo Sowftware development company

Experience software development with ROPARDO S.R.L.

RSS Feed
RSS Feed
  • Home
  • About ROPARDO S.R.L
  • Our websites

osCommerce jQuery price calculator

Let’s assume that we have to build a price calculator for a osCommerce website, that needs to have price based on dimensions(input from user – length, width), attributes, for each attribute there are more than 1 options with different prices for each option.


For the website that I had to build this calculator i had the attributes displayed in selects(drop downs), and one specific attribute it was displayed in div’s(material), because i needed to show picture for each option.
The attributes prices are not displayed in select options by default so from the code u need to put the prices into hidden input fields so u can use them into calculator.

Once i had that covered i needed a way to get the selected values every time user plays with the drop downs and get their prices to use in the calculator.

Let’s assume the following output code:

<div class="product-options-page">
<span>Optiuni disponibile:</span><br />
<script type="text/javascript">
var options_vector = new Array();
</script>
<div class="options">
Actionare: <select name="id[7]" id = "7">
<option value="33" SELECTED>Alege optiunea</option>
<option value="25">De la dreapta la stanga</option>
<option value="24">De la stanga la dreapta</option>
</select>
<div class="question-mark">
<a href="images/help/actionare.gif" alt="Actionare">
<img src="images/question_mark.png" border="0" alt="" width="15" height="15">
</a>
</div>
<script type="text/javascript">
options_vector[0]= "7";
</script>
<input type="hidden" id="opt-33" value="" />
<input type="hidden" id="opt-25" value="" />
<input type="hidden" id="opt-24" value="" />
</div>
<div class="options">
Sistem de prindere: <select name="id[2]" id = "2">
<option value="4">Pe rama (+2.00RON)</option>
<option value="3">Pe perete (-8.00RON)</option>
<option value="37" SELECTED>Alege optiunea</option>
</select>
<div class="question-mark">
<a href="images/help/sistem_de_prindere.gif" alt="Sistem de prindere">
<img src="images/question_mark.png" border="0" alt="" width="15" height="15">
</a>
</div>
<script type="text/javascript">
options_vector[1]= "2";
</script>
<input type="hidden" id="opt-4" value="_2.00" />
<input type="hidden" id="opt-3" value="-8.00" />
<input type="hidden" id="opt-37" value="" />
</div>
<div class="options">
Tip inchidere/deschidere:<select name="id[3]" id = "3">
<option value="13">Normala (+1.00RON)</option>
<option value="14">Opusa (+2.00RON)</option>
<option value="15">Cortina (+8.00RON)</option>
<option value="39" SELECTED>Alege optiunea</option>
</select>
<div class="question-mark">
<a href="images/help/tip_inchidere_deschidere.gif" alt="Tip inchidere/deschidere">
<img src="images/question_mark.png" border="0" alt="" width="15" height="15">
</a>
</div>
<script type="text/javascript">
options_vector[2]= "3";
</script>
<input type="hidden" id="opt-13" value="_1.00" />
<input type="hidden" id="opt-14" value="_2.00" />
<input type="hidden" id="opt-15" value="_8.00" />
<input type="hidden" id="opt-39" value="" />
</div>
</div>

Te signs from the input values marks math operators, the “_” is the replacement for “+”, because i had some troubles in JavaScript with it.

Note the array variable from JavaScript, i used it to get the id’s of the attributes so i can get the price value in JavaScript.
The following function is responsible with price grabing for the attributes options:

function get_selects(){
var price = '';
var opt_selected;
for(i = 0; i< options_vector.length; i++){
var id = options_vector[i];
select_id = '#'+id;
opt_selected = $(select_id).val();
price += $('#opt-'+opt_selected).val(); //concat
}
return price;
}

Variable “options_vector” is the one defined in the output page earlier. The returned result is a string that i will parse with another function that will replace the signs, with
math operators and will return the final result.
So at the end we have:
dimensions: height, width
price: which is in square meters
attributes prices:
material price: which is also an attribute but since is displayed with div’s each material has it’s value in a hidden input from which the value is taken on click.

The final function returns:

((length * width)/1000000)*price + (material_price*((length * width)/1000000)) + options_price

Dimensions are given in milimeters that’s why i had to divide by 1 million;
e.g.
height:1500 mm
width: 4000 mm
option 1: -9 eur
option 2: 7 eur
option 3: 2.5 eur
material: 6 eur
price: 160 eur/m2

((1500*4000)/1000000)*160 + ((1500*4000)/1000000)*6)+(-9+7+2.5) =  996.5 eur
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Get Shareaholic
Tags: javascript jQuery osCommerce PHP

 Posted in: Javascrip/AJAX, PHP
June 21, 2010 | Mihai Ionescu | 4 Comments

4 Responses

  • cristi
    July 5, 2010
    1

    dragut calculator. dar cum pasezi mai departe dimensiunile(ca si descriere) si noul pret?

  • Mihai Ionescu
    July 6, 2010
    2

    Dimensiunile le concatenez cu x (1000×2300) si le pasesz dintr-un input ascuns apoi le salvez in baza de date atunci cand se adauga produsul, pretul calculat este tot intr-un input ascuns, dar se calculeaza usor pt ca am toate datele si doar folosesc fomula matematica.

    Dimensiunile le trimit asa ca sa fac diferenta intre produse. (200×1200) != (1200×200) ca produs, chiar daca pretul e acelasi.

  • brunette teenage girls
    July 30, 2010
    3

    It was very interesting for me to read the blog. Thank you for it. I like such topics and everything connected to this matter. I would like to read more on that blog soon.

    Anete Kuree

  • Anonymous
    September 24, 2010
    4

    Great post! I want to see a follow up to this topic!

Leave a Reply

 


  • « Previous post
  • Next post »
  • Recent Posts

    • Installing PyGraphviz on Windows
    • Convert python object to XML representation
    • Liferay Portlet Development
    • Norway Road Show 2011 private meeting invitation
    • Oracle OpenWorld 2011
  • Ropardo is Hiring

  • Subscribe

    • Add to Google Reader or Homepage Add to netvibes TopOfBlogs
  • Recent Comments

    • Rajkumar Pomaji on Bluetooth PC Remote Control
    • Stelian Morariu on GWT 2.1 – Uploading a file using the RPC mechanism
    • Sergio on GWT 2.1 – Uploading a file using the RPC mechanism
    • Artem on Liferay: Deployment will start in a few seconds… and how to realy start
    • rkd80 on GWT 2.1 – Uploading a file using the RPC mechanism
  • Archives

    • November 2011 (1)
    • September 2011 (4)
    • July 2011 (3)
    • June 2011 (2)
    • May 2011 (4)
    • April 2011 (4)
    • March 2011 (3)
    • February 2011 (2)
    • January 2011 (2)
    • December 2010 (1)
    • November 2010 (4)
    • October 2010 (4)
    • August 2010 (3)
    • July 2010 (3)
    • June 2010 (6)
    • May 2010 (8)
    • April 2010 (7)
    • March 2010 (9)
    • February 2010 (6)
    • January 2010 (5)
    • December 2009 (7)
    • November 2009 (9)
    • October 2009 (10)
    • September 2009 (14)
    • August 2009 (10)
    • July 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (1)
    • March 2009 (1)
    • October 2008 (3)
    • October 2007 (3)
    • July 2007 (4)
    • June 2007 (1)
    • May 2007 (3)
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Categories

    • News (15)
    • Ropardo Team (8)
    • Ropardo Products (6)
      • File Tracking Client (4)
      • iManagement (2)
    • Software Development (83)
      • Microsoft.NET (22)
      • Java (40)
      • Oracle (8)
      • Power Builder (3)
      • Liferay (5)
      • Lotus Notes (9)
      • xWiki (4)
    • System Adminstration (13)
      • Linux (10)
      • Windows (3)
    • Programming (1)
    • Uncategorized (3)
    • Databases (10)
      • MSSQL (5)
      • PostgreeSQL (3)
    • Microsoft.NET (1)
    • Web Development (28)
      • ASP/ASPX (3)
      • Content Management Systems (1)
      • HTML/CSS (5)
      • Javascrip/AJAX (8)
      • PHP (7)
    • Oracle E Business Suite (6)
  • Tags

    .NET ajax blog C# certification client CMS control css database Debugging django Domino Eclipse extension file tracking filter fun gentoo google Hibernate how to html image iManagement import Java javascript jQuery liferay Linux Lotus Notes lotus script Oracle Oracle BI Publisher 11g PHP portal PostgreSQL powerbuilder Python SQL Telerik velocity xml Xwiki

© 2010 ROPARDO s.r.l..

Powered by WordPress. Styled by Ropardo