Display each cart item field as a separate line in the cart summary table

  • Posts: 8
  • Thank you received: 0
  • Hikashop Business
2 weeks 6 days ago #370811

Hi HikaShop team,

We are customizing the checkout cart template (show_block_cart.php) to display each product option and cart item field as a separate line in the cart summary table, with individual unit price, quantity, and total columns.

While implementing this, we found that cart item fields (stored in $cart->cart_products[$i]->field_namekey) lack some metadata that would be essential for correct display:

1. No tax rate available for item fields
The field value stored in the cart item is the price excluding tax (e.g. 42.975), but there is no associated tax rate or tax category accessible from the template. We had to hardcode × 1.21 (21% VAT) because it happened to match the configured tax for that service. If a field uses a different tax rate (10%, 4%, etc.), the displayed price with tax will be wrong.

Suggested improvement: Include the tax rate or computed price_value_with_tax alongside the raw field value in the cart item data, similar to how prices[0]->price_value_with_tax is available for product options.

2. No indication of whether a field price scales with quantity
Some item fields represent a per-unit cost (should multiply by cart quantity), while others represent a flat one-time service fee (should not multiply). Currently there is no way to distinguish these cases from the template — we have to guess based on business logic.

Suggested improvement: Add a metadata flag to field definitions (e.g. field_multiply_by_quantity: true/false) so templates can handle both cases correctly without hardcoding assumptions.

3. prices[0]->unit_price in option elements equals prices[0]->price_value_with_tax
When displaying grouped options (group_options = 1), the unit_price nested object inside prices[0] of an option element contains the same value as price_value_with_tax (i.e. total price, not unit price). This makes it impossible to retrieve the true per-unit price for display without manually dividing by cart_product_quantity.

Suggested improvement: Ensure prices[0]->unit_price->price_value_with_tax consistently reflects the price for one unit, regardless of cart quantity.

These improvements would allow template developers to build accurate per-line breakdowns without relying on hardcoded business logic or reverse-engineering prices from totals.

Thank you for considering these improvements.


Pablo Arias

www.pabloarias.eu

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

  • Posts: 85393
  • Thank you received: 13958
  • MODERATOR
2 weeks 6 days ago #370812

Hi,

I'm surprised by your message.
The custom item fields can't change the price of a product. So tax and quantity are irrelevant.
Could you explain where you're coming from with this ?
The only way this is possible is if you're using the price calculation plugin, but I don't see any purchase of it on your account, or some custom plugin on your end. If it's done by a custom plugin on your end, then the tax information and quantity should be an information provided by the plugin when modifying the price of the product via the events HikaShop provide, not something HikaShop itself does, since it doesn't know how the price is being modified by the plugin.

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

  • Posts: 5
  • Thank you received: 1
2 weeks 5 days ago #370849

Hi Nicolas,
Sorry, this is related to this thread: www.hikashop.com/support/forum/product-c...er-vehic.html#370015 . It's a project shared between Pablo and me, that's whay you cannot find that plugin under his account, but you can in mine.

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

  • Posts: 85393
  • Thank you received: 13958
  • MODERATOR
2 weeks 5 days ago #370856

Hi,

Thanks for the details. That provided valuable context.
We've worked on a new version of the plugin which will help you do what you want.
You can read more about it here:
www.hikashop.com/marketplace/product/148...ce-calculations.html

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

  • Posts: 5
  • Thank you received: 1
2 weeks 43 minutes ago #370947

Hi,

Thank you for the updated calculations plugin — we really appreciate the quick response.

After reviewing it, we can see that price_calculation->fields[] is now populated with name, raw_value, resolved_value, taxed, tax_id and value_used, which is a great step forward. However, in our case taxed still comes as false and tax_id as 0, because our item field does not have product_tax_id_for_custom_values set on the product. The tax ends up being applied elsewhere in the price pipeline, so the plugin has no visibility of it at that point.

The two remaining gaps that we still cannot solve generically are:

1. Tax information for item fields without product_tax_id_for_custom_values
When the field value gets taxed through the product's own tax group rather than through product_tax_id_for_custom_values, the taxed flag stays false and tax_id stays 0. As a result, we cannot determine the with-tax value of the field from price_calculation->fields[] alone and have to fall back to calling getTaxedPrice() with the parent product's tax ID, which may be incorrect if the item field carries a different tax rate.

2. Whether an item field scales with quantity or is a flat one-time charge
This is still not exposed anywhere. We are hardcoding quantity = 1 for all numeric item fields, which will be wrong as soon as we have a per-unit item field on a different product.

Would it be possible to address these two points in a future update? We are happy to provide a reproducible test case if that would help.

Thanks again for your support.

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

  • Posts: 85393
  • Thank you received: 13958
  • MODERATOR
1 week 6 days ago #370955

Hi,

That would be great if you can provide a reproducible test case, yes. That would allow us to validate the changes that need to happen, because I'm not clear in them.

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

  • Posts: 5
  • Thank you received: 1
1 week 6 days ago #370969

Hi,

I’m sharing some additional context to help clarify the situation.

This is the production website:
neumaticosacueducto.com/

And here is an example product:
neumaticosacueducto.com/neumaticos/turis...imacy-hp-mo-mercedes

In our case, the additional services (Ecotasa, Mounting, Inflation, and Rotation) are configured as products that are added together with the tire.
Among them, Ecotasa and Mounting are mandatory, while Inflation and Rotation are optional.

On the other hand, Alignment/Geometry is configured as a characteristic, using the price calculation plugin.

The issue appears when the user adds these additional services to the cart. At that point, the cart view does not display the prices clearly, as the different items are not properly separated, which creates confusion.

In fact, several users have already reported that this lack of clarity in the cart summary reduces their trust in the purchase process.

