Jump to:

2087 Posts in 1007 Topics by 455 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » Calculate Shipping Rate based on Shipping Zip Code

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1687 Views
  • Dynamic
    Community Member
    16 Posts

    Calculate Shipping Rate based on Shipping Zip Code Link to this post

    I'm working on a (US) zip code based shipping module for Ecommerce v.6.

    First, I added a field named 'ShippingZip' to the OrderForm class. There's a list of 10 zip codes (set in config file similar to Simple Shipping Modifier) that get one rate, and any other zip code gets the default rate.

    The problem is, I'm so far unable to read the value of the entered ShippingZip value in the form to pull into the modifier and check against the list. I've disabled the JS based validation, leaving the server side enabled (so I can see if the shipping cost updates in the order form). When the page reloads after submitting with a value for ShippingZip, the value is being populated in the field by javascript (i believe) but not in the value attribute of the input in the HTML source.

    I thought I was on to something with the populate defaults recipe but still no luck.

    If anyone can point me in the right direction on this I'd greatly appreciate it.

  • Dynamic
    Community Member
    16 Posts

    Re: Calculate Shipping Rate based on Shipping Zip Code Link to this post

    Figured it out:

    Needed to use the AJAX update field functionality (for the country drop down) in the OrderForm and Shopping Cart classes, so set the value of ShippingZip in the session. Shipping Modifier gets updated on AJAX change and reads the value from the session (defined in shopping cart). Also needed to add the input onchange code for ShippingZip to the ecommerce.js file so it would update the form fields on change.

    Now that I see how it's setup, it's actually some very nice code behind that functionality.

    Hope this helps someone else.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.