Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    122
    Plugin Contributions
    0

    Default jQuery Price Change On Option Selection.

    Hi guys and girls,

    While doing a search on Google for something I came across a website that has some code on it that allows the price listed on your product page to change depending on what option you have selected. As shown on this website here.

    http://store.passion4health.biz/inde...60-120%29.html

    If you select one of the options from the drop down box you will notice that the price on the products page is updated automatically to include the option price that you selected.

    Here is the code that is used to do this and on the page this code is mentioned the fellow has written the following:

    *NB:* Please don't just cut and paste the code. You will need to play with the regex based on our option values.

    Code:
    $j("document").ready(function(){
      var newprice = parseFloat($our_price);
      var initialfinals = {};
      $j('#attrib-1 option').each(function(option){
      arr = $j(this).text().match(/(.*) \( ([+,-])\$(.*) \)$/);
      if (arr) {
       if (arr[2] == "+") {
        initialfinals[arr[1]] = parseFloat($our_price) + parseFloat(arr[3]);
       } else {
        initialfinals[arr[1]] = parseFloat($our_price) - parseFloat(arr[3]);
       }
      } else {
       initialfinals[$j(this).text()] = parseFloat($our_price);
      }
      });
      
    
      $j('#attrib-1').change(function(){
      arr = $j('#attrib-1 option:selected').text().match(/(.*) \( ([+,-])\$(.*) \)$/);
      if (arr) {
       var upgrade = arr[3];
       newprice = parseFloat(initialfinals[arr[1]]);
      }
      $j('#our_price').html('Our Price: $'+newprice.toFixed(2));
      
      //recalc other options....
      $j('#attrib-1 option').each(function(option) {
       arr = $j(this).text().match(/([a-z,A-Z,0-9]* *[a-z,A-Z,0-9]*)[ ,\(]*/);
       delta = newprice - initialfinals[arr[1]]
       newoption = "";
       if (delta > 0) {
        newoption = arr[1]+ " ( -$"+delta.toFixed(2)+" )";
       } 
       if (delta <0) {
        delta = -1 - (delta) +1;
        newoption = arr[1]+" ( +$"+delta.toFixed(2)+" )";
       }
       if (delta == 0) {
        newoption = arr[1];
       }
       $j(this).text(newoption);
      });
      });
      
    })
    So my question is. Does anyone know where this code is to be inserted and in to which file is it to be inserted to?

    Also what is meant by the fellows comment when he says "You will need to play with the regex based on our option values." ? What is regex and where can it be found?

    Any help on this would be very much appreciated as it looks like a great mod.

    Thanks.

  2. #2
    Join Date
    Jul 2006
    Location
    Montreal, Canada
    Posts
    2,279
    Plugin Contributions
    0

    Default Re: jQuery Price Change On Option Selection.

    there is a mode already for zencart ..


 

 

Similar Threads

  1. Change price with option change???
    By 4thwave in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 18 Sep 2010, 07:22 PM
  2. JQuery price slider
    By Kooba in forum General Questions
    Replies: 0
    Last Post: 30 Aug 2010, 09:23 AM
  3. Hard coded price to change with the currency selection
    By tingtongmaak in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 0
    Last Post: 7 Nov 2008, 03:39 AM
  4. Change price by attribute set to lowest option
    By joerubes in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 6 Feb 2008, 04:42 AM
  5. How prevent auto-selection of payment option when only 1 payment option available
    By DogTags in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 3 Jun 2006, 01:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg