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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   2755 Views

Avatar
jsirish

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.

Avatar
jsirish

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.