Skip to main content

How can I get the checkout cart subtotal price?

More
1 year 5 months ago #366495 by m.mihov
Hello,
I'm working on a module.
How can I get the checkout cart subtotal price?

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

More
1 year 5 months ago #366497 by nicolas
Hi,

First, you want to load HikaShop, in case it's not already loaded on the page by the time Joomla runs your module:
Code:
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }
Then, you want to load the cart:
Code:
$cartClass = hikashop_get('class.cart'); $cart = $cartClass->getFullCart();
You could loop through the products in $cart->products to sum the products price. But a simpler solution would be to directly get the subtotal :
Code:
echo $cart->total->prices[0]->price_value_with_tax; // with taxes echo $cart->total->prices[0]->price_value; // without taxes
And if you want to format it as a price (with the currency, decimals rounding, etc), you'll want to display it like that for example:
Code:
$currencyClass = hikashop_get('class.currency'); echo $currencyClass->format($cart->total->prices[0]->price_value_with_tax, $cart->total->prices[0]->price_currency_id);

www.hikashop.com/support/documentation/6...umentation.html#code

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

More
1 year 5 months ago #366500 by m.mihov
Thanks a lot.
Can I call from the configuration how the price should be with or without tax?
Something like:
Code:
if(!empty($this->options['price_with_tax']))

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

More
1 year 5 months ago #366502 by nicolas
Hi,

If you want to base yourself on the "Show taxed prices" of the HikaShop configuration, you can get its value like this:
Code:
$config = hikashop_config(); $price_with_tax = $config->get('price_with_tax');

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

More
1 year 5 months ago #366511 by m.mihov
Thanks.
It worked.

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

Time to create page: 0.256 seconds
Powered by Kunena Forum