Discount calculation includes all adjustments.

Created on 13 December 2024, 5 days ago

Problem/Motivation

On the purchase event, an item level discount value is passed. The discount value is captured by subtracting the adjusted unit price from the item price.

By default ->getAdjustedUnitPrice() will return a price minus fees, promotions, taxes. I think in most cases the customer will expect the discount field to subtract only the promotion. I could certainly be wrong.

Steps to reproduce

Add a taxed item to cart and check the value of the discount within Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\PurchaseEvent.

Proposed resolution

I have two possible ideas, we could make the value configurable, allowing choice/combination of the values. Likely there is already code that allows us to pull adjustment types and populate options. getAdjustedUnitPrice() already allows us to pass an array of the adjustments we want, so we just spit out our configured array into line 78 of PurchaseEvent.

Or, if we think no one will ever want their fees and taxes to count as a discount, we simply hardcode the option. I'm pretty heavily leaning towards this, as I can only imagine taxes and fees in a discount causing confusion.

Which is how I ended up here in the first place.

Remaining tasks

Do it.

User interface changes

None, depending.

API changes

None.

Data model changes

None.

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States kazajhodo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024