Skip to main content

Automatically filling cart information

More
10 years 11 months ago #217868 by Tsunoo
-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.4
-- PHP version -- : 5.5.29
-- Browser(s) name and version -- : Chrome 46

Hello,

I am trying to create automatically a cart.

I have a form in which visitors enter information, including name and address. They also choose in this form their status. When the form is submitted, I do the following:

- according to the status, I add a product to the cart; this is actually working well.
- I try to initialize the address with the information provided in the form; this is not working.

Here is the PHP code I am using after the form submission:
Code:
<?php if(!@include_once(rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikashop' . DS . 'helpers' . DS . 'helper.php')) { return false; } $Produit = $_GET["zkprod"]; $Reference = $_GET["zkref"]; $Nom = $_GET["zknom"]; $Prenom = $_GET["zkpre"]; $CP = $_GET["zkcp"]; $cartClass = hikashop_get('class.cart'); $cartClass->update($Produit, 1); $addrClass = $cartClass->loadAddress(); $addrClass->address_title = $Reference; $addrClass->address_first_name = $Prenom; $addrClass->address_last_name = $Nom; $addrClass->address_post_code = $CP; ?>

All the variables contain correct information at this point and the correct product is added to the cart. However, I cannot manage to initialize the address : when I proceed to checkout, the order is created with the correct product but the address information is empty.

I understood that only the Business edition of HikaShop can manage guest checkout. Is the problem occuring because I am currently using the starter edition? Will my PHP code run correctly when I purchase the Business edition?

I don't want to use the custom fields from HikaShop because the form I need is not only used for ordering online: I still want to use my form as it is.

And do you have more PHP code samples available? I only saw a few in the developer documentation...

Thank you very much for your answers.

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

More
10 years 11 months ago #217950 by nicolas
Hi,

You can't do it like that.
You need to first create a user with an email address in the hikashop_user table with a MySQL query.
Then, you need to store the user_id of the user in the session like that:
$app = JFactory::getApplication();
$app->setUserState('com_hikashop.user_id', $user_id);
Then, you need to create an address in the hikashop_address table with another MySQL query. You need to set the address_user_id of the address there.
Finally, you need to set the address_id of the address in the session like that:
$app = JFactory::getApplication();
$app->setUserState('com_hikashop.shipping_address', $address_id);
$app->setUserState('com_hikashop.billing_address', $address_id);

Once that's done, the cart system will automatically use them when other things in HikaShop try to load the cart.
The following user(s) said Thank You: Tsunoo

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

More
10 years 11 months ago #217957 by Tsunoo
Thank you very much!

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

Time to create page: 0.168 seconds
Powered by Kunena Forum