Adding Product To Cart Remotely

[quote name='tbirnseth' timestamp='1396677289' post='181028']

It's going to checkout.checkout and then it's finding the cart is empty. Do your require https for your checkout? If you add under http and the go to checkout under https, then the cart may not have any contents. I would have to add some diagnostics to figure out what's happening at your site and I'm sorry, but I don't have time to investigate site specific issues right now.

[/quote]

Thanks for the reply, I turned off the Https in checkout and tested but it still did not work, This is not essential to me but it would be a great addition, I will revisit it when I have a few €s to get you to fix it.



Alan

Thanks for the code.



Got this working for a client.



A few changes:


if ( !defined('AREA') ) die('Access denied');



should be:


if ( !defined('BOOTSTRAP') ) die('Access denied');


app/addons/my_changes/frontend/checkout.pre.php



should be


app/addons/my_changes/controllers/frontend/checkout.pre.php

yep

Hi,



This works great also in 4.1.3



But is it possible to add “virtual” product to the basket?



We have an external shop from our manufacturar, we would like that if someone ad an product to this cart, that is product will be added to cs-cart shoppingcart (while this product not excist in cs-cart)

It must the also import the price from the external site

Hi Elektroshop,

I think it's possible if you put before the product into cscart and after this adding by put it to cart directly.

To put the I suggest you to do it in jquery with the curl connexion and after in the remote store and the end of of the add

to redirect the customer to the remote checkout…

But carefully don't do this “add product” ouside from curl connexion because you'll break your security base.

Hope this answer could help you could use CSCART_api script and find in this forum.

Regards

Mmovies

You would have to pass a lot more information to have it create products on the fly. This little interface was not designed with that intent.

I tried this script on CS Cart 4.1.4; adding multiple products (e.g. Cart contents - Bookcafe.com.my | Kedai Buku Online@1) but its not working.



Only the first product code in the URL string is added to cart, and item quantity is the sum of both product.

I've updated the script located at http://www.ez-ms.com/private/unsupported_scripts/checkout.pre.php.txt



It should work in V4 as it is and with a couple of adjustments near the top, V3 also. However I did simply edit in a text editor to update it to the current version but it has NOT been tested. However, it is running well at the client site where it was originally developed for.



Your mileage may vary.

Thanks tbirnseth, everything is perfect; though please advise the correct syntax for this line:



if( empty($product_id) ) // Try option inventory
$product_id = db_get_field("SELECT product_id FROM ?:product_options_inventory WHERE product_code=%s", $product_code);




Should it be "WHERE product_code=?s" ?



If i use the original code, any products with invalid product id will produce a “store is closed” message. So I change it to product_code=?s

Yes, you are correct. It should be '?s' versus '%s'.

I will update my source and thee source pointed to by the link.



Good catch.

Hi tbirnseth and thank you for posting this very great solution. However as one of the users also pointed out, i'm getting an empty cart when i try to checkout. What i found out is that it only works if there is already an existing product in the cart. The question now is that is there a workaround for this? i did a mupltiple product by the way.



Thanks,

Mark

There have been several publications of this free code snippet. Not knowing what you have it is hard for me to guess.

There should be no restriction on whether the cart is empty or not. I use this extensively on some of my client sites for quickly adding products to checkout from a blog and then taking the customer there to complete the process.

Hi tbirnseth,



This is what i have: http://www.ez-ms.com/private/unsupported_scripts/checkout.pre.php.txt i think this is also what you provided from the previous post. I already disabled https for testing purposes and i'm still getting the same result.



Usage:



I used your script to provide a “one time offer” feature in our store.

I'd need a bit more info… I.e. single or multiple products? I've not been able to reproduce any requirement for already having items in the cart.

You might try changing:


if (empty($_SESSION['cart'])) {
fn_clear_cart($_SESSION['cart']);
}


to


if (empty($_SESSION['cart'])) {
$_SESSION['cart'] = array();
fn_clear_cart($_SESSION['cart']);
}




If that resolves the problem, please let me know and I'll update the public source.

Hi tbirnseth,



Its for a multiple product checkout. I used this link internally.

Your link name

unfortunately adding this inside the condition

$_SESSION['cart'] = array();



didn't resolve the issue. If i understand correctly, you are setting an empty array into the cart session. i cleared cache, template cache and still getting empty cart.



Thanks,

Mark

I'll try to reproduce. However would suggest you not use the 'cc' parameter (conflicts with the clear cache parameter) and instead use 'c_code'.



Basically if the $_SESSION['cart'] is empty (i.e not set or equals array(), false, zero or other non-cart value) then set it to 'array()' and call the function to clear the cart which will do some initialization (I.e. if the user is logged in, uses their profile info, etc.). If it's already set, then it just points to it and uses is.



It then goes on to process the products.



You are not getting any kind of notification (either an error or notification of success)?



What happens if you use 'remote_add' instead of 'remote_checkout'? Do you see the items in the cart then?

Unfortunately, I'm not able to reproduce this using the following URL (a cs-cart demo store products). Have you tried without the coupon code?



XX.com?dispatch=checkout.remote_checkout.U0012O5AF0@3|G0017HS88V@2|H0148VPS1T



It shows the proper number of products in the cart with the specified quantities. I didn't have any valid coupons setup so I didn't test with that. But even if using the clear_cache parameter (cc), it shouldn't affect the user's session data.

The only notification i get is “Your cart is empty, so you cannot proceed to checkout”. i tried switching to remote_add, unfortunately im still getting the same result. i also set the coupon code to blank and used c_code as well but still the same.



You can reproduce the error by putting the link tag in the checkout.complete page. I'm using this internally that's why it's in that page.



The structure of my link tag is like this:



Checkout Now




Thanks,

Mark

Update:



It works now! :) the issue is on my end, the structure of my files. i missed putting the frontend folder inside the controllers folder in my changes folder. i deeply apologize for that. im so sorry for taking much of your time. but i really do appreciate you for taking the time on answering my questions. tbirnseth=life saver.



Thanks,

Mark