# Price calculation

### Price Mapping

Stockeo gives you a possibility to update product prices based on the supplier feed.

Add the Price field in the Data Mapping section, and specify which column/node contains prices in the supplier feed.

<figure><img src="https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-7b11786286b4e80bc2ec79463629a47a96dc78aa%2Fcsv-data-mapping.png?alt=media&#x26;token=f9b979fb-b0c6-4c68-a935-65012d8dd5f0" alt="price data mapping"><figcaption></figcaption></figure>

### Price Formula

You can also calculate prices according to your needs. Click on the gear icon ![](https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-bdbe9954f361f9bad0220d8db5e7b54697a69b71%2Fimage.png?alt=media\&token=fff94302-92fe-413f-b9fc-08b5e1d836e4) to define a price formula in Liquid.

<figure><img src="https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-dd98013ceb3d26ea7eeb001c96b8c1e812942402%2Fprice-formula.png?alt=media&#x26;token=6449e9b0-7881-422e-8498-cfb2427249c0" alt=""><figcaption></figcaption></figure>

### Variables

The available variables are

* `price` - the feed price
* `sku` - the feed SKU
* `quantity` - the feed quantity, available if added to data mapping
* `cost` - the product cost as in the feed, available if added to data mapping
* `variant.price` - the current variant price in Shopify (before update)

### Operations

You can use all the standard Liquid math filters to perform calculations.

#### plus

Use the `plus` filter to add a number.

```liquid
{{ price | plus: 3 }}
```

#### minus

Use the `minus` filter to subtract a number.

```liquid
{{ price | minus: 1 }}
```

#### times

Use the `times` filter to multiply price by a given number.

```liquid
{{ price | times: 1.2 }}
```

#### **divided\_by**

Use the `divided_by` filter to divide price by a given number.

```liquid
{{ price | divided_by: 1.2 }}
```

#### round

Use the `round` filter to round the price to the nearest integer or to the specified number of decimals.

| Formula                   | Feed Price | Result |
| ------------------------- | ---------: | -----: |
| `{{ price \| round }}`    |       4.32 |   4.00 |
| `{{ price \| round }}`    |       4.56 |   5.00 |
| `{{ price \| round: 1 }}` |       4.44 |   4.40 |
| `{{ price \| round: 1 }}` |       4.68 |   4.70 |

#### ceil

Use the `ceil` filter to round the price up to the nearest integer.

| Formula               | Feed Price | Result |
| --------------------- | ---------: | -----: |
| `{{ price \| ceil }}` |       4.32 |   5.00 |
| `{{ price \| ceil }}` |       4.56 |   5.00 |

#### floor

Use the `floor` filter to round the price down to the nearest integer.

| Formula                | Feed Price | Result |
| ---------------------- | ---------: | -----: |
| `{{ price \| floor }}` |       4.32 |   4.00 |
| `{{ price \| floor }}` |       4.56 |   4.00 |

#### at\_least

Use the `at_least` filter to limit prices to a minimum value.

| Formula                      | Feed Price | Result |
| ---------------------------- | ---------: | -----: |
| `{{ price \| at_least: 5}}`  |       2.34 |   5.00 |
| `{{ price \| at_least: 5 }}` |       5.67 |   5.67 |

### Rounding

You can combine the standard math filters to achieve more price-specific rounding.

#### Round up to .99

Use the following formula to round prices up to the nearest .99

```liquid
{{ price | ceil | minus: 0.01 }}
```

If a price is already a whole number, then the formula will still subtract one cent. If you prefer to keep whole prices as they are, and only round up fractions to .99, then use the following formula.

```liquid
{{ price | ceil | minus: 0.01 | at_least: price }}
```

| Formula                                                | Feed Price | Result |
| ------------------------------------------------------ | ---------: | -----: |
| `{{ price \| ceil \| minus: 0.01 }}`                   |      12.34 |  12.99 |
| `{{ price \| ceil \| minus: 0.01 }}`                   |      12.00 |  11.99 |
| `{{ price \| ceil \| minus: 0.01 \| at_least: price}}` |      12.34 |  12.99 |
| `{{ price \| ceil \| minus: 0.01 \| at_least: price}}` |      12.00 |  12.00 |

