Friday 18 September 2015

Add product to cart but price getting 0 or NULL in magento API

I’m testing out the Cart API and it seems I cannot get any data related to price, total price, etc until I enter in customer information.  The variables are there, but all of the price values are null/0. Is this the intended functionality, or am I doing something wrong?

The code below works except any variable relating to the price is null.

<pre>
<?php
$client = new SoapClient('http://magento.com/api/soap/?wsdl');
$session = $client->login('jemsw','write');
$cartId = $client->call($session,'cart.create',array(0));
$result = $proxy->call($sessionId, 'cart_product.add', array($cartId, array("product_id" => 53,"qty" => 2)));
$result = $client->call($session,'cart.totals',array($cartId));
print_r($result);
?></pre>

Array(
    [0] => Array(
        [title] => Subtotal
        [amount] =>
        )
        [1] => Array(
        [title] => Grand Total
        [amount] =>
        )
    )

If I add this code in after add product to cart `cart_product.add` the price is reflected correctly.

<pre>
<?php

    $client = new SoapClient('http://magento.com/api/soap/?wsdl');$session = $client->login('jemsw','write');

    $cartId = $client->call($session,'cart.create',array(0));

    $result = $proxy->call($sessionId, 'cart_product.add', array($cartId, array("product_id" => 53,"qty" => 2)));


    ################################################################################


    $arrAddresses = array(

        array(

            "mode" => "shipping",

            "firstname" => "test",

            "lastname" => "test",

            "company" => "test",

            "street" => "test",

            "city" => "test",

            "region" => "test",

            "postcode" => "test",

            "country_id" => "id",

            "telephone" => "0123789",

            "fax" => "01234589",

            "is_default_shipping" => 0,

            "is_default_billing" => 0

        ),

        array(

            "mode" => "billing",

            "firstname" => "test",

            "lastname" => "test",

            "company" => "test",

            "street" => "test",

            "city" => "test",

            "region" => "test",

            "postcode" => "test",

            "country_id" => "id",

            "telephone" => "012356789",

            "fax" => "0123459",

            "is_default_shipping" => 0,

            "is_default_billing" => 0

        )

    );

    $resultCustomerAddresses = $client->call($session, "cart_customer.addresses", array($cartId, $arrAddresses));


    ################################################################################

    $result = $proxy->call($sessionId, "cart.info", array($cartId));

    print_r($result);

    ?>

    </pre>

Display Your Cart item with price. 

No comments:

Post a Comment