Shopping Cart API

Last modified by sgunfio on Fri, August 19, 2011 03:26
Source|Old Revisions  

This is an old revision of the document!


Allows to create/modify shopping cart and create an order after complete filling shopping cart. Consists of two main parts: Shopping Cart and Checkout processes.

Module: Mage_Checkout

Resource: cart

Methods

cart.create

Create a blank shopping cart

Return: int - Shopping Card Id (Quote Id)

Arguments:

  • mixed (int | string) storeView - Store view Id or code (optional)

cart.order

Create an order from shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • mixed (int | string) storeView - Store view Id or code (optional)
  • array (String) agreements - Website’s license identifiers (optional)

cart.info

Get full information about current shopping cart

Return: array (ShoppingCartEntity) - return an associate array contained information about Shopping Cart (quote)

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • mixed (int | string) storeView - Store view Id or code (optional)

cart.totals

Get all available prices based on additional parameters set

Return: array (ShoppingCartPriceEntity) - return an associate array contained information about all prices in Shopping Cart (quote)

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • mixed (int | string) storeView - Store view Id or code (optional)

cart.licenseAgreement

Get website license agreement

Return: array of shoppingCartLicenseEntity - list with website license

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • mixed (int | string) storeView - Store view Id or code (optional)

Faults

Fault Code Fault Message
1001 Can not make operation because store is not exists
1002 Can not make operation because quote is not exists
1003 Can not create a quote.
1004 Can not create a quote because quote with such identifier is already exists
1005 You did not set all required agreements
1006 The checkout type is not valid. Select single checkout type.
1007 Checkout is not available for guest
1008 Can not create an order.

Resource: cart_product

Methods

cart_product.add

Add product or several products into shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • array of CartProductEntity - an array with list of CartProductEntity

e.g.

array( array (’product_id’ ⇒ 1, ‘qty’ ⇒ 2), array( “sku” ⇒ “testSKU”, “quantity” ⇒ 4), array (’product_id’ ⇒ 1, ‘qty’ ⇒ 2,

 'options' => array("2" => 'A000000')
),

)

note options is an array in the form of

option_id ⇒ content

at moment there is no way to obtain option_id from Webservice Api

  • mixed (int | string) storeView - Store view Id or code (optional)

cart_product.update

Update product or several products into shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • array of CartProductEntity - an array with list of CartProductEntity
  • mixed (int | string) storeView - Store view Id or code (optional)

cart_product.remove

Remove product or several products from shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • array of CartProductEntity - an array with list of CartProductEntity
  • mixed (int | string) storeView - Store view Id or code (optional)

cart_product.list

Get list of products in shopping cart

Return: array of catalogProductEntity - an array contained list of products

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • mixed (int | string) storeView - Store view Id or code (optional)

cart_product.moveToCustomerQuote

Move product(s) from Quote To Customer Shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • array of CartProductEntity - an array with list of CartProductEntity
  • mixed (int | string) storeView - Store view Id or code (optional)

Faults

Fault Code Fault Message
1001 Can not make operation because store is not exists
1002 Can not make operation because quote is not exists
1021 Product’s data is not valid.
1022 Product(s) could not be added.
1023 Quote could not be saved during adding product(s) operation.
1024 Product(s) could not be updated.
1025 Quote could not be saved during updating product(s) operation.
1026 Product(s) could not be removed.
1027 Quote could not be saved during removing product(s) operation.
1028 Customer is not set for quote.
1029 Customer’s quote is not existed.
1030 Quotes are identical.
1031 Product(s) could not be moved.
1032 One of quote could not be saved during moving product(s) operation.

Resource: cart_customer

Methods

cart_customer.set

Add Customer Information into shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • CartCustomerEntity customerData - an associative array with customer information
  • mixed (int | string) storeView - Store view Id or code (optional)

cart_customer.addresses

Set customer’s addresses (shipping, billing) in shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • array of CartCustomerAddressEntity customerAddressData - an array with list of CartCustomerAddressEntity
  • mixed (int | string) storeView - Store view Id or code (optional)

Faults

