# Conditionally Updating Order Prices

**URL:** <https://forum.sambapos.com/t/conditionally-updating-order-prices/8017>\
**Category:** V5 Tutorial\
**Created:** [November 8, 2015, 7:03pm UTC](https://forum.sambapos.com/t/conditionally-updating-order-prices/8017 "2015-11-08T19:03:02Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![emre](https://forum.sambapos.com/user_avatar/forum.sambapos.com/emre/32/39073_2.png) [@emre](https://forum.sambapos.com/u/emre)\
**Post date:** [November 8, 2015, 7:03pm UTC](https://forum.sambapos.com/t/conditionally-updating-order-prices/8017/1 "2015-11-08T19:03:02Z")

</div>

In this tutorial I’ll show you how to automate updating order prices conditionally. We’ll have 3 prices. Breakfast price, Dinner price and ToGo price. Breakfast or Dinner price will apply automatically depending on time of the day. Regardless time of the day ToGo price will activate when ticket marked as ToGo.

##Configuring Prices

First we’ll define price definitions from Management \> Products \> Price Definitions screen.

 ![](https://forum.sambapos.com/uploads/default/original/3X/3/4/34b36736a488cfa5e502efcbc15f8c0587124dc1.png)

Breakfast price will appear as `BB` on ticket and bills. I’ll create another price definition for `Dinner` price and tag as `DN`.

 ![](https://forum.sambapos.com/uploads/default/original/3X/8/4/847b90c10d95266fa45292af64a057fb6f5727fc.png)

> 💡 I won’t create a price definition for ToGo prices as I’ll use default product prices as ToGo prices.

When I display Price List Editor I’ll see three prices for each product. I’ll use first column prices as ToGo prices. BB is Breakfast and DN is Dinner price. Update prices and click Save.

> 💡 If you leave BB or DN price empty default price will be used.

 ![](https://forum.sambapos.com/uploads/default/original/3X/f/1/f155214964c91da35a9fb95f5d34fc15d5e9fa56.png)

After finishing defining prices I’ll create a new action to update order prices. Use Automation \> Actions screen to create a new action and choose action type as `Update Order`.

 ![](https://forum.sambapos.com/uploads/default/original/3X/b/b/bb02820c870d187849c80d1cf3e5208ac378c3fc.png)

By using `Update Order` action we can change order line values. I’ll use this action to change order’s price tag so I’m defining a variable for `Price Tag` parameter.

> 💡 I can use Price parameter to set a fixed price value for order but I need to read defined price for related price tag so I’m using `Price Tag` parameter.

> 💡 `Update Order` is a special action that works for selected orders on ticket. If there are no selected order lines on ticket it updates **all** order lines. When you add a new order it becomes selected while order specific rules working like `Order Added`. So if you execute this action in `Order Added` event it updates only related order. If you execute it in a ticket rule like `Ticket Closing` it updates all orders as there are no selected orders.

> 💡 While defining action I’ve defined `[:Price Tag]` variable instead of typing a fixed `BB` or `DN` price tag value. So I can tell which price tag will apply to order line while executing this action inside a rule.

##ToGo Tickets

Tracking ToGo tickets topic is out of scope for this tutorial. We’ll use Ticket Tags to mark a ticket as a ToGo ticket. I’ll create a Toggle button to Enable / Disable ToGo ticket.

We need an action to Update Ticket’s `Delivery Type` tag. It can be `ToGo` or `Dine in`. Create new action and set action type as `Update Ticket Tag`

 ![](https://forum.sambapos.com/uploads/default/original/3X/1/f/1f1bc5c80de9adf15dfdab46fc3d8823cda3e726.png)

Now we’ll create a button that toggles ticket’s delivery type.

 ![](https://forum.sambapos.com/uploads/default/original/3X/8/7/87391f41b741e5138816f036567019718ad47dcb.png)

When we enable toggle each button click executes `Toggle Delivery Type` command with a command value defined in values section. Each click executes next command value. I’ll map this button to ticket on `Mappings` screen.

 ![](https://forum.sambapos.com/uploads/default/original/3X/1/9/19935daa902da764b2f5d1e80d5c80943e619056.png)

We need to execute `Update Delivery Type` action when this button clicked. I’ll create a new rule to do that.

 ![](https://forum.sambapos.com/uploads/default/original/3X/8/f/8f065d079d64e927b5fc498a1d10d8276d96bc59.png)

Our default Delivery Type will be dine in so I’ll create a new `Ticket Created` rule to set default Delivery Type as Dine in.

 ![](https://forum.sambapos.com/uploads/default/original/3X/b/a/bae7781e8a9dbc694377404b6252789bef402bdb.png)

Create a new ticket to see if default Delivery Type correctly updates and if Clicking `ToGo` button toggles delivery type correctly.

 ![](https://forum.sambapos.com/uploads/default/original/3X/e/6/e6af34887a6798f62851b92a148512dc80605c51.png)

##Price Automation

Now we’re ready to configure how prices will change. Assume we need to update prices as..

- Default price will be used for all `ToGo` tickets.
- BB (breakfast) price will be used for `Dine in` tickets until 01:00 PM (13:00).
- DN (dinner) price will be used for `Dine in` tickets after 01:00 PM (13:00).

So we need to update prices…

- When a new order added to ticket.
- When delivery type toggles.

> 💡 We need to update prices when delivery type toggles as operator can change delivery type after adding orders. While adding orders dine in prices will apply but when operator changes delivery type as ToGo we need to change all order’s prices.

**IMPORTANT!!! Must Read:** When we have multiple cases to implement it is a good idea to implement it without attaching it to a specific rule. To do this: **I’ll create a temporary button that updates prices when clicked. When I ensure it works fine I’ll delete button and make it run automatically.** By using this technique you can easily test if your implementation works fine and you can easily map actions to multiple rules.

I’ll create `Update Prices` button and map it to Ticket.

 ![](https://forum.sambapos.com/uploads/default/original/3X/5/4/54b64cabdc8557323d1249079b720fb6724abeb9.png)

I’m mapping it to Ticket.

 ![](https://forum.sambapos.com/uploads/default/original/3X/9/f/9fb1855fef9cbf60881b341642ee33dcf24301a7.png)

You should see button here:

 ![](https://forum.sambapos.com/uploads/default/original/3X/4/b/4b3a9ac529c940ae34a0ea0238c2e6bd1a107286.png)

Now I’ll create 3 Rules that works when `Update Prices` button clicked. When you add orders, change delivery type and click `Update Prices` button, order prices should change accordingly.

####ToGo Price Rule

We’ll create a new `Automation Command Executed` Rule that applies default prices when ticket’s delivery type is `ToGo`.

 ![](https://forum.sambapos.com/uploads/default/original/3X/0/6/06b2ebe4676e36051e121287ccd877cb4a4a3863.png)

> 💡 I’ve used `{TICKET TAG:Delivery Type}` tag to read selected Delivery Type for ticket.

> 💡 **Add a single space for Price Tag parameter to leave price tag empty and apply default prices.**

####Breakfast Price Rule

While applying Dine in prices we’ll also test time of day. We’ll apply breakfast prices if time is before 01:00 PM. I’ll create a new rule that applies `Breakfast` (BB) prices if `Delivery Type` is `Dine in` and time is before 01:00 PM (13:00).

 ![](https://forum.sambapos.com/uploads/default/original/3X/7/b/7bf2594691742da77362c979edc8cc290d9f904d.png)

> 💡 `{DATE}` tag returns actual date & time. As I can define formatting for this tag I’m using it as `{DATE:HHmm}` to format time as HHmm. HHmm formatting returns time in 24 hr format. So when time is 03:45 PM it returns 1545. If I need to know time is before 08:30 PM I can assume all values less than 2030 is before 08:30 PM (20:30).

> 💡 **Don’t forget to change constraint operator as `Matches All`.**

####Dinner Price Rule

Dinner price rule is similar to `Apply Breakfast Prices Rule` rule. You can duplicate it or create a new rule to define how Dinner Price rule works. This rule will work when `Delivery Type` is `Dine in` and Time is after 01:00 PM (13:00)

 ![](https://forum.sambapos.com/uploads/default/original/3X/0/6/06ed35f4dfc170f80d97ed9f830ff3ecc679d076.png)

###Testing

To ensure prices updates correctly create a new ticket, set delivery type and click `Update Prices` button to see if prices updates correctly. If you need to find a configuration mistake you can use `Show Message` action to see how rules updates prices.

Create a new ticket and add few orders. Be sure sure you’ve configured all prices.

 ![](https://forum.sambapos.com/uploads/default/original/3X/f/c/fc581a9e6fc49c715f4dfb2f9574ac6c884c7c0e.png)

Clicking `Update Prices` button should apply prices accordingly.

 ![](https://forum.sambapos.com/uploads/default/original/3X/f/5/f51cf6dc725c8e9bc8379d3a5b5abf70b08d9087.png)

Also test if `ToGo` and `Breakfast` prices applies fine before automating events.

##Automation

On final step we’ll make `Update Prices` button to work automatically when an order is added to ticket and when Delivery Type changes.

#### Updating prices after adding an order

I’ll create a new `Execute Automation Command` action. This action will trigger Automation Command our `Update Price` button executes.

 ![](https://forum.sambapos.com/uploads/default/original/3X/c/d/cd0e22f7a1d8d85b11fde205bac741acb142d7f9.png)

I’ll create a new rule that executes this action when a new order line added to ticket.

 ![](https://forum.sambapos.com/uploads/default/original/3X/f/6/f669a78676f1b7267acf7100dfd50260603f148c.png)

We’re benefiting from how we’ve setup rules. We can trigger `Update Prices` anytime we need.

####Updating prices while changing Delivery Type

You’ll remember we already created `Update Delivery Type` rule to change Ticket’s delivery type as ToGo or Dine in. Now I’ll edit `Update Delivery Type` Rule and add `Execute Update Prices` action to update prices after delivery type changes.

 ![](https://forum.sambapos.com/uploads/default/original/3X/6/8/6860cb27eecb45504f1ab07dbb254ac13ebc003d.png)

##Final test

Now prices should update fine without the need of clicking `Update Prices` button. If it works fine you can unmap or remove `Update Prices` button to remove it from ticket screen.

![](https://forum.sambapos.com/uploads/default/original/3X/3/9/3969c1c914d39b5221ef683c9373c8af0d187f06.gif)

---

_[View the full topic](https://forum.sambapos.com/t/conditionally-updating-order-prices/8017)._
