Jump to content
wisekurt

Restrict Shipping Method for 2.3

Recommended Posts

This is the official support thread for Restrict Shipping Method for 2.3.

 

This addon allows you to restrict shipping types/methods for certain products, or alternatively exclude certain shipping types for products. It is very effective if for example you have an item for sale in your shop that can ONLY be sent via courier but not post. So "courier" can be set as the restricted type of shipping method and enabled in (by selecting "1") that product.

 

This addon is a modification of the "Restrict Delivery" addon for 2.2 by idolcemia, including modifications suggested by ReDYeViL.

I have added instructions to allow you to modify which products are the restricted class in the admin backend (categories.php), where previously you had to modify it directly through the SQL database which can be extremely tedious. I changed the name of the addon to help with search results (personally it took me ages stumbling to find the original).

 

See the addon here: http://addons.oscommerce.com/info/9071

 

Full credit to the original author idolcemia for the original code and addon.

Share this post


Link to post
Share on other sites

Besides restricting shipping choices for various products, would this be a good base for other restrictions on a product? For example, some cities or states may not allow certain "weapons" (e.g., knives or swords) to be shipped to addresses within them, or require an affidavit that the purchaser is of a certain age. Some products might be subject to national export (or import) controls, and thus can't be shipped to certain countries. Some products may be considered hazardous, and refused by certain shippers, but this is probably already handled. So, given a shipping address (and/or age), some products might have no shipping method at all, and would have to be deleted from the order, while others would have a restricted choice of shippers (you might choose to bundle the entire order together, even at a less attractive rate, rather than ship part by one shipper and part by another.

 

Finally, it would be good to have icons indicating shipping restrictions, to appear on a product listing page (wherever a customer could add it to the cart). For example, if FedEx won't handle it, you could have red-circle-slash "FedEx", or if you must be 21 to purchase, red-circle-slash "under 21" (or green-circle "over 21"). That sort of thing. They could trigger the "signing" of an affidavit that the purchaser is over some minimum age, although I don't know how much legal protection that would give you (it might be worthwhile to consult a lawyer, if you're selling such things). It's worth considering, rather than having all sorts of different ways to restrict shipping for various reasons.


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get (stable) Frozenpatches or (unstable) Edge. See also the naming convention and the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

Besides restricting shipping choices for various products, would this be a good base for other restrictions on a product? For example, some cities or states may not allow certain "weapons" (e.g., knives or swords) to be shipped to addresses within them, or require an affidavit that the purchaser is of a certain age. Some products might be subject to national export (or import) controls, and thus can't be shipped to certain countries. Some products may be considered hazardous, and refused by certain shippers, but this is probably already handled. So, given a shipping address (and/or age), some products might have no shipping method at all, and would have to be deleted from the order, while others would have a restricted choice of shippers (you might choose to bundle the entire order together, even at a less attractive rate, rather than ship part by one shipper and part by another.

 

Finally, it would be good to have icons indicating shipping restrictions, to appear on a product listing page (wherever a customer could add it to the cart). For example, if FedEx won't handle it, you could have red-circle-slash "FedEx", or if you must be 21 to purchase, red-circle-slash "under 21" (or green-circle "over 21"). That sort of thing. They could trigger the "signing" of an affidavit that the purchaser is over some minimum age, although I don't know how much legal protection that would give you (it might be worthwhile to consult a lawyer, if you're selling such things). It's worth considering, rather than having all sorts of different ways to restrict shipping for various reasons.

 

Sure all of this would be relative easy to do. The code to integrate some type of "icon" or notification that an order is unavailable is a good idea.

 

I quickly knocked up this code taking advantage of the other loop on the page to achieve exactly this:

 

checkout_shipping.php

Find (approximately line 295):

<tr>
<td colspan="3"><strong><?php echo $quotes[$i]['module']; ?></strong> <?php if (isset($quotes[$i]['icon']) && tep_not_null($quotes[$i]['icon'])) { echo $quotes[$i]['icon']; } ?></td>
</tr>

 

Replace with:

<?php
if ($order->restrict_delivery == false || in_array($quotes[$i]['module'], $restrict_delivery_allowed) ) {
echo '<tr><td colspan="3"><strong>' . $quotes[$i]['module'] . '</strong> ';
if (isset($quotes[$i]['icon']) && tep_not_null($quotes[$i]['icon'])) { echo $quotes[$i]['icon'] . '</td></tr>'; }
} else {
echo '<tr><td colspan="3"><strong>' . $quotes[$i]['module'] . '</strong> ';
if (isset($quotes[$i]['icon']) && tep_not_null($quotes[$i]['icon'])) { echo $quotes[$i]['icon']; }
echo '(Unavailable on this order)</td></tr>';
}
?>

 

You only need to change the text "(Unavailable on this order)" to what ever you want. This could be a static image e.g. <img src="" alt=""/>

I will implement this code into the next version if there is enough interest.

 

To use this code to pick up on DOB or the accounts state you would only really need to change what restrict_delivery actually refers to (which is currently a shipping type). But yes it can be done.

Edited by wisekurt

Share this post


Link to post
Share on other sites

Does this Mod work? I put in both "ground" and "Ground" for UPS, then added 1 in the product field I want restricted, but USPS is showing its options as well.. 

Edited by opus_uno2001

Share this post


Link to post
Share on other sites

I was unable to limit to specific options within a shipping method (like "Ground").  However, when I put "United Parcel Service" in, only UPS options showed.  

 

Edit: Also, this mod is very specific.  If you add a method, be sure you separate it with ONLY a semicolon - no spaces.

Edited by Supertex

Share this post


Link to post
Share on other sites

Does this Mod work? I put in both "ground" and "Ground" for UPS, then added 1 in the product field I want restricted, but USPS is showing its options as well.. 

 

Yes it works. Most likely what is happening here is the name of the shipping has a variable in it e.g. it gives the shipping time dynamically in the name. The mod looks for the name as its identifier, this is why I suggest flat rate as the best method. Otherwise you will need to modify the code for your shipping module so it doesn't implement time/weight quotes within the actual name itself.

 

 

I was unable to limit to specific options within a shipping method (like "Ground").  However, when I put "United Parcel Service" in, only UPS options showed.  

 

Edit: Also, this mod is very specific.  If you add a method, be sure you separate it with ONLY a semicolon - no spaces.

 

The only reason "Ground" wouldn't work is the above explanation, but it is good to know you got UPS to work. And yes the items must be separated by semi colon only. I didn't take much notice of this while writing up the guide.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×