G'day guys,
I'm trying to set-up a shopping cart function using the e-commerce module but I've run into a bit of a brick wall trying to calculate postage. Because postage is done by weight not the quantity of items, it needs to be calculated on ranges. For example:
1 - 3 DVDs = $4.00 postage
4 - 8 DVDs = $12.00 postage (and so on)
So if the customer enters 1, 2 or 3 DVDs it's still the same postage. But if they enter more it goes up into the next bracket and so on.
My guess is that I need to make an ecommerce rule that lists all the possible number of items (up to 100 for example) with their relevant postage values which is then somehow linked to the total number of items field entered at checkout.
Does that sound like the right thing to do? How do I go about this?
cheers
Not having worked with ecommerce yet (most of the clients I work with are government), I couldn't say whether the package supports such a rule. If not, you could possibly add some javascript over the top to achieve some calculation of the postage.
// Quick example
var data = { 1: 4, 4: 12, 9: 20 }
var postage=data[1];
for ( var i = 1,counter=document.getElementById('test').value; i++ < counter; ) {
postage = (data[i]) ? data[i] : postage;
}
// Alert(postage)
[quote]
Not having worked with ecommerce yet (most of the clients I work with are government), I couldn't say whether the package supports such a rule. If not, you could possibly add some javascript over the top to achieve some calculation of the postage.
// Quick example
var data = { 1: 4, 4: 12, 9: 20 }
var postage=data[1];
for ( var i = 1,counter=document.getElementById('test').value; i++ < counter; ) {
postage = (data[i]) ? data[i] : postage;
}
// Alert(postage)
[/quote]
Thanks Anthony,
This is helpful. But I'm am really a total newbie to this and not a coder I might need my hand held a bit more. Is it easy to explain what the code is doing and where (ie which asset) I would insert it?
[quote]
This is helpful. But I'm am really a total newbie to this and not a coder I might need my hand held a bit more. Is it easy to explain what the code is doing and where (ie which asset) I would insert it?
[/quote]
No worries. The where of this would be done on your checkout page, I would imagine. I have very limited experience with the ecommerce asset, but you would need to use code similar to this to pass the actual postage value to your checkout form. You'd also need to show it to your user, and then I would imagine add that to the total value being sent by the form. Javascript may or may not be an appropriate mechanism to do this, it all depends on your implementation and requirements.
I can, however, give you a quick overview of what the code would be doing:
var data = { 1: 4, 4: 12, 9: 20 }
// this is a selection of your number of dvd's, and the cost at which it increases to the next range.
// 1: 4 (this means 1 dvd or higher is $4)
// 4: 12 (this means 4 dvd's or higher is $12).. and so on
var postage=data[1];
var quantity=document.getElementById('test').value;
for ( var i = 1,counter=quantity; i++ < counter; ) {
postage = (data[i]) ? data[i] : postage;
}
// Here you would set the default value of 'postage' to whatever 1 dvd costs to send, just to give it a value.
// I changed the variable name to quantity so you could see where the number of dvd's the user has ordered appears in the code
// Then there is a simple loop to calculate the price range.
There would be more javascript than this needed to actually implement it. You need to pass the value of 'postage' to the ecommerce form, perhaps write it out to the page somewhere so the user can see how much they are paying etc. Basically, you couldn't really take this and drop it into a form and have it work, it would need to be tailored specifically to your implementation. But hopefully sets you on the right track.
Perhaps another Squiz-ite with E-Commerce experience could comment on the functionality we have to tackle issues like this.
[quote]
No worries. The where of this would be done on your checkout page, I would imagine. I have very limited experience with the ecommerce asset, but you would need to use code similar to this to pass the actual postage value to your checkout form. You'd also need to show it to your user, and then I would imagine add that to the total value being sent by the form. Javascript may or may not be an appropriate mechanism to do this, it all depends on your implementation and requirements.
I can, however, give you a quick overview of what the code would be doing:
var data = { 1: 4, 4: 12, 9: 20 }
// this is a selection of your number of dvd's, and the cost at which it increases to the next range.
// 1: 4 (this means 1 dvd or higher is $4)
// 4: 12 (this means 4 dvd's or higher is $12).. and so on
var postage=data[1];
var quantity=document.getElementById('test').value;
for ( var i = 1,counter=quantity; i++ < counter; ) {
postage = (data[i]) ? data[i] : postage;
}
// Here you would set the default value of 'postage' to whatever 1 dvd costs to send, just to give it a value.
// I changed the variable name to quantity so you could see where the number of dvd's the user has ordered appears in the code
// Then there is a simple loop to calculate the price range.
There would be more javascript than this needed to actually implement it. You need to pass the value of 'postage' to the ecommerce form, perhaps write it out to the page somewhere so the user can see how much they are paying etc. Basically, you couldn't really take this and drop it into a form and have it work, it would need to be tailored specifically to your implementation. But hopefully sets you on the right track.
Perhaps another Squiz-ite with E-Commerce experience could comment on the functionality we have to tackle issues like this.
[/quote]
Great, thanks very much for this level of detail this helps clarify which bits are doing what. I think I'll have a bit more of a play and a read to try and educate myself a bit more.
Anyone want to dedicate some time to writing an e-commerce tut over at the Community site? We desperately want to share this knowledge around the community. PM me or Nic and we'll help organise…
[quote]
Anyone want to dedicate some time to writing an e-commerce tut over at the Community site? We desperately want to share this knowledge around the community. PM me or Nic and we'll help organise…
[/quote]
Yes. Please.
[quote]
Anyone want to dedicate some time to writing an e-commerce tut over at the Community site? We desperately want to share this knowledge around the community. PM me or Nic and we'll help organise…
[/quote]
I am pretty sure that Aleks promised that he would do this!