YaaS offers a coupon services. The “Coupon Management (Beta)” package can be added with the YaaS Marketplace via the YaaS Builder (Administration – Subscriptions). With “Configure it” you could start to add coupons in the Builder, but we will do it in Node-RED and our percentage value will depend on temperature values.
Before we start we also have to manage the required scopes in the Builder Clients. I’ve selected all 4 scopes and as you can see there’s also a
hybris.coupon.redemption event for PubSub (the previous blog post Order created goes more into PubSub and events).
Create a coupon
Let’s start to create a coupon. The easiest way would be to use an inject node with a value. But we want to use temperature values. Therefore I’ve installed the openweathermap Node-RED library and obtained an API key on OpenWeatherMap.
Drag & drop the openweathermap node and configure it:
OpenWeatherMap configuration for Munich.
With a change node you change the ‘tempc’ value to a payload:
Change the tempc property to a payload.
Now we add a coupon create node and select Percentage as the Type. We connect all the nodes, add an inject node and deploy it. When you now press the inject node you see the coupon code and the percentage value:
Use a temperature value to create a coupon.
But before you get too excited, the summer in Munich is cold. So the discount price isn’t so high and it would only make sense if you sold winter stuff. For summer clothing and cold drinks it would make sense to start at 40 degree Celsius and subtract the temperature.
Get coupon and apply it
You can take a look at the Builder in Coupons to see the new created coupon. To get the coupon in Node-RED, add the coupon get node to the flow and configure it. Also add an inject node with the coupon text as string and a debug node:
Show a specific coupon.
When you now press the inject node you can see the coupon data in the debug tab on the right side. To apply this coupon to a shopping cart, just drag & drop a apply discount node and configure it for a customer:
Get a specific coupon and apply it.
After deploying it and pressing the inject node again the discount is added to the customer shopping cart. Open the shop, log in with the customer account and take a look at the shopping cart. You may have to add a product to see it:
Shopping cart with the apply coupon.
The weather forecast for the weekend looks better. Sunday should be 25 degrees, so enjoy the shopping, weather and weekend with some YaaS and Node-RED hacking:
- Take the temperature from tomorrow’s weather forecast
- Use a function node to subtract a temperature value from 42
- Use Fahrenheit divided by π 🙂
- listen to the
hybris.coupon.redemption PubSub event