backdrop-contrib / ubercart

A flexible but easy-to-use e-commerce system for Backdrop.
GNU General Public License v2.0
4 stars 9 forks source link

Packages for USPS shipments #498

Open oadaeh opened 4 months ago

oadaeh commented 4 months ago

I'm not sure the words I need to use to ask the question(s) I need to ask (since it seems every word seems to have two or meanings, and not all of the meanings are commonly used).

What I want to know is how I can specify the physical packages/boxes/etc available for a USPS shipment that can contain whatever number of whatever products, based on the dimensions of the packages and products.

Based on my searching through the code and clicking around the UI, there are only two available for USPS: Envelope and Small package. Also, they aren't modifiable, nor is it possible to add more packages. Also, also, it does not seem that the code actually verifies if the products can fit in them (at least based on dimensions). However, it looks like the UPS module has all those features included in it.

Am I missing something? Is it possible to add boxes to be used for calculating the number of items that can fit in them for a USPS shipment? If it is, how?

Thank you.

bugfolder commented 3 months ago

It is possible to add boxes, etc., but a significant amount of programming is needed. uc_usps is pretty bare-bones. Some years back I wrote a heavily modified version of this module for a site. Because it has some site-specific aspects to it, I'm not releasing it as a contrib module, but it might provide some guidance for making your own modified version of uc_usps. We've been using it now for about 10 years (eight years on D7, the last two years on B).

I'm posting the README for the module below for information. If it looks like it might be useful, DM me on Zulip and I'll make the code available to you.


Ubercart USPS (OUSA)

This module (uc_usps_ousa) is a replacement for the uc_usps module that is part of Ubercart shipping. You should use either this or uc_usps, but not both. Thus module is best suited when you are packing multiple products into a given package, and/or you will ship different packages at different rates, and/or different products have unique packaging requirements (e.g., paper that goes in a tube). This module packs the product into one or more packages, finds the cheapest USPS rate for the set (including fixed-size priority mail boxes), then returns a single total rate for the entire set.

Installation

Install this module like any other module: add the folder to your modules directory (or your custom module directory) and enable the module in the site administration.

See USPS API information here.

How to Use

This module replaces the stock Ubercart USPS module, and so it has both similarities and differences. The basic notion is that for each product, you assign it a USPS "container" (which you can think of as a specialization of the small_package shipping type that is used by other Ubercart shipping modules; all products shippable by this module must be small_package, and if this is the only shipping module you use, you might as well set small_package to be the store default).

Packages also are characterized by this container field. If you select the "all in one" packing option, then this module will try to pack multiple products into a single container that is compatible with that type of product. In the initial release, the 3 types of container are ENVELOPE_OR_BOX, BOX_ONLY, and LARGE_PAPER_TUBE. Products that are ENVELOPE_OR_BOX can go into either ENVELOPE_OR_BOX or BOX_ONLY type packages, but BOX_ONLY products can't go into ENVELOPE_OR_BOX packages. LARGE_PAPER_TUBE products only go into LARGE_PAPER_TUBE packages. And so on.

The process of packing products into packages, and getting rate quotes on packages, is very different from uc_usps. In uc_usps, the module gets multiple rate quotes and lets the user select the rate he/she wants, but only a single shipping rate is considered for all packages. This is problematic when there are multiple packages of different types (e.g., envelopes and differently-sized boxes). So in this module, after packaging up the products, we get a different rate quote for each package, then the module selects the lowest-price quote for each package. The results of all the different rate quotes are summed together and presented as a single combined postage cost (so there's no user choice).

The process of packaging products is also different from what takes place in uc_usps. For each package, we compute a size based on a vertical stack of all products in the package. (That's a pretty good method for flat things like books and paper; not so good for odd sizes.) This package size is used when getting rate quotes: while USPS will return many rates, we filter those rates against the known size limits of the various rate settings (envelopes, flat rate boxes, etc.). So, for example, if the size fits within one of the (cheaper) flat-rate boxes, we'll use that box, rather than a more general weight-based rate.

Since some products don't work very well with this relatively basic package size calculation, it is also possible for some packages to override the computed size. This works, for example, for paper that is shipped in a tube.

While the user only sees the number of packages and total shipping cost, details of each package (its specific rate, dimensions, weight, and which products go into it) are posted as an admin comment in the order record for the utility of the fulfillment team.

Module Configuration Settings

In the module configuration (Store Administration > Shipping Quote Settings > Quote Methods), there's a block called Services that contains blocks of checkboxes for all of the USPS domestic and international services, one set for each of the product containers. You'll select the services that you want to apply to each type of container. If you (programmatically) add additional containers (see below), new blocks will automatically appear here.

The "Quote options" are the same as in the uc_usps module.

In "Markups", you have three types of markup to apply. The first is a weight markup, that adds a fixed weight, percentage, or multiple to each package before getting a USPS rate quote. This allows you to include an estimated weight of packing materials, for example. (Weight is ignored for flat-rate containers. You have to pick a single value that applies to all possible products, though this could be overridden programmatically.) The second markup is a markup applied to each package after the quote is received. This markup allows you to include a handling charge per package. The third is a markup applied to the total order (this is equivalent to the markup in uc_usps).

Note: the heterogeneous packaging functionality is intended primarily to support the "all in one" quote option. If you choose the "each in own" option, then each product will get its own package (possibly broken into multiples based on quantity limits per package). The system will still seek the best rate for each individual package.

Adding more containers

This module was written with the goal of being easily extensible programmatically. You can add more containers by editing the code in the module. The logic of a new package can get rather complex (see, for example, the logic for dealing with a mix of ENVELOPE_OR_BOX and BOX_ONLY products), and so rather than trying to support everything someone might want to do via UI manipulations, I've just tried to make it easy to find where you make programmatic changes to customize the module for your particular situation. For the simplest situations, you will simply add elements to some of the arrays defined at the end of the .module file.