Skip to main content

Fatal error in addDiscount() for related products with variant-only prices – ord

2 weeks 6 days ago - 2 weeks 6 days ago #100000664 by earmaster
-- HikaShop version -- : 6.8.2
-- Joomla version -- : 5.4.9
-- PHP version -- : 8.5.12
-- Browser(s) name and version -- :  Chrome 157.0

### Impact

Customers receive a **blank order created email**. It happens with the standard `related_products` mail block whenever a related product gets its price from its variants and a discount applies to it, with "Floating tax prices" enabled. Each of these is a normal setup: variant pricing, catalogue discounts, and floating tax prices for VAT-inclusive prices in the EU.

The root cause is not limited to emails. For **every product priced through its variants**, the `'all'` price display type puts a raw price string next to each price object in `$product->prices` (details below). Any code that loops over the prices and expects objects is affected. Here it crashes in `addDiscount()`.

### Error

> Attempt to assign property "price_value_with_tax" on string
> in `administrator/components/com_hikashop/classes/currency.php` on line 2512

```
#0 classes/currency.php(2438): hikashopCurrencyClass->addDiscount('26.50000', Object(stdClass), 0, 1120, 12)
#1 classes/currency.php(2373): hikashopCurrencyClass->addDiscountToPrices(Object(stdClass), Array, 0, 1120)
#2 classes/currency.php(1091): hikashopCurrencyClass->addDiscountToPrices(Array, Array, 0, 1120)
#3 classes/currency.php(532): hikashopCurrencyClass->getProductsPrices(Array, Array)
#4 classes/product.php(2769): hikashopCurrencyClass->getListingPrices(Array, 1120, 1, 'inherit')
#5 media/com_hikashop/mail/blocks/related_products.html.php(46): hikashopProductClass->loadProductsListingData(Array, Array)
#6 classes/mail.php(885): include(...)
...
#12 classes/order.php(2448): hikashopMailClass->get('order_creation_notification', Object(stdClass))
```

### Steps to reproduce

1. Enable "Floating tax prices".
2. Create product B with variants. Put the prices on the variants only, not on the main product.
3. Publish a discount that applies to product B (or to all products).
4. Add product B as a related product of product A.
5. Order product A. The `order_creation_notification` email is sent blank.

### Cause (`classes/currency.php`, 6.8.2)

**1.** In `getProductsPrices()`, variant price search, case `'all'` (around line 931):

```php
foreach($matches as $j => $match){
    if(isset($found[$match->price_value])) continue;
    $found[]=$match->price_value;        // line 934
    ...
    $found[$match->price_value]=$match;  // line 940
}
$rows[$k]->prices = array_values($found);
```

Line 934 adds the price value as an extra array entry, so the price list becomes for example ``. The duplicate check on line 933 only needs the keyed entry from line 940.

The `related_products` mail block passes `'inherit'` as the price display type. `getProductsPrices()` does not resolve `'inherit'`, so it falls through `default:` into this `'all'` case.

**2.** `addDiscount()` (line 2508) writes to `$price` in the floating tax block before its `is_object($price)` check:

```php
if($config->get('floating_tax_prices', 0)) {
    if(!isset($price->price_value_with_tax))
        $price->price_value_with_tax = $price->price_value;  // line 2512: fatal error on a string
    ...
}
if(!is_object($price))
    return;
```

With floating tax prices off, the check skips the string silently. With it on, the email fails.

### Suggested fix

- Remove line 934 (`$found[]=$match->price_value;`)
- Move the `is_object($price)` check to the top of `addDiscount()`

Thanks!
Last edit: 2 weeks 6 days ago by earmaster.

Please Log in or Create an account to join the conversation.

2 weeks 6 days ago #100000669 by nicolas
Hi,

Thank you for the detailed analysis, it is correct. For products priced through their variants, the price list got the raw price value added next to each price, and addDiscount() then wrote to that string before checking it with floating tax prices on. We applied both changes you suggested: the extra line is removed and the is_object check is now at the top of addDiscount().

This is fixed in the latest build of HikaShop 6.8.2. Download it from your account on our website and install it over your current HikaShop (same version number, so the Joomla updater will not offer it; your settings are kept). The order created email then shows the related products with their variant prices again, and is no longer sent blank.

Please Log in or Create an account to join the conversation.

Time to create page: 0.043 seconds
Powered by Kunena Forum