[Skip to main content](#vessel-content)

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

##

- **[earmaster](/forum/user/35023-earmaster "View earmaster's Profile")**
- [![earmaster's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/35023-earmaster "View earmaster's Profile") Topic Author
- [ Offline](/forum/user/35023-earmaster)

Less More

- Posts: 137
- Thank you received: 2
-
-

2 hours 19 minutes ago -  2 hours 17 minutes ago [\#100000664](#100000664) by [earmaster](/forum/user/35023-earmaster "View earmaster's Profile")  *[Fatal error in addDiscount() for related products with variant-only prices – ord](/forum/25-install-update/100000138-fatal-error-in-adddiscount-for-related-products-with-variant-only-prices---ord#100000664 "-- 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 &#42;&#42;blank order created email&#42;&#42;. It happens with the standard &#96;related&#95;products&#96; mail block whenever a related product gets its price from its variants and a discount applies to it, with &quot;Floating tax prices&quot; 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 &#42;&#42;every product priced through its variants&#42;&#42;, the &#96;'all'&#96; price display type puts a raw price string next to each price object in &#96;$product-&gt;prices&#96; (details below). Any code that loops over the prices and expects objects is affected. Here it crashes in &#96;addDiscount()&#96;.  ### Error  &gt; Attempt to assign property &quot;price&#95;value&#95;with&#95;tax&quot; on string &gt; in &#96;administrator/components/com&#95;hikashop/classes/currency.php&#96; on line 2512  &#96;&#96;&#96; #0 classes/currency.php(2438): hikashopCurrencyClass-&gt;addDiscount('26.50000', Object(stdClass), 0, 1120, 12) #1 classes/currency.php(2373): hikashopCurrencyClass-&gt;addDiscountToPrices(Object(stdClass), Array, 0, 1120) #2 classes/currency.php(1091): hikashopCurrencyClass-&gt;addDiscountToPrices(Array, Array, 0, 1120) #3 classes/currency.php(532): hikashopCurrencyClass-&gt;getProductsPrices(Array, Array) #4 classes/product.php(2769): hikashopCurrencyClass-&gt;getListingPrices(Array, 1120, 1, 'inherit') #5 media/com&#95;hikashop/mail/blocks/related&#95;products.html.php(46): hikashopProductClass-&gt;loadProductsListingData(Array, Array) #6 classes/mail.php(885): include(...) ... #12 classes/order.php(2448): hikashopMailClass-&gt;get('order&#95;creation&#95;notification', Object(stdClass)) &#96;&#96;&#96;  ### Steps to reproduce  1. Enable &quot;Floating tax prices&quot;. 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 &#96;order&#95;creation&#95;notification&#96; email is sent blank.  ### Cause (&#96;classes/currency.php&#96;, 6.8.2)  &#42;&#42;1.&#42;&#42; In &#96;getProductsPrices()&#96;, variant price search, case &#96;'all'&#96; (around line 931):  &#96;&#96;&#96;php foreach($matches as $j =&gt; $match){     if(isset($found&#91;$match-&gt;price&#95;value&#93;)) continue;     $found&#91;&#93;=$match-&gt;price&#95;value;        // line 934     ...     $found&#91;$match-&gt;price&#95;value&#93;=$match;  // line 940 } $rows&#91;$k&#93;-&gt;prices = array&#95;values($found); &#96;&#96;&#96;  Line 934 adds the price value as an extra array entry, so the price list becomes for example &#96;&#96;. The duplicate check on line 933 only needs the keyed entry from line 940.  The &#96;related&#95;products&#96; mail block passes &#96;'inherit'&#96; as the price display type. &#96;getProductsPrices()&#96; does not resolve &#96;'inherit'&#96;, so it falls through &#96;default:&#96; into this &#96;'all'&#96; case.  &#42;&#42;2.&#42;&#42; &#96;addDiscount()&#96; (line 2508) writes to &#96;$price&#96; in the floating tax block before its &#96;is&#95;object($price)&#96; check:  &#96;&#96;&#96;php if($config-&gt;get('floating&#95;tax&#95;prices', 0)) {     if(!isset($price-&gt;price&#95;value&#95;with&#95;tax))         $price-&gt;price&#95;value&#95;with&#95;tax = $price-&gt;price&#95;value;  // line 2512: fatal error on a string     ... } if(!is&#95;object($price))     return; &#96;&#96;&#96;  With floating tax prices off, the check skips the string silently. With it on, the email fails.  ### Suggested fix  - Remove line 934 (&#96;$found&#91;&#93;=$match-&gt;price&#95;value;&#96;) - Move the &#96;is&#95;object($price)&#96; check to the top of &#96;addDiscount()&#96;  Thanks!")* was created by *[earmaster](/forum/user/35023-earmaster "View earmaster's Profile")*

-- 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 &#96;related_products&#96; 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 &#96;'all'&#96; price display type puts a raw price string next to each price object in &#96;$product-&gt;prices&#96; (details below). Any code that loops over the prices and expects objects is affected. Here it crashes in &#96;addDiscount()&#96;.

\### Error

&gt; Attempt to assign property "price_value_with_tax" on string
&gt; in &#96;administrator/components/com_hikashop/classes/currency.php&#96; on line 2512

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

\### 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 &#96;order_creation_notification&#96; email is sent blank.

\### Cause (&#96;classes/currency.php&#96;, 6.8.2)

**1.** In &#96;getProductsPrices()&#96;, variant price search, case &#96;'all'&#96; (around line 931):

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

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

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

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

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

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

\### Suggested fix

- Remove line 934 (&#96;$found[]=$match-&gt;price_value;&#96;)
- Move the &#96;is_object($price)&#96; check to the top of &#96;addDiscount()&#96;

Thanks!

Last edit: 2 hours 17 minutes ago by [earmaster](/forum/user/35023-earmaster "View earmaster's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzEwMDAwMDEzOC1mYXRhbC1lcnJvci1pbi1hZGRkaXNjb3VudC1mb3ItcmVsYXRlZC1wcm9kdWN0cy13aXRoLXZhcmlhbnQtb25seS1wcmljZXMtLS1vcmQ/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.050 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