Fault Code Fault Message
1001 Can not make operation because store is not exists
1002 Can not make operation because quote is not exists
1041 Customer is not set.
1042 The customer’s identifier is not valid or customer is not existed
1043 Customer could not be created.
1044 Customer data is not valid.
1045 Customer’s mode is unknown
1051 Customer address data is empty.
1052 Customer’s address data is not valid.
1053 The customer’s address identifier is not valid
1054 Customer address is not set.
1055 Customer address identifier do not belong customer, which set in quote

Resource: cart_shipping

Methods

cart_shipping.method

Set a shipping method for shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • string shippingMethod - shipping method code
  • mixed (int | string) storeView - Store view Id or code (optional)

cart_shipping.list

Get list of available shipping methods for shopping cart

Return: array of CartShippingMethodEntity - an array with list of available shipping methods

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • mixed (int | string) storeView - Store view Id or code (optional)

Faults

Fault Code Fault Message
1001 Can not make operation because store is not exists
1002 Can not make operation because quote is not exists
1061 Can not make operation because of customer shipping address is not set
1062 Shipping method is not available
1063 Can not set shipping method.
1064 Can not receive list of shipping methods.

Resource: cart_payment

Methods

cart_payment.method

Set a payment method for shopping cart

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • CartPaymentMethodEntity paymentData - an associative array with payment method information
  • mixed (int | string) storeView - Store view Id or code (optional)

cart_payment.list

Get list of available payment methods for shopping cart

Return: array of CartPaymentMethodEntity - an array with list of available payment methods

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • mixed (int | string) storeView - Store view Id or code (optional)

Faults

Fault Code Fault Message
1001 Can not make operation because store is not exists
1002 Can not make operation because quote is not exists
1071 Payment method data is empty.
1072 Customer’s billing address is not set. Required for payment method data.
1073 Customer’s shipping address is not set. Required for payment method data.
1074 Payment method is not allowed
1075 Payment method is not set.

Resource: cart_coupon

Methods

cart_coupon.add

Add coupon (code) to Quote

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • string couponCode - coupon code
  • mixed (int | string) storeView - Store view Id or code (optional)

cart_coupon.remove

Remove coupon (code) from Quote

Return: boolean

Arguments:

  • int quoteId - Shopping Cart Id (Quote Id)
  • mixed (int | string) storeView - Store view Id or code (optional)

Faults

Fault Code Fault Message
1001 Can not make operation because store is not exists
1002 Can not make operation because quote is not exists
1081 Coupon could not be applied because quote is empty.
1082 Coupon could not be applied.
1083 Coupon is not valid.