I hope this explanation helps clarify the situation. If you need any additional information or further examples, please let me know.

Thank you again for your support.

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

  • Posts: 85393
  • Thank you received: 13958
  • MODERATOR
1 week 5 days ago #370979

Hi,

Thank you for the detailed explanation, however I'm not sure I can see the issue. The price shown next to the product name includes all the add-ons from the price calculation plugin, which is confusing since those add-ons are also listed separately below.
This, I can agree.
We've fixed this in the next release of HikaShop (6.4.1). The base price next to the main product name will now show the original price before the price calculation formula was applied.

In the meantime, if you'd like to apply the fix right away, you can create a view override:

1. Go to HikaShop > Display > Views
2. Find `checkout / show_block_cart`
3. Click on it to create an override
4. Find this line (around line 259):

echo ' <span class="hikashop_product_base_price">' . strip_tags($this->getDisplayProductPrice($product, true)) . '</span>';

Replace it with:
echo ' <span class="hikashop_product_base_price">' . strip_tags($this->getDisplayProductPrice($product, true, true)) . '</span>';

Then, this requires a small change in the checkout view class. You can also edit the file `components/com_hikashop/views/checkout/view.html.php` and find the `getDisplayProductPrice` method (around line 442). Replace:
public function getDisplayProductPrice(&$product, $unit = false) {

with:
public function getDisplayProductPrice(&$product, $unit = false, $beforeCalculation = false) {

And add the following code right after the opening of the method (before `$previous_price_with_tax`):
$savedPrices = null;
if($beforeCalculation && !empty($product->price_calculation) && isset($product->price_calculation->price_before)) {
    $savedPrices = $product->prices;
    $product->prices = array();
    foreach($savedPrices as $k => $price) {
        $product->prices[$k] = clone $price;
        if(isset($price->unit_price))
            $product->prices[$k]->unit_price = clone $price->unit_price;
    }
    if(isset($product->prices[0]->unit_price)) {
        $product->prices[0]->unit_price->price_value = $product->price_calculation->price_before;
        if(isset($product->price_calculation->price_before_with_tax))
            $product->prices[0]->unit_price->price_value_with_tax = $product->price_calculation->price_before_with_tax;
    }
}

And at the end of the method, just before `return $ret;`, add:
if($savedPrices !== null)
    $product->prices = $savedPrices;

Is this "the cart view does not display the prices clearly, as the different items are not properly separated" you were talking about ? Or are you talking about something else ?
Because on my end, I can see the different elements of the product clearly separated: imgur.com/AttgHrl

If you're talking about something else, then maybe you could provide some screenshots to illustrate the problem ?

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

  • Posts: 5
  • Thank you received: 1
1 week 5 days ago #370998

Hi,

Thank you for the $beforeCalculation suggestion. We implemented the equivalent logic directly in our template override (without modifying view.html.php) by reading $product->price_calculation->price_before_with_tax directly. This works well for the unit price display.

However, we still have two assumptions in our override that we cannot resolve with the current data available in the cart object. We are attaching a screenshot of what we want to achieve and the relevant section of our override code.

Remaining problem 1: Tax rate for numeric item fields

When a numeric item field (e.g. alignment_service) is added to the cart, its value is stored as a raw price excluding tax. To display it with tax in the cart, we need to apply the correct tax rate. The price_calculation->fields[] objects have taxed: false and tax_id: 0 for this field, so we cannot read the tax rate from there. We are currently falling back to getTaxedPrice() using the parent product's product_tax_id, which happens to work for us because the alignment service uses the same tax rate as the tyre — but this will break if a future product has an item field with a different tax rate.

Is there a way to know the correct tax ID (or the taxed value) for each item field at cart display time?

Remaining problem 2: Whether an item field scales with quantity

Some item fields represent a flat one-time service (e.g. wheel alignment: one charge regardless of how many tyres are purchased), while others could represent a per-unit cost. There is no attribute on the field or on the cart product that tells us which behaviour applies. We are currently hardcoding quantity = 1 for all numeric item fields, which will be wrong for per-unit fields.

Is there a field attribute or cart product property that indicates whether a numeric item field should be multiplied by cart_product_quantity or treated as a flat fee?

Attachments:

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

  • Posts: 85393
  • Thank you received: 13958
  • MODERATOR
1 week 4 days ago #371005

Hello,

We have updated the Price Calculations plugin to version 2.4.1 with two new properties in the calculation metadata that should help you with your cart template override.

`$product->price_calculation->tags` is an associative array of all the tags that were replaced in the formula and their resolved values. For example, if your formula is `{price} + {ecotasa} + {montaje} * {cart_product_quantity}`, you would get:

[
    'price' => 213.63,
    'ecotasa' => 1.81,
    'montaje' => 23.95,
    'cart_product_quantity' => 2
]
This way, you can check if `cart_product_quantity` is present in the tags and use its value to determine which fields scale with quantity and which are flat fees.

`$product->price_calculation->tax_id` contains the tax category ID that was used for the calculation. You can use it with the currency class to compute taxed prices for individual field values in your template, for example:
$currencyClass = hikashop_get('class.currency');
$taxedValue = $currencyClass->getTaxedPrice($field->raw_value, hikashop_getZone(), $product->price_calculation->tax_id);

You can download the updated plugin from the marketplace page.

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

  • Posts: 5
  • Thank you received: 1
5 days 9 hours ago #371088

Hi,

Thank you very much for your reply, and apologies for the delay in getting back to you.

We are currently testing the new plugin update and working on configuring the cart view according to the client’s requirements. Once we have this completed, I will get back to you with an update.

Thank you very much for your support.

Best regards

The following user(s) said Thank You: nicolas

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

Time to create page: 0.081 seconds
Powered by Kunena Forum