AnuragBabaresco
AnuragBabaresco

Reputation: 604

SimpleCart.js - add shipping information to object

I am integrating SimpleCart.js (http://simplecartjs.org/) into a small project. I wanted to see if it is possible to actually add the shipping information to the SimpleCart Object.

I get the shipping information from an existing user account, and it contains:

shipId, ship_first, ship_last, ship_street, ship_city, ship_state, ship_zip, ship_phone

I have seen in the documentation that I can extend the SimpleCart.js object (http://simplecartjs.org/documentation/simplecart-extend). So currently I am doing it like this:

In my HTML markup :

<a href="#" onclick="setShipping(<?php echo $address['id'] . ", '" . $address['ship_first'] [...] ?>Set Address</a>

My javascript looks like this:

<script>
    function setShipping(shipId, ship_first [...]) {
        var shippingInfo = {
             shipId: shipId,
             ship_first: ship_first,
             [...]
        };

    simpleCart.extend(simpleCart, shippingInfo); 

   // do some more stuff like updating the checkout button and tax rate
  }
 </script>

This code works on this page, however when I browse to another page the shipping properties appear to have gotten lost. I basically check on every page if the shipping has been set or not, and if it hasn't, I display the link to set the shipping address.

How would I extend the object "permanently" ?

Upvotes: 1

Views: 659

Answers (1)

VeeeneX
VeeeneX

Reputation: 1578

Simply add your simpleCart extender to actual simpleCart.js file.

Upvotes: 0

Related Questions