Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Proper storage of taxes for an order #521

Conversation

rintisch
Copy link
Collaborator

@rintisch rintisch commented Jun 4, 2024

Render fields tax and orderTax in BE List module.

  • Remove obsolete TCA settings canNotCollapse.
  • Proper TCA configuration for taxes by introducing foreign_match_fields to correctly resolve relations.
  • Add EventListener to persist taxes during an order process.
  • Remove code which created unrelated tax records when ordering a product with BE variants.

Fixes: #312, #509

rintisch added 5 commits May 31, 2024 18:36
Tax fields were not shown as they were not
referenced because they were prefixed with
`order_`.
An order has two different taxes:
* `tax`: That's the tax for all the products in
  the cart.
* `totalTax`: That's the tax for the whole order
  which includes the tax from above plus tax on
  services like shipping and/or payment.

Before this bugfix the taxes were not persisted
properly because the relation was not correct
implemented in TCA. By introducing the
`foreign_match_fields` the relations are correctly
resolved.

Fixes: extcode#312
This adds an EventListener which persists the
fields `tax` and `totalTax` for an orderItem so
that those values can be used for PDFs and of
course also to show them in the BE view.

Fixes: extcode#509
During an order the EventListener created tax
records. These records are never used and not even
configured in the TCA so they are not even related
to the orderProduct after there creation (field
`item` is `0` after persisting them in the table.)
);
$orderTax->setPid($this->storagePid);

$this->taxRepository->add($orderTax);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think the $this->taxRepository isn't needed anymore in this class. Could the property and inject-method can also be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@extcode I have unfortunately no laptop with me, just a smartphone with the GitHub app. If you want to merge it quick you need to adapt the code yourself. All the proposals look good to me.


protected function addTaxToRepositoryAndItem(
PersistOrderEventInterface $event,
OrderItem $orderItem,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the extra function parameter $orderItem? We can get it from $event in this method again.

Suggested change
OrderItem $orderItem,

OrderItem $orderItem,
string $typeOfTax
): OrderItem {
$cart = $event->getCart();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above.

Suggested change
$cart = $event->getCart();
$cart = $event->getCart();
$orderItem = $event->getOrderItem();


/** @var int $taxClassId */
/** @var float $tax */
foreach ($taxes as $taxClassId => $tax) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change:

Suggested change
foreach ($taxes as $taxClassId => $tax) {
foreach ($taxes as $taxClassId => $taxValue) {

you can remove the new variable in line 55.

foreach ($taxes as $taxClassId => $tax) {
$taxValue = $tax;
$taxClass = $taxClasses[$taxClassId];
$orderTax = GeneralUtility::makeInstance(OrderTax::class, $taxValue, $taxClass);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is also readable:

Suggested change
$orderTax = GeneralUtility::makeInstance(OrderTax::class, $taxValue, $taxClass);
$orderTax = GeneralUtility::makeInstance(OrderTax::class, $taxValue, $taxClasses[$taxClassId]);

to we do not need the variable assignment.

Extcode\Cart\EventListener\Order\Create\PersistOrder\Taxes:
tags:
- name: event.listener
identifier: 'cart--order--create--persist-order--tax'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My syntax for the identifier is related to the class name. Can you change this?

Suggested change
identifier: 'cart--order--create--persist-order--tax'
identifier: 'cart--order--create--persist-order--taxes'

@extcode extcode changed the base branch from main to bugfix/312/multiple-tax-entries-v2 June 8, 2024 11:35
@extcode extcode merged commit 0af2151 into extcode:bugfix/312/multiple-tax-entries-v2 Jun 8, 2024
9 checks passed
extcode added a commit that referenced this pull request Jun 8, 2024
extcode added a commit that referenced this pull request Jun 8, 2024
@rintisch rintisch deleted the bug/312/multiple-tax-entries-v2 branch June 11, 2024 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple tax entries.
2 participants