Jump to content

[SOLVED] Injecting Add to Cart Externally


Recommended Posts

I have a custom service wizard that used to run under good old phpshop. I'm trying to do a rewrite so that it will work with prestashop. In a nutshell the wizard does a step by step. After step one I need it to inject a product into the cart along with a customization option. Then after step two it will inject anywhere from 1-20 smaller products that coincide with the first product. It then collects some information, stores it, and sends them on to checkout.

Questions simplified: What queries should I use to add a product the cart? How can I update the id_cart value in $cart and $cookie once I've assigned the cart an id number?

The latter is the one I'm having the most issues figuring out. Working with the cart tables seems easy enough but until I can get that id_cart stored it isn't going to show me the additions I made to the cart.

It would be nice if prestashop had some basic ssi libraries that can be used externally. Hey a guy can wish.

Link to comment
Share on other sites

Solution: The queries are easy enough to figure out and now that I have a way to establish the $cart->id before injecting the product I can see the queries work just fine. Low and behold it shows up in the blockcart on the next step screen. Here is the trick to establishing id_guest and id_cart. Slap in at the top of your own script and you're in business.

if (!$_SESSION[sinfo][id_guest] || !$_SESSION[sinfo][id_cart]) {
   ?>
   <iframe src="/yourprestapath/cart.php?token=<? echo Tools::getToken(); ?>&id_product=1&add=1&id;_product_attribute=&qty=1&Submit=Add+to+cart" height="1" width="1" frameborder="0">
   </iframe>
<?
}



Checks to see if it has been done already and whether the results are in my session. If either the guest id or cart id are blank it invisibly sends a shout out to the cart. Note on what product to shout out to... use one that requires a customization so that it doesn't actually add it to the cart on this first pass.

Happy trails... now back to finish up my new toy.

Link to comment
Share on other sites

  • 3 months later...
  • 9 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...