Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Adjustments Refactoring

Ryan Bigg
February 26, 2014

Adjustments Refactoring

A talk that goes into the reasons why we refactored Spree's adjustments system.

Ryan Bigg

February 26, 2014
Tweet

More Decks by Ryan Bigg

Other Decks in Programming

Transcript

  1. 2. Discounts + Credits "Use 10off to get 10% off

    this weekend!" "We screwed up. Have $20 off your whole order."
  2. 8. Allow multiple discounts per order "Can I combine a

    free shipping promotion and a 10% off promotion?" "You can't!"
  3. A. Avoid excessive calculations B. Avoid multiple adjustments per line

    item C. Not overly complicate things Ground Rules
  4. A. Avoid excessive calculations B. Avoid multiple adjustments per line

    item C. Not overly complicate things Ground Rules
  5. A. Avoid excessive calculations B. Avoid multiple adjustments per line

    item C. Not overly complicate things Ground Rules
  6. "Clothing and footwear under $110 are exempt from New York

    City and NY State Sales Tax. ! Purchases above $110 are subject to a 4.5% NYC Sales Tax and a 4% NY State Sales Tax." http://www.nyc.gov/html/dof/html/business/nys_sales_tax.shtml
  7. OR

  8. Old Adjustments * Source - Thing doing the adjustment *

    Originator - Maybe same as source, maybe not * Adjustable - Thing being adjusted * Amount - Self-explanatory
  9. 1. tax included in price (i.e. GST) 2. default tax

    zone is the same as the order's zone IF THEN Purchases in same country as store (price inc.) Adjustment Line Item Line Item Line Item Adjustment Adjustment 1. Apply adjustments to every single line item
  10. 1. tax included in price (i.e. VAT) 2. default tax

    zone is NOT the order's zone IF THEN 1. apply one big negative adjustment to the entire order (a refund) Purchases outside of the country (price inc.) Adjustment Order
  11. Spree < 2.2 - 10% VAT $1.82 tax refund $1.82

    tax refund 1 whole-order adjustment for $3.64
  12. 1. tax is NOT included in price (i.e. sales tax)

    THEN 1. apply one big adjustment to the whole order Purchases in country (price excl.) Order Adjustment
  13. Spree < 2.2 - 7% Sales Tax (NY) 1 whole-order

    adjustment for $2.78 + $1.39 tax + $1.39 tax
  14. Adjustment Line Item Line Item Line Item Adjustment Adjustment Adjustment

    Adjustment Adjustment Line Item Line Item Line Item Spree 2.2+ +
  15. Spree 2.2+ - 10% GST $3.63 tax incl. $1.82 tax

    incl. 2 $39.98 $59.97 $59.97 1 adjustment for $3.63, 1 adjustment for $1.82
  16. Spree 2.2+ - 7% Sales Tax 1 adjustment per line

    item for $1.39 + $1.39 tax + $1.39 tax
  17. Spree 2.1+ Adjustments * Source * Originator * Adjustable *

    Amount * Included? - Counts towards final total
  18. * Source * Originator * Adjustable * Amount * Included?

    - Counts towards final total Spree 2.2+ Adjustments
  19. Shipment Adjustment * Source = Shipment * Originator = ShippingMethod

    * Adjustable = Order Spree 2.1 Shipment Adjustment * Source = TaxRate * Adjustable = Shipment Spree 2.2
  20. $2 off $2 off Spree < 2.2 - 10% off

    promotion 1 Order Adjustment for -$4
  21. $2 off $2 off Spree 2.2+ - 10% off promotion

    1 adjustment per line item for -$2
  22. Promotion Handlers Cart 1. Find all non-code or path promotions

    2. Check if they're eligible for that line item or order 3. Activate
  23. Promotion Handlers Coupon 1. Find promotion matching coupon code 2.

    Validate promotion usage limit & eligiblity 3. Attempt application of promotion to order 4. Report on success of application
  24. Promotion Handlers Free Shipping 1. Find all 'Free Shipping' promotion

    actions 2. Check eligibility for order 3. Activate
  25. Promotion Handlers Page 1. Find promotion for specified path 2.

    Check eligibility for order 3. Activate
  26. "Can I combine a free shipping promotion and a 10%

    off promotion? " "You can!" ORDER SUMMARY Item Total: $1,599.00 Sales Tax $80.45 - Free Shipping Promotion (10% off) Order Total: $1,511.51 -$167.95
  27. Commandment B: Avoid multiple adjustments per item. Oops. One promotion

    adjustment. One credit adjustment. One taxation adjustment.