Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

E-Commerce Modules /

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, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

Calculate Shipping Rate based on Shipping Zip Code

Go to End

2 Posts   2164 Views


Community Member, 18 Posts

14 April 2010 at 7:30am

Edited: 14/04/2010 7:30am

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.


Community Member, 18 Posts

14 April 2010 at 9:17am

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.