1

Why this happaning product to cart but price getting 0 or NULL in magento API

2

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.

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

Your Result.

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.

<?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);

    ?>

See http://kanasagraj.blogspot.com/2015/09/add-product-to-cart-but-price-getting-0.html

2
0

This issue of getting 0 or null in add to cart API is fixed now after taking below steps (Note: This is for magento 2 or later version.)

Open file 'vendor/magento/module-quote/Model/QuoteManagement.php'. Find function 'createEmptyCartForCustomer'. Add below code inside try{}, around line number 235:

$quote->getBillingAddress();
$quote->getShippingAddress()->setCollectShippingRates(true);

After that it will work perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.