Working with discounts and rounding.
Copy the link to the article
Copied

Main provisions

Starting from version 6.0, discounts are structured differently. The key change is that the discount for an order is not taken into account in the total sum of the order, but is distributed between the products and taken into account in the sum of each individual item of the product in the order. At the same time, the distributed order discount does not affect the discounts on products, which can be specified separately as before.

Let's look at an example, where you have the following order:

| Name | Price | Discount | Qty | Total |
| | | | | |
| Shorts | 600 eur | 50 euros (per product) | 2 | 1100 euros |
| | | | | |
| Slates | 300 eur | 0 eur (per product) | 3 | 900 eur |
| | |
| Total | 2000 eur |

We gave a discount for the order of 300 euros.

In system version 5.0 and lower this discount will be included in the total sum of the order:

| Name | Price | Discount | Qty | Total |
| | | | | |
| Shorts | 600 eur | 50 eur (per product) | 2 | 1100 eur |
| | | | | |
| Slates | 300 eur | 0 eur (per product) | 3 | 900 eur |
| | |
| Discount on order | 300 eur |
| | |
| Total | 1700 eur |

In version 6.0 and higher the order discount will be distributed between the products and will be taken into account in their cost:

| Name | Price | Discount | Qty | Total |
| | | | | |
| Shorts | 600 eur | 50 eur (per product) | 2 | 980 eur |
| | | 60 eur (to order) | | |
| | | | | |
| Slates | 300 eur | 0 eur (per product) | 3 | 720 eur |
| | | 60 eur (to order) | | |
| | |
| Total | 1700 eur |

In this case, the order cost is calculated as follows: (600 – 50 – 60) x 2 + (300 – 60) x 3 = 1700

API

API v4

In API v4 and lower, discount fields order[discount], order[discountPercent], order[items][][discount], order[items][][discountPercent] in the order remain unchanged and are available both for writing and reading.

Using the order example above, when creating an order, the values ​​must be passed in the following form:

order = {
 // ...
 "discount": 300,
 "items": [
 {
 "offer": { "externalId": "1" },
 "initialPrice": 600,
 "discount": 50,
 "quantity": 2
 },
 {
 "offer": { "externalId": "2" },
 "initialPrice": 300,
 "quantity": 3
 }
 ],
 // ...
}

In the API methods for receiving orders, the content and values ​​of the fields will be similar:

{
 // ...
 "discount": 300,
 "items": [
 {
 "offer": { "externalId": "1" },
 "initialPrice": 600,
 "discount": 50,
 "quantity": 2
 },
 {
 "offer": { "externalId": "2" },
 "initialPrice": 300,
 "quantity": 3
 }
 ],
 // ...
}

API v5

In the methods for creating and editing the order /api/v5/orders/create, /api/v5/orders/{externalId}/edit, /api/v5/orders/upload, you can transfer discounts on the order and products in the fields order[discountManualAmount], order[discountManualPercent], order[items][][discountManualAmount], order[items][][discountManualPercent], and discounts on the order will be distributed between the products.

Using the order example above, when creating an order, the values ​​must be passed in the following form:

order = {
 // ...
 "discountManualAmount": 300,
 "items": [
 {
 "offer": { "externalId": "1" },
 "initialPrice": 600,
 "discountManualAmount": 50,
 "quantity": 2
 },
 {
 "offer": { "externalId": "2" },
 "initialPrice": 300,
 "quantity": 3
 }
 ],
 // ...
}

In the methods of getting orders /api/v5/orders, /api/v5/orders/{externalId} returns the total calculated monetary discount per product unit for each product item in the field order[items][][discountTotal], which takes into account both the current product discounts and the order discounts distributed between products.

{
 // ...
 "items": [
 {
 "offer": { "externalId": "1" },
 "initialPrice": 600,
 "discountTotal": 110,
 "quantity": 2
 },
 {
 "offer": { "externalId": "2" },
 "initialPrice": 300,
 "discountTotal": 60,
 "quantity": 3
 }
 ],
 // ...
}

Extreme cases when distributing order discounts between products

In some cases, the system cannot distribute the order discount between products. Let's show with an example.

Let's say there is an order with the following details:

| Name | Price | Discount | Qty | Total |
| | | | | |
| Shorts | 600 eur | - | 3 | 1800 eur |
| | |
| Total | 1800 eur |

We add a discount for the order of 10 euros. The system needs to distribute the order discount between all units of products, of which there are 3 pieces in the order.

By default, when you try to specify such a discount for an order, the system will display an error message. What is important, an error will be generated both if you place such an order in the system, and via API, regardless of the API version '.

If the “Correct order discount” setting is enabled in the system in the Settings > Orders section, the system will adjust the order discount to the nearest divisible value (in this case, it will change the order discount from 10 euros to 9.99 euros).

Rounding

In version 6.0, a rounding function has been added, which can be enabled in the Settings > Orders section. Rounding, if enabled, applies to the product items in the order. The cost that is discarded from the sum of the product as a result of rounding goes into the discount of the product

In the settings there is also an option for rounding the cost of the product taking into account the order cost, which is set by default when rounding is enabled. With this option, the cost of the products is rounded in such a way that the resulting cost of the order is as close as possible to the cost of the order without rounding.

Thank you for your feedback.
Was this article helpful?
No
  • Рекомендации не помогли
  • Нет ответа на мой вопрос
  • Текст трудно понять
  • Не нравится описанный функционал
Yes
Previous article
Working with API methods of history
This article explains the general principles of working with API methods of history and provides descriptions of the fields that can be obtained as a result.
Next article
Interaction with API under hosting restrictions
If your site is running on a hosting that does not meet the requirements of the PHP client to interact with API, you can call API using the usual file_get_contents function. In the article, we will analyze examples of its use.
#}