### Price formatting

When passing prices to Shopify, it is crucial to ensure they are in the correct format. Prices containing currency codes (e.g., *125 USD*) or commas as decimal separators (e.g., *312,74*) can result in errors such as "Invalid price". To prevent them, you can use Liquid formulas to reformat prices.

#### Removing the currency code from a feed price

Suppose the feed provides a price in the format *125 USD*. To remove the currency code, apply the following Liquid formula:

```liquid
{{ price | remove: "USD" }}
```

Whitespaces are removed from prices by Stockeo under the hood so there is no need to include them in Liquid formulas.

#### Replacing commas with dots in prices for decimal separator

Suppose the feed provides a price in the format *312,74.* To replace the comma with a dot and remove the currency code, apply the following formula:

```liquid
{{ price | replace: ",","." }}
```

#### Removing commas as thousand separators in prices

Suppose the feed provides a price in the format *1,000.* To the comma used as a thousand separator, apply the following formula:

```liquid
{{ price | remove: "," }}
```

{% hint style="info" %}
Replacing a comma with a dot or removing a comma from a price can significantly alter its value if not applied correctly. Make sure to verify the price format used in the feed provided by the supplier.
{% endhint %}

### Add markup to the feed price using metafields

With Stockeo you can shape prices in your store based on the amounts from the feed and markup stored in the metafields for individual products.

In order to access to the metafield use one of the following pattern:

* `product.metafields.namespace.key`
* `variant.metafields.namespace.key`

For example, if you want to add a 50% markup to the product's price, you need to set the markup metafield to 50 and use the following price formula:

```liquid
{% assign markup = product.metafields.custom.markup | default: 0 %}
{% assign markup_multiplier = markup | divided_by: 100 | plus: 1 %}
{{ price | times: markup_multiplier }}
```

The **default** filter prevents error when the metafield with the markup is empty. In such a case the product price will be the same as the amount in the feed.

| Feed Price | Markup Metafield | Calculated Price |
| :--------: | :--------------: | :--------------: |
|    $100    |   no set value   |       $100       |
|    $100    |         0        |       $100       |
|    $100    |        50        |       $150       |
|    $100    |        100       |       $200       |

### Calculate the product price depending on the price level in the feed

If you want the calculation of the price of a product in your store to change depending on the price in the feed, you can use the Liquid formula with **if/elsif** statements.

```liquid
{% if price > 0 and price < 5 %}
{{ price | times: 3 }}
{% elsif price >= 5 and price < 10 %}
{{ price | times: 2 }}
{% elsif price >= 10 and price < 15 %}
{{ price | times: 1.5 }}
{% else %}
{{ price }}
{% endif %}
```

What price does the above code return?

If the price in the feed is between **0** and **4.99**, it will be multiplied by **3**.\
If the feed price is between **5** and **9.99**, it will be multiplied by **2**.\
If the feed price is between **10** and 1**4.99**, it will be multiplied by **1.5**.\
In all other cases, the product price will be equal to the feed price.

### Get price from different columns conditionally

Assume you want to take a price from the column **RRP**. When **RRP** is equal to **0** or **empty**, then get a value from the column **Price**. To handle this case, use the following Liquid code in the Price field:

```liquid
{% assign RRP = RRP | plus: 0 %}{% if RRP == 0 %}{{ Price }}{% else %}{{ RRP }}{% endif %} 
```

<figure><img src="https://2071801931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6HyRe5TyFXHKQEybH7n%2Fuploads%2Fgit-blob-2fa6ad679585f490579b7fd1791c59d8fb02bcf1%2Fstockeo-use-price-from-another-field-liquid.png?alt=media" alt="If statemant in the price field in the Data Mapping section of Stockeo automation"><figcaption><p><strong>If</strong> statemant in the price field of Stockeo automation</p></figcaption></figure>

The code above is used to select from which column Stockeo should take the price. If you set a **price formula** to calculate the final price, it will be executed on the value that Stockeo selected according to the above condition.
