Matt Cashatt
Matt Cashatt

Reputation: 24208

Open Cart Free Shipping Exception

I offer free online shipping for orders totaling over $75 dollars and the process for offering this discount is straight forward.

I will soon add some items to my inventory that are bulky and need to be exempted from the Free Shipping discount because the shipping cost on these items will make the transaction result in a loss of money if the buyer does not pay the shipping.

In Open Cart, how do I exempt certain items from the "Free Shipping over $75" policy? I am guessing this will have to be done in code, but I am not sure where to look.

Upvotes: 1

Views: 3210

Answers (2)

Paul Gregory
Paul Gregory

Reputation: 1753

Actually, the process for offering free delivery in OpenCart with the standard shipping extensions is dumb. It offers customers the choice of the calculated delivery or the free delivery! This only really makes sense if the delivery is different - ie free delivery is slower.

As you want to exempt purchases from free delivery, rather than having a lower priced delivery option, I assume that currently you simply make a bit more money when any customer chooses the paid delivery when free delivery is available.

What I strongly suggest you do is combine the two rules into one shipping extension. This will not only allow you to remove the free delivery rate, but it will not show the paid delivery option when it would be stupid.

Where do you find this code?

Each of the shipping calculation options in the Admin section is a shipping extension. This is divided into five files.

The logic is in catalog\model\shipping, admin controls are in admin\controller\shipping and admin\view\template\shipping. There's also language in catalog\language\english\shipping and admin\language\english\shipping. In all these folders the filename should be the same.

You can add your own shipping extension by taking the files from your existing 'free' shipping extension and duplicating them with new filenames and matching classnames, or you can hack your existing extension.

If you are creating your extension from a copy of an existing extension, don't forget to amend the class names accordingly (eg change the Free part in ModelShippingFree, ControllerShippingFree to match your filename).

Because I always end up using store-specific rules, I always name these files after the store. This also makes it more obvious which one should be active.

Before you get bogged down in writing the code, work out what your ideal combined rules should be in pseudo-code, for example if you have a flat rate for non-bulky products and you've only actually set the Weight to be greater than 0 on products that are bulky, it would be something like:

if subtotal>75 then cost=0 else cost=10 if totalweight > 0 then cost = cost + (1*totalweight)

Look at all the existing extensions for example code that you can use and adapt, and figure out which values you are happy hardcoding and which you need to adjust in the Admin settings.

(You can get totalweight from $this->cart->getWeight and the subtotal from $this->cart->getTotal())

If you are already using weight, then unless you can still tell that there's a bulky product in the cart because the totalweight is so high, the coding gets much harder. You will have to step through each item in the cart and add up the 'bulky' products that match some other pattern. Look first at fields that you can edit within OpenCart.

Finally, to avoid surprises, don't forget to change your text screens to mention that the free shipping does not apply to bulky items, and change your product screens to show that a product is bulky and exempt from free shipping.

Upvotes: 4

Jay Gilford
Jay Gilford

Reputation: 15151

On a standard OC setup this won't be possible. You'll need to code in some kind of flag you can set products to be excluded, and then in the model file of the free shipping extension you'll have to re-code it to calculate the cost of items that don't have the flag only. The standard cart just uses the $this->cart->getTotal() which won't exclude the flagged items

Upvotes: 1

Related Questions