-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
[BUGFIX] Proper storage of taxes for an order #521
Conversation
Tax fields were not shown as they were not referenced because they were prefixed with `order_`.
This setting is removed since TYPO3 v7, see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/7.4/Breaking-67753-DropSecondaryOptions.html#tca
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
OrderItem $orderItem, | |
OrderItem $orderItem, | ||
string $typeOfTax | ||
): OrderItem { | ||
$cart = $event->getCart(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
$cart = $event->getCart(); | |
$cart = $event->getCart(); | |
$orderItem = $event->getOrderItem(); |
|
||
/** @var int $taxClassId */ | ||
/** @var float $tax */ | ||
foreach ($taxes as $taxClassId => $tax) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you 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); |
There was a problem hiding this comment.
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:
$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' |
There was a problem hiding this comment.
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?
identifier: 'cart--order--create--persist-order--tax' | |
identifier: 'cart--order--create--persist-order--taxes' |
0af2151
into
extcode:bugfix/312/multiple-tax-entries-v2
Render fields tax and orderTax in BE List module.
Fixes: #312, #509