Calculate the value of a shopping cart, and have discounts, promotions and taxes automatically calculated by API. You only need to input item IDs and quantities.
calculateShoppingCart is a very versatile function that:
Parameter name | Description | Possible value | Required |
---|---|---|---|
documentID | Sales document ID. | integer | |
type | Possible values: INVWAYBILL, CASHINVOICE, WAYBILL, PREPAYMENT, OFFER, EXPORTINVOICE, RESERVATION, ORDER, INVOICE, CREDITINVOICE. Default value is CASHINVOICE. |
string | |
date | If omitted, current date will be used. | ISO date (yyyy-mm-dd) | |
warehouseID | Warehouse ID. You may specify either warehouseID or pointOfSaleID , whichever is more convenient for you.If you do not specify neither location nor register, API automatically assumes you are selling from the first location in your locations list (by ID). All price lists and promotions associated with that location will apply, and that location's tax rate will be set to all items. To be always sure of what location's price lists, promotions and taxes are being applied, we recommend to set this parameter explicitly. |
integer | |
pointOfSaleID | Register ID. An alternative to warehouseID. |
integer | |
pricelistID | Price list ID. Set this value ONLY when you want to apply just this one price list to the sale and no others. In most cases, you do not need that! API will automatically apply any store, customer, or customer group price lists that have been defined, and will combine them automatically. |
integer | |
customerID | Customer ID. If not set, API will not make any assumptions about the customer, so no customer (or customer group) price lists will apply. If you want the sale to go to the "Default customer" or "POS Customer", send that customer's ID. |
integer | |
currencyRate | Exchange rate of the shopping cart currency against system's default currency. If the shopping cart is in system's default currency, this parameter does not have to be specified (but if you specify it, use Pay attention to the way rates should be divided. If your shopping cart is in JPY and your account default currency is EUR, the expected value is To get the current rate for a currency defined in Erply back office, see getCurrencies. When using currencies, Erply can only apply price list prices, not any promotions.. Translating a promotion into a foreign currency has not been implemented yet. So, if you want to use the "currencyRate" input parameter, you must also specify If currencyRate is not a valid positive decimal, API returns error 1014. |
Decimal | |
applyQuotedPrices | API calculateShoppingCart can also apply "a price from customer's previous quote". We assume that if a confirmed quote has been given to a customer (and it has not expired yet), then the items on the quote could be freely sold at the indicated price, as many times as the customer wants. If you want this feature, set this flag to 1. If this flag has been set to 1, and there is a quote for the specified customer that has not expired yet, and it contains the specific product, the price from the quote will override price list price (even if quoted price is higher than price list price). Promotions, however, will still apply on top of the quote price as usual. Currently, this flag only has an effect if you have not disabled the use of quote prices with configuration parameter |
Integer (1 or 0) | |
doNotApplyPromotions | If set to 1, then only price lists will be applied — not promotions. | Integer (1 or 0) | |
getAutomaticCoupons | If set to 1, API will also return a list of coupons that should be automatically printed from POS after the sale. See output field automaticCoupons for a more detailed explanation. We recommend to leave it unset while you are still building up shopping cart contents — but set it to 1 when the cart has been finalized and you issue the final call to calculateShoppingCart. |
integer | |
couponIdentifiers | Eg: "109000002346,109000002351" Coupon codes (identifiers) that cashier has scanned. Erply allows you to issue printed coupons to customers. Each printed coupon must have a unique identifier. In Erply backend, all issued coupons are listed in the Retail Chain » Issued Coupons module. A coupon is basically a method for invoking a sales promotion, so if customer returns to the store with a coupon and cashier scans it, a promotion will apply. The recommended API workflow for accepting coupons is as follows:
NB! Coupons are not the same as "promotional codes", eg. "Get 20% off of all barbecue equipment with promo code JULY4" (which many be printed in an ad, or distributed in customer newsletter). As far as Erply is concerned, you do not need a coupon setup for that. For that case, we recommend to define a manual promotion, set "JULY4" as its name, and have cashier to apply the promotion manually whenever customer presents the code. Certain types of promotions allow to scan more than one coupon (the promotion will then apply multiple times):
|
String (Comma-separated strings) | |
manualPromotionIDs | Eg: "1,4,18" Old deprecated name: "manualCampaignIDs" IDs of promotions that cashier has applied manually. In Erply, a promotion can be configured in three ways:
manualPromotionIDs field must all be manual promotions; others will be ignored.A promotion MAY be listed multiple times (if you want to apply it multiple times), but this only works with the following promotion types:
|
String (Comma-separated integers) | |
doNotApplyInvoiceLevelPromotions | Integer (0 or 1) | ||
taxExempt | Set a manual tax exemption to this sale. If the selected customer is already marked as being tax exempt on customer card, you do not need to send this flag. If customer provides a tax exemption certificate number, you may attach it to the sale using the taxExemptCertificateNumber field in saveSalesDocument. |
Integer (0 or 1) | |
euInvoiceType | Whether the sale is a domestic sale, a sale to another EU country or a sale to outside of the EU. Possible values are "DOMESTIC", "EU", "OUTSIDE_EU". The default tax rate suggested by API calculateShoppingCart depends on that. If this concept does not apply (your business is not in the EU), just leave the field unset. |
string | |
***** | Send invoice lines (ie., items and quantities) as a flat list. For each item, you may send the following input parameters. Replace # with a sequential number (0, 1, 2, 3 etc.) | ||
productID# | ID of the product (SKU) sold. | integer | yes |
amount# | Sold quantity. In general, quantity can be unlimited. However, for performance reasons, API imposes two limitations.
|
number | yes |
price# | A fixed net price for this item. Set this parameter only if you want to override API's pricing. In other cases, omit it and let API set the appropriate selling price automatically. This parameter overrides product card price and price lists. On top of this price, API will still apply manual discount (parameter discount# ) and promotions that discount the whole cart (Get % Off Everything, Get $ Off Your Purchase). However, the most common use case for the price# parameter is to get an updated total for an already saved invoice or sales order, and in that case, you should turn off these promotions, too, with parameter doNotApplyInvoiceLevelPromotions=1 .Item-level promotions do not apply. (If you want to set a price and have it discounted by all available promotions, use basePrice# instead.)As a historic exception, item-level promotions still apply on top of price# if the product card price is 0, and the item has been marked with the check box "Cashier must set price in POS", and configuration parameter apply_promotions_to_zero_price_products = 1 has been set. |
Decimal | |
basePrice# | Net price, pre-discount. Use this field for a price that cashier has entered manually or has scanned from a price barcode. Like with parameter price# , setting basePrice# overrides price list prices, but API will still apply all promotion discounts, item-level as well as cart-level.If both basePrice# and price# are passed for the same item, basePrice# is ignored. Note that this is a net price. If the scanned barcode contains a price with tax, or you want the cashier to enter price with tax, you need to convert it into a net price first. |
Decimal | |
discount# | Manual discount. Set this field ONLY if cashier has set a manual discount for this invoice line. Manual discount will be applied cumulatively on top of promotion discounts; there is no way to "override" a promotional discount with a manual discount. In general, price lists, discounts and promotions are applied by the API in the following order:
|
Decimal | |
vatrateID# | Set this field if you want a specific VAT / tax rate to be applied to this item. If not set, API will automatically determine the appropriate tax rate (which may be set at register, location, product group or product level). For a list of tax rates and IDs, see getVatRates. For reference, this is the priority (in decreasing order) of various tax rate settings that you can specify in Erply backend:
|
integer | |
manualDiscountReasonCodeID# | Set this field if row must be marked as manually discounted | integer | |
algorithmVersion | Optional calculation algorithm version number. Can be used to return calculated results for a specific version. Valid values are 1,2,3,4 and 5. | integer |
Field name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
rows | array | Array elements have the following attributes:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
netTotal | Decimal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vatTotal | Decimal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rounding | Decimal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
total | number | =netTotal+vatTotal+rounding | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
automaticCoupons | string | Eg:"1,4,18" Superseded by printAutomaticCoupons , see next. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
printAutomaticCoupons | array | List of coupons that should be automatically printed to the customer after the sale has been completed. Array contents:
The recommended workflow is as follows:
Important! API assumes that you are calling calculateShoppingCart to prepare a sales invoice. The list of automatic coupons is provided on the assumption that customer will earn a few more points from the current sale — and those points are already counted in.Eg.: let's say that customers are always given a coupon when they reach 200 points. If a customer currently has 180 points, you call calculateShoppingCart and basket total value is $25, API will instruct you to print a coupon. (After the sale, the customer would have 205 pts, meaning that they would be eligible for the coupon.)However, this assumption does not work if you are calling calculateShoppingCart to create an order, quote, lay-by, waybill or prepayment invoice. In that case, ignore the printAutomaticCoupons field and do not issue any coupons. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
usedCouponIdentifiers | string | Eg: "109000002346,109000002351" Comma-separated list of coupons that had an effect on the given sale (from among all the coupons specified in input parameter couponIdentifiers ). If a coupon was effective, it should be redeemed upon sale completion with API call redeemIssuedCoupon. Ineffective coupons should be given back to the customer, to be used at some other occasion. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
appliedPromotions | array | Promotions that were applied to the cart. Each array element contains the following fields:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
information | string | API analyzes the current shopping cart and customer history, and returns a plain-text message if it makes an interesting observation:
This field might not ber enabled by default, so let us know if you want to retrieve this information. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
freeExtraProductID | integer | This field (and the next ones) notify the cashier if there is a promotion "Buy X and get product Y for free", promotion prerequisites have been fulfilled (customer has purchased X), but free gift Y has not been added to the basket yet. This field contains the product ID of the free gift item. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
freeExtraProductCode | string | See previous. Product code of the free gift item. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
freeExtraProductName | string | See previous. Name of the free gift item. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
freeExtraNotification | string | See previous. Free-text notification about the free gift item that is available. Can be displayed in POS UI. |