Example

  1.     $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
  2. $sessionId = $proxy->login('apiUser', 'apiKey');
  3.  
  4. // Create a quote, get quote identifier
  5. $shoppingCartId = $proxy->call( $sessionId, 'cart.create', array( 'magento_store' ) );
  6.  
  7. // Set customer, for example guest
  8. $customerAsGuest = array(
  9.     "firstname" => "testFirstname",
  10.     "lastname" => "testLastName",
  11.     "email" => "testEmail",
  12.     "website_id" => "0",
  13.     "store_id" => "0",
  14.     "mode" => "guest"
  15. );
  16. $resultCustomerSet = $proxy->call($sessionId, 'cart_customer.set', array( $shoppingCartId, $customerAsGuest) );
  17.  
  18. // Set customer addresses, for example guest's addresses
  19. $arrAddresses = array(
  20.     array(
  21.         "mode" => "shipping",
  22.         "firstname" => "testFirstname",
  23.         "lastname" => "testLastname",
  24.         "company" => "testCompany",
  25.         "street" => "testStreet",
  26.         "city" => "testCity",
  27.         "region" => "testRegion",
  28.         "postcode" => "testPostcode",
  29.         "country_id" => "id",
  30.         "telephone" => "0123456789",
  31.         "fax" => "0123456789",
  32.         "is_default_shipping" => 0,
  33.         "is_default_billing" => 0
  34.     ),
  35.     array(
  36.         "mode" => "billing",
  37.         "firstname" => "testFirstname",
  38.         "lastname" => "testLastname",
  39.         "company" => "testCompany",
  40.         "street" => "testStreet",
  41.         "city" => "testCity",
  42.         "region" => "testRegion",
  43.         "postcode" => "testPostcode",
  44.         "country_id" => "id",
  45.         "telephone" => "0123456789",
  46.         "fax" => "0123456789",
  47.         "is_default_shipping" => 0,
  48.         "is_default_billing" => 0
  49.     )
  50. );
  51. $resultCustomerAddresses = $proxy->call($sessionId, "cart_customer.addresses", array($shoppingCartId, $arrAddresses));
  52.  
  53. // add products into shopping cart
  54. $arrProducts = array(
  55.     array(
  56.         "product_id" => "1",
  57.         "qty" => 2
  58.     ),
  59.     array(
  60.         "sku" => "testSKU",
  61.         "quantity" => 4
  62.     )
  63. );
  64. $resultCartProductAdd = $proxy->call($sessionId, "cart_product.add", array($shoppingCartId, $arrProducts));
  65.  
  66. // update product in shopping cart
  67. $arrProducts = array(
  68.     array(
  69.         "product_id" => "1",
  70.         "qty" => 5
  71.     ),
  72. );
  73. $resultCartProductUpdate = $proxy->call($sessionId, "cart_product.update", array($shoppingCartId, $arrProducts));
  74.  
  75. // remove products from shopping cart, for example by SKU
  76. $arrProducts = array(
  77.     array(
  78.         "sku" => "testSKU"
  79.     ),
  80. );
  81. $resultCartProductRemove = $proxy->call($sessionId, "cart_product.remove", array($shoppingCartId, $arrProducts));
  82.  
  83. // get list of products
  84. $shoppingCartProducts = $proxy->call($sessionId, "cart_product.list", array($shoppingCartId));
  85. print_r( $shoppingCartProducts );
  86.  
  87. // get list of shipping methods
  88. $resultShippingMethods = $proxy->call($sessionId, "cart_shipping.list", array($shoppingCartId));
  89. print_r( $resultShippingMethods );
  90.  
  91. // set shipping method
  92. $randShippingMethodIndex = rand(1, count($resultShippingMethods) );
  93. $shippingMethod = $resultShippingMethods[$randShippingMethodIndex]["code"];
  94.  
  95. $resultShippingMethod = $proxy->call($sessionId, "cart_shipping.method", array($shoppingCartId, $shippingMethod));
  96.  
  97. // get list of payment methods
  98. $resultPaymentMethods = $proxy->call($sessionId, "cart_payment.list", array($shoppingCartId));
  99. print_r($resultPaymentMethods);
  100.  
  101. // set payment method
  102. $paymentMethod = array(
  103.     "method" => "checkmo"
  104. );
  105. $resultPaymentMethod = $proxy->call($sessionId, "cart_payment.method", array($shoppingCartId, $paymentMethod));
  106.  
  107. // add coupon
  108. $couponCode = "aCouponCode";
  109. $resultCartCouponRemove = $proxy->call($sessionId, "cart_coupon.add", array($shoppingCartId, $couponCode));
  110.  
  111. // remove coupon
  112. $resultCartCouponRemove = $proxy->call($sessionId, "cart_coupon.remove", array($shoppingCartId));
  113.  
  114. // get total prices
  115. $shoppingCartTotals = $proxy->call($sessionId, "cart.totals", array($shoppingCartId));
  116. print_r( $shoppingCartTotals );
  117.  
  118. // get full information about shopping cart
  119. $shoppingCartInfo = $proxy->call($sessionId, "cart.info", array($shoppingCartId));
  120. print_r( $shoppingCartInfo );
  121.  
  122. // get list of licenses
  123. $shoppingCartLicenses = $proxy->call($sessionId, "cart.licenseAgreement", array($shoppingCartId));
  124. print_r( $shoppingCartLicences );
  125.  
  126. // check if license is existed
  127. $licenseForOrderCreation = null;
  128. if (count($shoppingCartLicenses)) {
  129.     $licenseForOrderCreation = array();
  130.     foreach ($shoppingCartLicenses as $license) {
  131.         $licenseForOrderCreation[] = $license['agreement_id'];
  132.     }
  133. }
  134.  
  135. // create order
  136. $resultOrderCreation = $proxy->call($sessionId,"cart.order",array($shoppingCartId, null, $licenseForOrderCreation));



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs