magentomagento-1.7magento-soap-api

Can one generate a link to the checkout page for a cart in magento?


I've got an instance of magento 1.7 CE running, and a second site that calls it via the SOAP api v2 from php.

I can't seem to find out how to add an array of products (given by productId or SKU) to a cart and then redirect to the cart page.

I've tried adding the items to the cart via shoppingCartProductAdd, which works, however I can't find out how to then open that cart back on magento.

I've also tried directly formulating a link that passes products via GET, however this only works for a single product ( checkout/cart/add?product=[id]&qty=[qty] ), for my purpose a whole array of products needs to be passed before redirecting to magento.

Any ideas?


Solution

  • Figured it out. Basically one can use a link shaped like

    http://example.com/checkout/cart/add?product=1&related_product=2,3,4,5

    To fill the shoppingcart with products with id 1 .. 5 and then go to the cart in magento.

    In my case I generated the link like this

    if(!isset($session)) {
        $client = new SoapClient('http://example.com/index.php/api/v2_soap?wsdl=1');
        $session = $client->login('username', 'Qq314asdgUScrncfD7VMb');
    }
    if(!isset($cart)) {
        $cart = $client->shoppingCartCreate($session);
    }
    $ids = array();
    
    foreach($items as $id) {
        $result = $client->catalogProductInfo($session, $id." ", null, 'sku');
        $ids[] = $result->product_id;
    }
    
    $this->Session->delete('Cart');
    
    $this->redirect('http://example.com/checkout/cart/add?product='.$ids[0].'&related_product=' . implode(array_slice($ids, 1), ','));