0

I have used Magento Soap API v2 to create Mobile APP API. For order place I have created a function in which I used API shoppingCartOrder(), this API works perfect when no discount amount added to cart items.

But when I added discount amount on cart Items then discount amount not added to cart totals.

My Custom function code for place order is below :

...
// cart info after apply discount amount
$cartTotal = $soapClient->shoppingCartTotals($sessionId, $cartId);
{ $cartTotal not showing discount amount }

// place the order
$orderId = $soapClient->shoppingCartOrder($sessionId, $cartId, '1', '1');
...

How to add discount amount in cart total in soap API?

0

I think you were missing store ID in the shoppingCartCouponAdd API call. Here is the complete script to place order using Magento SOAP API V2 with Discount Code :

$storeId = '1';

$quoteId = $client->shoppingCartCreate($session,$storeId);

echo "<br>Quote ID : " . $quoteId;

/* Set cart customer */
$guest = true;

if ($guest) 
{
    $customerData = array(
        "firstname" => "testFirstname",
        "lastname" => "testLastName",
        "email" => "testEmail@mail.com",
        "mode" => "guest",
        "website_id" => "1"
    );
} 
else 
{
    $customer  = array(
        "customer_id" => '69301',
        "website_id" => "1",
        "group_id" => "1",
        "store_id" => "1",
        "mode" => "customer",
    );
}

//Set cart customer (assign customer to quote)
$resultCustomerSet = $client->shoppingCartCustomerSet($session, $quoteId, $customerData,$storeId);

echo "<br>Set Customer: ";
var_dump($resultCustomerSet);   //Set customer

/* Set customer addresses Shipping and Billing */

$addresses = array(
    array(
        "mode" => "shipping",
        "firstname" => "Ahsan",
        "lastname" => "testLastname",
        "company" => "testCompany",
        "street" => "testStreet",
        "city" => "Karachi",
        "region" => "Sindh",
        "postcode" => "7502",
        "country_id" => "PK",
        "telephone" => "0123456789",
        "fax" => "0123456789",
        "is_default_shipping" => 0,
        "is_default_billing" => 0
    ),
    array(
        "mode" => "billing",
        "firstname" => "Ahsan",
        "lastname" => "testLastname",
        "company" => "testCompany",
        "street" => "testStreet",
        "city" => "Karachi",
        "region" => "Sindh",
        "postcode" => "7502",
        "country_id" => "PK",
        "telephone" => "0123456789",
        "fax" => "0123456789",
        "is_default_shipping" => 0,
        "is_default_billing" => 0
    )
);

//Set cart customer address
$resultCustomerAddress = $client->shoppingCartCustomerAddresses($session, $quoteId, $addresses,$storeId);   

echo "<br>Set Customer Address: ";
var_dump($resultCustomerAddress);   //Set customer addresses

/* Add products to cart */
$product = array(
                            'product_id' => '905',
                            // 'sku' => 'simple_product',
                            'qty' => '1',
                            'options' => null,
                            'bundle_option' => null,
                            'bundle_option_qty' => null,
                            'links' => null);
$product2 = array(
                            'product_id' => '904',
                            // 'sku' => 'simple_product',
                            'qty' => '2',
                            'options' => null,
                            'bundle_option' => null,
                            'bundle_option_qty' => null,
                            'links' => null);

$addToCart = $client->shoppingCartProductAdd($session, $quoteId, array($product,$product2),$storeId);

echo "<br>Add to Cart: ";
var_dump($addToCart);

/* Set payment method */
$responsePayment = $client->shoppingCartPaymentMethod($session, $quoteId, array(
    'method' => 'cashondelivery',
),$storeId);  

echo "<br>Set Payment method: ";
var_dump($responsePayment);

/* Set shipping method */
$setShipping = $client->shoppingCartShippingMethod($session, $quoteId, 'flatrate_flatrate',$storeId);

echo "<br>Set Shipping method: ";
var_dump($setShipping);

/* Set Discount Code */

try
{
    $result = $client->shoppingCartCouponAdd($session, $quoteId, 'test123',$storeId);
    echo "<br>Apply discount code: ";
    var_dump($result);
}
catch(Exception $ex)
{
    echo "<br>Discount code Failed: " . $ex->getMessage();
    die();
}


$orderId = $client->shoppingCartOrder($session, $quoteId, $storeId, null);
echo "<br>Placed Order: ";
var_dump($orderId);

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.