From 806ed47fa6d286229ba2e6622e6e300d044cedbd Mon Sep 17 00:00:00 2001 From: rintisch Date: Fri, 31 May 2024 18:36:39 +0200 Subject: [PATCH 1/5] [BUGFIX] Use tax fields in palettes Tax fields were not shown as they were not referenced because they were prefixed with `order_`. --- Configuration/TCA/tx_cart_domain_model_order_item.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Configuration/TCA/tx_cart_domain_model_order_item.php b/Configuration/TCA/tx_cart_domain_model_order_item.php index ab241902..238a4f91 100644 --- a/Configuration/TCA/tx_cart_domain_model_order_item.php +++ b/Configuration/TCA/tx_cart_domain_model_order_item.php @@ -55,11 +55,11 @@ 'canNotCollapse' => 1, ], 'price' => [ - 'showitem' => 'currency, --linebreak--, currency_code, currency_sign, currency_translation, --linebreak--, gross, net, --linebreak--, order_tax', + 'showitem' => 'currency, --linebreak--, currency_code, currency_sign, currency_translation, --linebreak--, gross, net, --linebreak--, tax', 'canNotCollapse' => 1, ], 'total_price' => [ - 'showitem' => 'total_gross, total_net, --linebreak--, order_total_tax', + 'showitem' => 'total_gross, total_net, --linebreak--, total_tax', 'canNotCollapse' => 1, ], 'pdfs' => [ From 20c8209809046815eaeac8bb11ad94a6f797f095 Mon Sep 17 00:00:00 2001 From: rintisch Date: Fri, 31 May 2024 18:38:59 +0200 Subject: [PATCH 2/5] [TASK] Remove obsolete TCA setting `canNotCollapse` 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 --- Configuration/TCA/tx_cart_domain_model_order_item.php | 5 ----- Configuration/TCA/tx_cart_domain_model_order_payment.php | 2 -- Configuration/TCA/tx_cart_domain_model_order_product.php | 2 -- Configuration/TCA/tx_cart_domain_model_order_shipping.php | 2 -- 4 files changed, 11 deletions(-) diff --git a/Configuration/TCA/tx_cart_domain_model_order_item.php b/Configuration/TCA/tx_cart_domain_model_order_item.php index 238a4f91..ef3af00f 100644 --- a/Configuration/TCA/tx_cart_domain_model_order_item.php +++ b/Configuration/TCA/tx_cart_domain_model_order_item.php @@ -48,23 +48,18 @@ ], 'addresses' => [ 'showitem' => 'billing_address, shipping_address', - 'canNotCollapse' => 0, ], 'numbers' => [ 'showitem' => 'order_number, order_date, --linebreak--, invoice_number, invoice_date, --linebreak--, delivery_number, delivery_date', - 'canNotCollapse' => 1, ], 'price' => [ 'showitem' => 'currency, --linebreak--, currency_code, currency_sign, currency_translation, --linebreak--, gross, net, --linebreak--, tax', - 'canNotCollapse' => 1, ], 'total_price' => [ 'showitem' => 'total_gross, total_net, --linebreak--, total_tax', - 'canNotCollapse' => 1, ], 'pdfs' => [ 'showitem' => 'order_pdfs, --linebreak--, invoice_pdfs, --linebreak--, delivery_pdfs', - 'canNotCollapse' => 1, ], ], 'columns' => [ diff --git a/Configuration/TCA/tx_cart_domain_model_order_payment.php b/Configuration/TCA/tx_cart_domain_model_order_payment.php index cbf08e85..8d0c1126 100644 --- a/Configuration/TCA/tx_cart_domain_model_order_payment.php +++ b/Configuration/TCA/tx_cart_domain_model_order_payment.php @@ -30,12 +30,10 @@ 'showitem' => '', 'service' => [ 'showitem' => 'service_country, service_id', - 'canNotCollapse' => 0, ], ], 'service' => [ 'showitem' => 'service_country, service_id', - 'canNotCollapse' => 0, ], ], 'columns' => [ diff --git a/Configuration/TCA/tx_cart_domain_model_order_product.php b/Configuration/TCA/tx_cart_domain_model_order_product.php index c2e010bb..9369a53b 100644 --- a/Configuration/TCA/tx_cart_domain_model_order_product.php +++ b/Configuration/TCA/tx_cart_domain_model_order_product.php @@ -33,11 +33,9 @@ ], 'price' => [ 'showitem' => 'price, discount, --linebreak--, gross, net, --linebreak--, tax, tax_class', - 'canNotCollapse' => 1, ], 'product_type_and_id' => [ 'showitem' => 'product_type, product_id', - 'canNotCollapse' => 1, ], ], 'columns' => [ diff --git a/Configuration/TCA/tx_cart_domain_model_order_shipping.php b/Configuration/TCA/tx_cart_domain_model_order_shipping.php index efafde3b..f74d2c24 100644 --- a/Configuration/TCA/tx_cart_domain_model_order_shipping.php +++ b/Configuration/TCA/tx_cart_domain_model_order_shipping.php @@ -30,12 +30,10 @@ 'showitem' => '', 'service' => [ 'showitem' => 'service_country, service_id', - 'canNotCollapse' => 0, ], ], 'service' => [ 'showitem' => 'service_country, service_id', - 'canNotCollapse' => 0, ], ], 'columns' => [ From ec3a830ed7aa8e713f2bd6194a814db63242f9a2 Mon Sep 17 00:00:00 2001 From: rintisch Date: Tue, 4 Jun 2024 06:44:17 +0200 Subject: [PATCH 3/5] [BUGFIX] Proper TCA configuration for order taxes 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: #312 --- Configuration/TCA/tx_cart_domain_model_order_item.php | 6 ++++++ Configuration/TCA/tx_cart_domain_model_order_tax.php | 6 +++++- ext_tables.sql | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Configuration/TCA/tx_cart_domain_model_order_item.php b/Configuration/TCA/tx_cart_domain_model_order_item.php index ef3af00f..abeb5c78 100644 --- a/Configuration/TCA/tx_cart_domain_model_order_item.php +++ b/Configuration/TCA/tx_cart_domain_model_order_item.php @@ -407,6 +407,9 @@ 'readOnly' => 1, 'foreign_table' => 'tx_cart_domain_model_order_tax', 'foreign_field' => 'item', + 'foreign_match_fields' => [ + 'record_type' => 'tax', + ], 'maxitems' => 9999, 'default' => 0, ], @@ -419,6 +422,9 @@ 'readOnly' => 1, 'foreign_table' => 'tx_cart_domain_model_order_tax', 'foreign_field' => 'item', + 'foreign_match_fields' => [ + 'record_type' => 'total_tax', + ], 'maxitems' => 9999, 'default' => 0, ], diff --git a/Configuration/TCA/tx_cart_domain_model_order_tax.php b/Configuration/TCA/tx_cart_domain_model_order_tax.php index 54c99860..06b42971 100644 --- a/Configuration/TCA/tx_cart_domain_model_order_tax.php +++ b/Configuration/TCA/tx_cart_domain_model_order_tax.php @@ -18,10 +18,14 @@ 'enablecolumns' => [], 'searchFields' => '', 'iconfile' => 'EXT:cart/Resources/Public/Icons/Order/Tax.svg', + 'type' => 'record_type', ], 'hideTable' => 1, 'types' => [ - '1' => [ + 'tax' => [ + 'showitem' => 'tax, tax_class', + ], + 'total_tax' => [ 'showitem' => 'tax, tax_class', ], ], diff --git a/ext_tables.sql b/ext_tables.sql index 7958d922..e0d24537 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -105,6 +105,7 @@ CREATE TABLE tx_cart_domain_model_order_tax ( pid int(11) DEFAULT '0' NOT NULL, item int(11) unsigned DEFAULT '0' NOT NULL, + record_type varchar(255) DEFAULT '' NOT NULL, tax double(11,2) DEFAULT '0.00' NOT NULL, tax_class int(11) unsigned DEFAULT '0' NOT NULL, From 2c7b09533d691363bc262a5e1b2d4d1b9621d792 Mon Sep 17 00:00:00 2001 From: rintisch Date: Tue, 4 Jun 2024 07:09:01 +0200 Subject: [PATCH 4/5] [BUGFIX] Persist taxes for order item 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: #509 --- .../Order/Create/PersistOrder/Taxes.php | 71 +++++++++++++++++++ Configuration/Services.yaml | 7 ++ 2 files changed, 78 insertions(+) create mode 100644 Classes/EventListener/Order/Create/PersistOrder/Taxes.php diff --git a/Classes/EventListener/Order/Create/PersistOrder/Taxes.php b/Classes/EventListener/Order/Create/PersistOrder/Taxes.php new file mode 100644 index 00000000..9832966e --- /dev/null +++ b/Classes/EventListener/Order/Create/PersistOrder/Taxes.php @@ -0,0 +1,71 @@ +getOrderItem(); + + $orderItem = $this->addTaxToRepositoryAndItem($event, $orderItem, 'tax'); + $orderItem = $this->addTaxToRepositoryAndItem($event, $orderItem, 'totalTax'); + + $this->itemRepository->update($orderItem); + $this->persistenceManager->persistAll(); + } + + protected function addTaxToRepositoryAndItem( + PersistOrderEventInterface $event, + OrderItem $orderItem, + string $typeOfTax + ): OrderItem { + $cart = $event->getCart(); + $storagePid = $event->getStoragePid(); + $taxClasses = $event->getTaxClasses(); + + $taxes = $typeOfTax === 'tax' ? $cart->getTaxes() : $cart->getTotalTaxes(); + + /** @var int $taxClassId */ + /** @var float $tax */ + foreach ($taxes as $taxClassId => $tax) { + $taxValue = $tax; + $taxClass = $taxClasses[$taxClassId]; + $orderTax = GeneralUtility::makeInstance(OrderTax::class, $taxValue, $taxClass); + $orderTax->setPid($storagePid); + + $this->taxRepository->add($orderTax); + + if ($typeOfTax === 'tax') { + $orderItem->addTax($orderTax); + } else { + $orderItem->addTotalTax($orderTax); + } + } + + return $orderItem; + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index f2dd367e..12144b98 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -49,6 +49,13 @@ services: event: Extcode\Cart\Event\Order\PersistOrderEvent after: 'cart--order--create--persist-order--item' + Extcode\Cart\EventListener\Order\Create\PersistOrder\Taxes: + tags: + - name: event.listener + identifier: 'cart--order--create--persist-order--tax' + event: Extcode\Cart\Event\Order\PersistOrderEvent + after: 'cart--order--create--persist-order--tax-classes' + Extcode\Cart\EventListener\Order\Create\PersistOrder\Products: tags: - name: event.listener From e827cfe3fab97d9d4b02fe622db19018025402d6 Mon Sep 17 00:00:00 2001 From: rintisch Date: Tue, 4 Jun 2024 07:09:29 +0200 Subject: [PATCH 5/5] [BUGFIX] Do not create tax records for BE variants 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.) --- .../Order/Create/PersistOrder/Products.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Classes/EventListener/Order/Create/PersistOrder/Products.php b/Classes/EventListener/Order/Create/PersistOrder/Products.php index 4dd9cc9f..e831b347 100644 --- a/Classes/EventListener/Order/Create/PersistOrder/Products.php +++ b/Classes/EventListener/Order/Create/PersistOrder/Products.php @@ -16,7 +16,6 @@ use Extcode\Cart\Domain\Model\Cart\Product; use Extcode\Cart\Domain\Model\Order\Item; use Extcode\Cart\Domain\Model\Order\ProductAdditional; -use Extcode\Cart\Domain\Model\Order\Tax; use Extcode\Cart\Domain\Repository\Order\ProductAdditionalRepository; use Extcode\Cart\Domain\Repository\Order\ProductRepository; use Extcode\Cart\Domain\Repository\Order\TaxRepository; @@ -185,15 +184,6 @@ protected function addVariantsOfVariant(BeVariant $variant, int $level): void */ protected function addBeVariant(BeVariant $variant, int $level): void { - $orderTax = GeneralUtility::makeInstance( - Tax::class, - $variant->getTax(), - $this->taxClasses[$variant->getTaxClass()->getId()] - ); - $orderTax->setPid($this->storagePid); - - $this->taxRepository->add($orderTax); - $variantInner = $variant; for ($count = $level; $count > 0; $count--) { if ($count > 1) {