Get total value of cart from independed php file

  • Posts: 217
  • Thank you received: 4
5 years 1 month ago #311909

-- HikaShop version -- : 4.2.2

Hello,

I am trying to obtain total value of cart (with tax) in separated php file. Please, what is the simples method to get this value?
I am trying this, without success:

$hikashopHelper = 'https://elodyprsteny.cz/backup/administrator/components/com_hikashop/helpers/helper.php';

if(!file_exists($hikashopHelper) || !include_once($hikashopHelper))
	return;

$cartClass = hikashop_get('class.cart');
$cart = $cartClass->get(0);
echo $cart->full_total;

In another words, if user has in cart 3 products, each for 30 $, I need value with 90 $.

Please, could you give me an advise? I am completely lost when it comes to hikashop classes, structures, etc.. :-)

I need this to create custom js code that will load via ajax value for micro cart as to as I can use page cache.

Q2: This php function will be called via ajax from custom html module in Joomla. How can I assign value to correct user that called that ajax? Will it be done automatically or I need to pass some parameter?

Thank you very much,
Filip

Last edit: 5 years 1 month ago by FilipHradil.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 1 month ago #311922

Hi,

1.
You had a good start:

$hikashopHelper = 'https://elodyprsteny.cz/backup/administrator/components/com_hikashop/helpers/helper.php';

if(!file_exists($hikashopHelper) || !include_once($hikashopHelper))
	return;

$cartClass = hikashop_get('class.cart');
$cart = $cartClass->getFullCart();
echo $cart->full_total->prices[0]->price_value_with_tax;

2. Even in Ajax, the user session cookies are passed by the browser, so your PHP script will know which user account is asking for the information and thus it will automatically pick the correct cart with the correct prices.

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

  • Posts: 217
  • Thank you received: 4
5 years 1 month ago #312044

Hello,

Thank you! Sorry for late reply. Unfortunately, it says "Restricted access" when I paste your code into separated php file.

What I missed, please?

Thanks!
Filip

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 1 month ago #312046

Hi,

HikaShop requires Joomla to be loaded. Otherwise, you'll get such error.
Did you also load Joomla before loading the HikaShop helper ?
stackoverflow.com/questions/23937651/loa...al-php-file/23937818

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

  • Posts: 217
  • Thank you received: 4
5 years 1 month ago #312071

Hello,

I just did that.

But still getting empty cart when I call ajax from joomla module and php code is in separated .php file in root folder of website.

Any suggestions, please?
Filip

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 1 month ago #312073

Hi,

This means that the user session is not kept and thus HikaShop doesn't have the cart_id reference in the user session.
So maybe you need to do something in your code to load the user session yourself.
docs.joomla.org/How_to_access_session_va...n_external_script/en

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

Time to create page: 0.070 seconds
Powered by Kunena Forum