Forum for discussing general topics related to Couch.
10 posts Page 1 of 1
I've been wondering for a while now, is there any way, as mentioned in the title, to create a custom shipping calculation for couchcart?

More specifically I've created a custom field for each product which contains its weight, and i want to calculate the shipping based off of this. E.g. if the total weight adds up to 500 grams the charge would be 2$, but if the weight added up to over 1 kg the charge would then be 3.5$.

Would this be possible?

Thanks in advance
Hi,

Yes we can certainly use custom shipping calculations.
The documentation outlines some common calculations (http://www.couchcms.com/docs/concepts/s ... art-2.html) but also admits -
Please keep in mind that this is just my implementation of the required calculations. As I said, I've tried to cover some of the most common ways of doing them. However, it might, or might not, be suitable for your client's business requirements.
In case it is not, feel free to tweak, modify heavily or even discard this implementation completely and put in your version tailored to your specific needs.

To do so, however, will require PHP. Do you think you'd be fine with that?
If so, the 'cart_ex.php' has a 'get_shipping' function that you can modify to do your calculations.

Use an editable region named 'pp_shipping_scale' to input the weight dependent scale and then base your calculation off it.

Do let us know if you require any assistance with the process.

Thanks.
Thanks for the quick reply KK! :D

Well, honestly I'm not that experienced in PHP at all.. So I think this would become quite the challenge for me, but I can always try to give it a go!

But i might (quite probably) need some help to get this implemented, but as mentioned, I can always try to have a go at it myself, since I assume that you have more important things to take care of :)
i might (quite probably) need some help to get this implemented
Not a problem at all, Lasse :)

I'll try and get something coded up for you (would be useful for others too).

Can you please give me some real-world data that you'd be using? E.g. take 2-3 products and let me know what the shipping scale would be like. Basically something I can test my code with.

Thanks
That sounds fantastic!

Okay well, here's three individual products:

Product nr. 1 weighs 100 grams
Product nr. 2 weighs 200 grams
Product nr. 3 weighs 350 grams

When the total order weighs between 0-500g the shipping should be 4$, 501-1000g = 7.5$ and finally 1001g+ = 10$

I hope you're able to come up with a solution for this, and again thank you so much! :D
Hello again KK,
How is everything going with the php-script? :)
Do you still believe that it is possible, or should i try to come up with another solution?
Apologies for the delay, lasselupe33.
Please give me a day more.

Thanks.
Hi lasselupe33,

Apologies again for the delay.
As promised, here is your shipping calculator that uses the total weight of the cart to get a shipping charge.

I am attaching a modified 'cart_ex.php'. Please extract it and place it within 'couch/addons/cart' folder (replacing the original file of the same name, if it exists).
cart_ex.zip
(5.45 KiB) Downloaded 410 times

There are two modifications that you need to do to get things working -
1. Add an editable region to the products template to allow specifying each item's weight.
2. Set the shipping charges scale in the config file.

Here is how you do it -
1. Edit your products template (in our sample it is index.php) and add the definition highlighted below immediately after the 'pp_requires_shipping' field
<cms:editable
name='pp_requires_shipping'
label='Requires shipping'
desc='Select No if this is not a physical product that requires shipping'
opt_values='Yes=1 | No=0'
opt_selected = '1'
type='radio'
group='group_shipping'
order='10'
/>
<cms:editable
name='pp_weight'
label='Weight'
desc='Weight in grams'
maxlength='10'
search_type='decimal'
validator='non_negative_decimal'
width='150'
type='text'
group='group_shipping'
order='10'
/>


Visit the template as super-admin and now you should see a region for specifying weight in the admin.

2. Edit the config file (couch/addons/cart/config.php) and add the code highlighted below just after the 'Ship by quantity ordered' setting.
// Ship by quantity ordered:
// Set the option below if you want to set up a sliding scale of shipping charges based on the number of items in cart.
// For example, if you charge $3 to deliver one to five books, $7 to ship six to 15 books, and $10 to ship more than 15 books,
// set it to '[ 0=3 | 5=7 | 15=10 ]'
// where the string above stands for '3 for more than 0, 7 for more than 5, 10 for more than 15'
$pp['shipping_by_quantity_ordered'] = '';

// Shipping by weight ordered:
// Set the option below if you want to set up a sliding scale of shipping charges based on the order's total weight.
// For example, when the total order weighs between 0-500g the shipping should be 4$, 501-1000g = 7.5$ and finally 1001g+ = 10$
// set it to '[ 0=4 | 500=7.5 | 1000=10 ]'
// where the string above stands for '4 for more than 0, 7.5 for more than 500, 10 for more than 1000'
$pp['shipping_by_weight_ordered'] = '[ 0=4 | 500=7.5 | 1000=10 ]';


/*
Discounts
*/
// Discount by order total:

Add your values to the scale shown in red.

And that should be it.
Any product that has 'required shipping' set to 'Yes', will have its weight taken into consideration while calculating the shipping charges.

Hope this helps.
Please let us know.

Thanks.
Thank you so much KK, this was just what i had in mind! :D
I have tested it out, and it is working perfectly

And as a side note, this is a fantastic CMS, I've enjoyed working with it a lot! - and now I can add a great support to the large list of plusses about it :)
You are welcome, lasselupe33 :)
I am glad you found the solution useful.
10 posts Page 1 of 1
cron