Jump to content

[solved]Whats the best way to add a product to cart programmaticly


13thjoker

Recommended Posts

Update:

Works now :D

$context = Context::getContext();
$cart = $context->cart;
$cart->updateQty(1, 7);

Is this the correct way to do this or is there a more efficient way? Or a better way.

Edited by 13thjoker
I updated since the previous message wasnt of use anymore so i created less mess by updating instead of making a 2nd comment (see edit history)
Link to comment
Share on other sites

<?php

$context=Context::getContext();//new Cart();
$id_cart=$context->cookie->__get('id_cart');

$products_ids=$_GET['products_ids']; // comma seprated products id example : test.php?products_ids=1,2,3

$products_ids_array=explode(",",$products_ids);

if(count($products_ids_array)>0){
    $cart=new Cart($id_cart);
    $cart->id_currency=2;
    $cart->id_lang=1;
    foreach($products_ids_array as $key=>$id_product){
        $cart->updateQty(1, $id_product);
    }
}
?>
Edited by catalin.pop (see edit history)
Link to comment
Share on other sites

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