Problem/Motivation

\Drupal\commerce_google_tag_manager\EventTrackerService::purchase is missing to calculate tax costs.

Proposed resolution

Calculate tax costs and submit it as part of purchase data.

Remaining tasks

  • Write a patch
  • Write a test to cover - shipping, taxes (included & excluded from price) and total price value

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mbovan created an issue. See original summary.

mbovan’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
2.15 KB

I am submitting a patch that adds tax costs.

schtifu’s picture

Status: Needs review » Needs work

Thanks for your contribution mbovan, looking good! Just two things:

1)
public function calculateTax(OrderInterface $order) {
Could you make this private since it is a helper method and not part of the public API of EventTrackerService.

2) Do you have time to extend the test cases to cover this feature? I can do it if you don't find the time :)

P.S. If you prefer, you can also send a pull request via GitHub: https://github.com/gridonic/commerce_google_tag_manager

Cheers

mbovan’s picture

Thanks for the feedback @schtifu.

Please find the attached patch that changes the method to private.

Unfortunately, I will not have time at the moment to write tests. Feel free to work on it.

wengerk’s picture

Issue summary: View changes
FileSize
2.97 KB
3.48 KB

Many thanks for your contrib !!

Sorry it takes me ages to get into this issue ...
Here is a reroll patch, I will work on a functional tests asap.

wengerk’s picture

Here is the same patch with a tests ensuring \Drupal\commerce_google_tag_manager\EventTrackerService::purchase apply 'revenue' and 'taxes' properly when included or excluded from the unit_price of product

wengerk’s picture

oupsy, I added the file tests/src/Functional/PurchaseTest.php which should not be part of those patches ...

wengerk’s picture

here a fix, a Unit test was broken since we make a call to collectAdjustments and this call was not mocked

wengerk’s picture

wengerk’s picture

Issue tags: -Needs tests
mbovan’s picture

Thanks for taking the time to work on tests!

I am not sure if it is worth testing a case when there are 2 different tax rates applied to 2 different order items?

+++ b/src/EventTrackerService.php
@@ -279,8 +280,10 @@ public function purchase(OrderInterface $order) {
+            // The revenu should be the total value (incl. tax and shipping).

Small typo on "revenu".

wengerk’s picture

Yay you'r right, here is a refactored tests coverage.

wengerk’s picture

Status: Needs review » Reviewed & tested by the community
wengerk’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.