Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 2.35 KB

File metadata and controls

37 lines (26 loc) · 2.35 KB

plata order processors

plata is a shopping cart experience built in Django, and I've been using it for the last 6 months but somehow not written a single TIL about it. It's really well documented!

Order processors

Order Processors in the docs

Plata has a setting PLATA_ORDER_PROCESSORS:

The list of order processors which are used to calculate line totals, taxes, shipping cost and order totals.

The classes can be added directly or as a dotted python path. All classes should extend ProcessorBase.

In Order.recalculate_total(), we cycle through all of the processes in this setting and run the process() method on the order. But what's a process?

We can take a look at Plata's default settings:

PLATA_ORDER_PROCESSORS = getattr(
    settings,
    "PLATA_ORDER_PROCESSORS",
    [
        "plata.shop.processors.InitializeOrderProcessor",
        "plata.shop.processors.DiscountProcessor",
        "plata.shop.processors.TaxProcessor",
        "plata.shop.processors.MeansOfPaymentDiscountProcessor",
        "plata.shop.processors.ItemSummationProcessor",
        "plata.shop.processors.ZeroShippingProcessor",
        "plata.shop.processors.OrderSummationProcessor",
    ],
)

They contain all of the code that decides what the final total is. You can include or exclude the ones based on your needs. In my case, one of those was indeed the source of my bug... which I learned today was actually a feature: ZeroShippingProcessor. It's well-named, and it was the reason I couldn't save the shipping to the order. I was removing the shipping, literally setting it to zero.

Everything became clearer after that. As much as I love free shipping, I removed that class, and implemented a variation of the FixedAmountShippingProcessor.