Add product to cart
Use this method to add products to the cart during the current cart session.
Requirements
This method requires you to set a specific partner using setPartner.
Request parameters
sessionID
Required (string) Session identifier, which is the output of the Login method. An exception is thrown if the values are incorrect.
productId
Required (integer) Unique product identifier from the 2Checkout system.
pricingListCode
Required (string) The unique identifier of a partner price list.
quantity
Optional (integer) Defines the amount of product units to be ordered. If no quantity info is provided, the minimum available number of units is included in the order. If the quantity provided is not available for purchase, such as in the case of volume discounts, an error message is displayed. When NULL, quantity = 1 is added automatically.
priceOptions
Optional (stringArray) Array of price options codes. If no price options info is provided, the default, required pricing options of the product are ordered. These identifiers mark the individual options inside pricing options configuration groups. Can be NULL.
Request sample
<?php
require ('PATH_TO_AUTH'); // Authentication example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/02Authentication
require ('PATH_TO_SET_PARTNER'); // setPartner example: https://knowledgecenter.avangate.com/Integration/Channel_Manager_API/JSON-RPC/06Reference/Partner/00Set_partner
$productId = 'YOUR_PRODUCT_ID';
$pricingListCode = 'YOUR_PRICING_LIST_CODE';
$quantity = YOUR_PRODUCT_QUANTITY;
$priceOptions = array(
'PRICING_OPTION_1',
'PRICING_OPTION_2'
);
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'id' => $i++,
'method' => 'addProduct',
'params' => array($sessionID, $productId, $quantity, $priceOptions, $pricingListCode)
);
var_dump (callRPC((Object)$jsonRpcRequest, $host));Response
Result
Boolean True or false
Errors
INVALID_PARTNER
No partner is set.
PRODUCT_ERROR
Invalid product ID.
PARTNER_PRICING_LISTS_NOT_FOUND
There are no pricing lists with the provided code.
PRODUCT_NOT_FOUND
There is no active product with the specified product ID in the given pricing list.
INVALID_QUANTITY
Quantity is not available for purchase.
Last updated
Was this helpful?