show price without discount

  • Posts: 26
  • Thank you received: 1
5 years 4 months ago #308223

-- HikaShop version -- : 4.1
-- Joomla version -- : 3.9

Hello,
I am trying to display the price without discount in the checkout, for this I he¡avre edited
checkout / show_block_cart.php view and added a new line like this:

<td class="hikashop_cart_subtotal_value" data-title="<?php echo JText::_('SUBTOTAL'); ?>">
<span class="hikashop_checkout_cart_subtotal"><?php
echo $this->currencyClass->format(@$cart->total->prices[0]->price_value_without_discount,@$cart->total->prices[0]->price_currency_id);
?></span>
</td>

The problem is that always get 0€ in this field

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

  • Posts: 82864
  • Thank you received: 13372
  • MODERATOR
5 years 4 months ago #308225

Hi,

The price_value_without_discount on the total of the cart is the price without coupon applied. And if you don't have any coupon applied it is not set.
The total of the cart without discounts is not calculated anywhere, so you would have to calculate it in your custom code I'm afraid by looping on the $cart->products array.

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

  • Posts: 26
  • Thank you received: 1
5 years 4 months ago #308246

Thanks Nicolas I will try...

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

  • Posts: 26
  • Thank you received: 1
5 years 4 months ago #308279

Finally I think I get it:

$price_without_discount = 0;
foreach($cart->products as $i => $product) {

if(empty($product->cart_product_quantity))
continue;
if($group && !empty($product->cart_product_option_parent_id))
continue;

$price_without_discount += $product->prices[0]->price_value_without_discount;
}

Last edit: 5 years 4 months ago by fernandoIncerco.
The following user(s) said Thank You: nicolas

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

  • Posts: 26
  • Thank you received: 1
5 years 2 months ago #310583

Hi to all,
I want to do the same (display the price without discount) in the show_default.php , but here the cart objet is still empty...

How can I show it in this view?

Thanks

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

  • Posts: 82864
  • Thank you received: 13372
  • MODERATOR
5 years 2 months ago #310585

Hi,

The price without discount is already available in a variable on the product page.
You can just display it:

echo $this->element->prices[[0]->price_value_without_discount;

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

  • Posts: 26
  • Thank you received: 1
5 years 2 months ago #310618

Hi Nicolas,
With this I see the price of the product without options, to add the option price I tried:

$price_without_dto= $this->element->prices[0]->price_value_without_discount;
foreach($this->element->options as $optionElement){
			$price_without_dto+= $optionElement->order_product_price;
}

but is not working :(

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

  • Posts: 82864
  • Thank you received: 13372
  • MODERATOR
5 years 2 months ago #310620

Hi,

The price with options is calculated dynamically with javascript at the bottom of the "option.php" file of the "product" view.
Also, your code is not correct.
Supposing that your option doesn't have variants, then you can use such code instead:

$price_without_dto= $this->element->prices[0]->price_value_without_discount;
foreach($this->element->options as $optionElement){
			$price_without_dto+= $optionElement->prices[0]->price_value;
}
If it has, then it should be something like that (however, this will add the price of all the variants of the option to the main product price so you'll likely want to adapt it based on what you want):
$price_without_dto= $this->element->prices[0]->price_value_without_discount:
foreach($this->element->options as $optionElement){
	foreach($optionElement->variants as $variant) {
		$price_without_dto+= $variant->prices[0]->price_value;
	}
}

The following user(s) said Thank You: fernandoIncerco

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

  • Posts: 26
  • Thank you received: 1
5 years 2 months ago #310670

Ok I forgot that the calculation was in the option.php.
Done and working!!! Thanks so much

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

Time to create page: 0.069 seconds
Powered by Kunena Forum