Announcement

Collapse
No announcement yet.

Displaying a Message that Counts Down to Free Shipping

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Displaying a Message that Counts Down to Free Shipping

    I have implemented the code below from the AUG and it works fine except it uses the Total Cart value (getCartItem(1)) whereas the Sub Total is more useful as it excludes vat and the shipping charge.

    I have checked the actinicextras.js file and there appears to be only 2 values for getCartItem
    1 = TOTAL_VALUE, 3 = CART_COUNT so I'm assuming a value for Sub Total needs to be added unless I've missed something. Any help would be appreciated.


    <script language="javascript" type="text/javascript">
    function de(prc) {
    var data, endata;
    data = new String(prc);
    data = data.split(" ");
    endata = cut(data[0]);
    return endata;
    }
    function cut(dpt) {
    stng = dpt.replace("£","");
    stang = stng.replace(".",".");
    stang = stang.replace(",","");
    return stang; }
    var left;
    price = de(getCartItem(1));
    if (price >= 100) {
    document.write("You have qualified for free shipping!");
    }
    else {
    left = (100 - price).toFixed(2);
    document.write("You need to spend £"+left+" to obtain free shipping!");
    }
    </script>

    #2
    The info you need is held in a cookie (CART_CONTENT) and that only contains the count and total.

    You would need to patch the Perl routine in ActinicOrder.pm that generates this cookie at add in the sub total:

    Look for:
    Code:
    	my $sCookie =  "CART_TOTAL\t0\tCART_COUNT\t0\n";
    Replace with:
    Code:
    	my $sCookie =  "CART_TOTAL\t0\tCART_COUNT\t0\tCART_SUBTOTAL\t0\n";
    Look for:
    Code:
    	my $nTotal = $Response[6];
    Immediately below it add a line:
    Code:
    	my $nSubTotal = $Response[2];
    Look for:
    Code:
    	$sCookie =  "CART_TOTAL\t" . ACTINIC::EncodeText2($sTotal) . "\tCART_COUNT\t" . ACTINIC::EncodeText2($nCount) . "\n";
    Replace with:
    Code:
    	$sCookie =  "CART_TOTAL\t" . ACTINIC::EncodeText2($sTotal) . "\tCART_COUNT\t" . ACTINIC::EncodeText2($nCount) . "\tCART_SUBTOTAL\t" . ACTINIC::EncodeText2($nSubTotal) . "\n";
    This will put an unformatted number for the cart total into the cookie which you should be able to extract via JavaScript getCartItem(5)
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Thanks Norman for your help to amend the perl file ActinicOrder.pm. This appears to be working fine.
      I will be testing on a live site in the next few days but its looking ok so far.

      I have amended the javascript to work with the unformatted number that getCartItem(5) returns, removed the stripping code and added simple maths ie divide price by 100 to give correct amount.

      Script below is set for free delivery at £400

      <script language="javascript" type="text/javascript">
      var left;
      price = (getCartItem(5));
      if (price/100 >= 400) {
      document.write("You have qualified for free shipping!");
      }
      else {
      left = (400 - price/100).toFixed(2);
      document.write("SPEND £"+left+" more to obtain free shipping!");
      }
      </script>

      Comment


        #4
        Happy to help. I've removed the scary "untested" from my post.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment

        Working...
        X