simple-commerce
simple-commerce copied to clipboard
Wrong tax rate stored in line item
Description
Line items might store a wrong tax rate, if the tax rate contains decimal places. This is due to a conversion in TaxCalculation:
public function toArray(): array
{
return [
'amount' => (int) $this->amount,
'rate' => (int) $this->rate,
'price_includes_tax' => $this->priceIncludesTax,
];
}
The tax itself is calculated correctly though.
Is it possible to change the cast to a float? I think for amount it is fine to use int, because the amount represents the amount of cents, which should not contain decimals.
Steps to reproduce
- Create a tax rate with decimals (like 8.1% for Switzerland)
- Add a product with this tax rate to a cart
- The order entry contains the wrong tax rate at
items.*.tax.rate
Environment
Environment Laravel Version: 11.22.0 PHP Version: 8.2.20 Composer Version: 2.7.7 Environment: local Debug Mode: ENABLED Maintenance Mode: OFF Timezone: UTC Locale: de
Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED
Drivers Broadcasting: log Cache: file Database: mysql Logs: stack / single Mail: smtp Queue: sync Session: file
Simple Commerce Currencies: CHF, CHF Gateways: TWINT, Kreditkarte, Rechnung Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\EntryCustomerRepository Repository: Order: DuncanMcClean\SimpleCommerce\Orders\EntryOrderRepository Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository Shipping Methods: Default shipping method Tax Engine: DuncanMcClean\SimpleCommerce\Tax\Standard\TaxEngine
Statamic Addons: 1 Sites: 2 (Deutsch, Französisch) Stache Watcher: Enabled Static Caching: Disabled Version: 5.23.0 PRO
Statamic Addons duncanmcclean/simple-commerce: 7.4.5
If you know the fix for this, feel free to submit a PR and I can review & merge it. I'm currently only looking into show-stopping bugs while I work on the next version.
Released as part of v7.5.5.