[Skip to main content](#vessel-content)

#   Automatically filling cart information

##

- **[Tsunoo](/forum/user/38515-tsunoo "View Tsunoo's Profile")**
- [![Tsunoo's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38515.png)](/forum/user/38515-tsunoo "View Tsunoo's Profile") Topic Author
- [ Offline](/forum/user/38515-tsunoo)

Less More

- Posts: 10
- Thank you received: 0
-
-
-
-

11 years 3 weeks ago [\#217868](#217868) by [Tsunoo](/forum/user/38515-tsunoo "View Tsunoo's Profile")  *[Automatically filling cart information](/forum/27-checkout/879962-automatically-filling-cart-information#217868 "-- 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:  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.")* was created by *[Tsunoo](/forum/user/38515-tsunoo "View Tsunoo's Profile")*

-- 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:

&lt;?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-&gt;update($Produit, 1); $addrClass = $cartClass-&gt;loadAddress(); $addrClass-&gt;address_title = $Reference; $addrClass-&gt;address_first_name = $Prenom; $addrClass-&gt;address_last_name = $Nom; $addrClass-&gt;address_post_code = $CP; ?&gt;

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3OTk2Mi1hdXRvbWF0aWNhbGx5LWZpbGxpbmctY2FydC1pbmZvcm1hdGlvbj90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86561
- Thank you received: 14307
-
-

11 years 3 weeks ago [\#217950](#217950) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Automatically filling cart information](/forum/27-checkout/879962-automatically-filling-cart-information#217950 "-- 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:  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.")*

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-&gt;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-&gt;setUserState('com_hikashop.shipping_address', $address_id);
$app-&gt;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](/forum/user/38515-tsunoo "View Tsunoo's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3OTk2Mi1hdXRvbWF0aWNhbGx5LWZpbGxpbmctY2FydC1pbmZvcm1hdGlvbj90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Tsunoo](/forum/user/38515-tsunoo "View Tsunoo's Profile")**
- [![Tsunoo's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38515.png)](/forum/user/38515-tsunoo "View Tsunoo's Profile") Topic Author
- [ Offline](/forum/user/38515-tsunoo)

Less More

- Posts: 10
- Thank you received: 0
-
-
-
-

11 years 3 weeks ago [\#217957](#217957) by [Tsunoo](/forum/user/38515-tsunoo "View Tsunoo's Profile")  Replied by *[Tsunoo](/forum/user/38515-tsunoo "View Tsunoo's Profile")* on topic *[Automatically filling cart information](/forum/27-checkout/879962-automatically-filling-cart-information#217957 "-- 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:  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.")*

Thank you very much!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3OTk2Mi1hdXRvbWF0aWNhbGx5LWZpbGxpbmctY2FydC1pbmZvcm1hdGlvbj90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.046 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
