- Posts: 217
- Thank you received: 4
Get total value of cart from independed php file
- FilipHradil
-
Topic Author
- Offline
Less
More
6 years 11 months ago - 6 years 11 months ago #311909
by FilipHradil
Get total value of cart from independed php file was created by FilipHradil
-- 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:
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
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:
Code:
$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: 6 years 11 months ago by FilipHradil.
Please Log in or Create an account to join the conversation.
6 years 11 months ago #311922
by nicolas
Replied by nicolas on topic Get total value of cart from independed php file
Hi,
1.
You had a good start:
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.
1.
You had a good start:
Code:
$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.
- FilipHradil
-
Topic Author
- Offline
Less
More
- Posts: 217
- Thank you received: 4
6 years 11 months ago #312044
by FilipHradil
Replied by FilipHradil on topic Get total value of cart from independed php file
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
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.
6 years 11 months ago #312046
by nicolas
Replied by nicolas on topic Get total value of cart from independed php file
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
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.
- FilipHradil
-
Topic Author
- Offline
Less
More
- Posts: 217
- Thank you received: 4
6 years 11 months ago #312071
by FilipHradil
Replied by FilipHradil on topic Get total value of cart from independed php file
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
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.
6 years 11 months ago #312073
by nicolas
Replied by nicolas on topic Get total value of cart from independed php file
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
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.164 seconds