 Ben fyddwn i'w ddim yn buddillion, ond rwy'n meddwl. Fyddwn y ferfn o'r perffortschyniad segmentaethwch am colled. Roeddwn ni'nill'n meddwl i'r fath. Maen nhw'n brifysgonomiaid y rhywbeth. Pwysig yma, mae'n meddwl i'r qufosio'r bobbi. Rydyn ni'n meddwl am bwysig yma ar y cyfeunio chi'n meddwl. Rydyn ni'n ei wneud am yw Rolfgang Ziga wedi gwahoddi'r wneud ond drwpidog, as Bego, and also on Twitter here. So Wolfgang basically is the professor of rules, as far as I'm concerned. So he wrote the rules module and maintains it now and also does entity API and a lot of core contrib work as well. My name's Richard Jones, I'm the CTO of a company called ICOS in the UK. Sorry, Wolfgang's company is Genomics. Over in Austria, right? Yep. So yeah, we're over in the UK and we've been working with Wolfgang as part of the work we do on Drupal commerce, because Drupal commerce is very reliant on rules, dependency. And the session today is actually quite a lot of it is related to Drupal commerce, because those are the case studies we want to show you today. So the way we're going to play it is first of all Wolfgang's going to spend about ten minutes talking about the basics of rules, why it exists, how it works and sort of the anatomy. And then we're going to go and move on to a real life case study site, sorry it's a real live site of ours and I'll sort of be playing the role of the customer, bringing the requirements and Wolfgang will be showing us how to solve different real world problems. So hopefully it'll be an interesting one for anyone who's working with rules. So I'm going to not talk too much because as I say we've got a lot to go through so I'll hand over straight away to Wolfgang. So the question is why do you want to use something like rules at all. So rules is useful for two kind of things. First of it's a really great tool for doing the action on your site so that you can set up a rule to react on something and do something automatically on the site so you don't have to take care of yourself manually. So instead of maybe writing some custom code to do that you can set up some rules that do that for you in a very structured and simple way. And that way you can use it for automated workflows, you can automate a lot of stuff on your site. And another thing that's also useful with rules is that you can do actions that you configure by the user interface, you put them together, you configure how it should work and then other modules can leverage that configured actions to do whatever they want with them. But we'll have examples of that later on. So two common examples or one common example for doing automations with rules would be something simple like I have a blog post and I want to get notified when someone comments on my blog and yeah for that you configure a rule where you react when someone puts the comment on your blog post and you get an email and that's it. And with rules you also have the possibility to configure some conditions so you can also say I only want to get notified if there are some bad words in the blog post that might be spanned or so. So the anatomy of the rule is always the same, it follows the event condition action pattern. So you have one or more events that are the triggers, you will react often like a comment has been posted and then you can have a set of actions like sending the email in my example and then you can also have a set of conditions so that the actions are only executed when all of those conditions are met what refers to having some bad words in the text of the comment. So some example events would be when a user logs in or when content has been updated or a comment has been posted also a state transitions of a workflow module could be an example event like workbench doing already workflows and you just react when the state changes or when you add a product to your cart. On the action side some common examples would be to maybe can't erode to a user so if a user maybe registers or registers in a certain way by something you just can't an additional role where rules or also there's an action which just called set of data that allows you to modify any kind of field and data of entities in Drupal that's very useful and also you can create new entities and also automatically create new comments and stuff like that. In terms of conditions there are conditions like checking the content type so if you react on a note being saved you can check what kind of note has been saved and the various way the user logs in you have conditions for the user role so you can know what kind of user logs in but you also have the data comparison condition but it's a very mighty condition in rules what allows you to check any value of any entity and compare it with whatever you want and that brings me to a point that's very crucial to the way rules works it's how rules deals with data and it works that way that when you have an action which needs a note for example to work with you can't select the data source the action works with so while you are on an event that actually reacts on a note that's going to be saved it's obvious that you probably want to deal with that note but if you're reacting on a comment that gets to be saved you can use to the data select to select that the note to which the comment has been posted and that's very useful for that but the various way allows you to also specify fixed value for some needed data like when you have a term as input you can also specify a certain term instead of taking over the term that is maybe referenced in the field then rules also features something that's called components and components are really a way to make some reusable pieces in rules and they basically group together a set of actions or conditions or even rules such that you provide them as a reusable chunk to maybe rules itself or to other modules so once you have defined and configured a component you can just invoke the component via another action or other modules allow you to invoke the component like few spark operations what we will see later on as well or you can also do it just by custom code what is also very useful for test cases but makes it very easy to just write your own functionality and put some of the stuff that's going on up to rules let the user configures and else continue with your own code then there's another extension module which is called the rules scheduling module in rules so it's part of the rules package you just need to enable the additional modules and it allows to schedule the evaluation of any kind of component with any kind of input parameters so you can say publish the node just a day later on and it allows you to configure any kind of input parameters you could also do the same thing with comment or even combination of parameters but yeah again we'll have a use code for that later on where you can see that in action how that works and to last we also have loops what is very nice feature in rules 1 2 deal with data this actually multiple values like when you have a user reference and you have multiple users in the user reference and you want to execute an action on each of the user you can just loop over the user reference and just use the regular action actions you have on each of the user so it's very useful in some situations and then the rules module is very api driven in fact it was built api first and the user interface works just on top of that so you can do everything it can do via the api and you can use the api to extend it well a lot of modules will do that already oppositely so they can provide their own events conditions and actions to the system what makes the system even more valuable as you just need to plug in a workflow module and you get the event when the workflow state changed and you can combine this event with all the other great actions that you might have gotten from other modules so as you can tell there's a lot to rule so if if you've already started using it I'm sure you've found there's so much power in there and because so many other modules are already implementing the rules api every new module you switch on you go back into rules and you can see more stuff you can do of course not every module but many many of them and the complexity of rules itself and we felt that a really good way of demonstrating this today would be you know we can't show you absolutely everything in an hour there's so much going on in here so what we've tried to do is pick out representative examples from real life of the different things that Wolfgang has just explained and what we've done is we've picked a site that it's a very simple e-commerce site using Drupal Commerce so Drupal Commerce uses has rules of dependency and there's so many things that that we could figure out that we could do using rules that before we would have needed to write custom modules for or find someone else had done it and so again what we're going to show you today is is just some of those examples and how rules solves the problem for us and hopefully it will get you thinking about other problems that you can solve that may not be immediately obvious so I'll just kick straight into this what we've done is we've prerecorded with this many live demos it would be quite insane to try and do it really live so what we've done is prerecorded these and we will be putting them up with the slides later and Wolfgang's done a voice over for them but for today he's going to live voice over the demos as we go so the first example is a commerce example where you know the customer wants to be able to charge a different VAT for different types of products and we know that the rules API module allows us to interact with other modules and so Drupal Commerce is already doing this there is a set of rules inside Drupal Commerce that allows you to modify the price the selling price of a product depending on certain conditions and that's the one that we're going to show you here so what I'm going to do because we've actually got about an hour's worth of video which we haven't got time to show so we're going to try them all a little over speed and we're going to see if you can keep up so what do you reckon three times no we'll do it at 1.5 so you can go let's stop that okay so hang on hang on sorry it's not on the screen oh policies this is going to be fun I'm going to have to do it like this so Drupal Commerce has set already integrative rules and leverages rules for doing VAT calculation so it applies the VAT rates already with the mean of rules and in order to have an example where you just want to have some certain VAT on some certain products you just need to add some conditions to it as you can see here the VAT rates for Drupal Commerce can be configured on its own in this example we have 20 percent and that's already a component which Drupal Commerce uses for applying the VAT rate and you just need to click configure components you get into the gozi and you can set up conditions and only if the conditions are met the VAT rate will be applied as you see that the action is already reconfigured it's called apply a tax rate to a line item and it just takes the VAT and applies it to the line item line items in Drupal Commerce are basically just the line of an order so it can be a product that is a line item but it can also be something else like the cost for delivery or a coupon and that way for example we only want to calculate and apply the VAT period if it's a product that is not let's say we don't want to have VAT for better than bags so we don't apply the rate for those we have already a field setup which is the field category on products so if it's a belt or a bag it's a term reference it just references a belt or a bag tag and we are going to leverage this field and check it with rules and only apply the VAT rate if the product is not a belt or bag okay let's head back to the component and add some conditions first off we'll add a data comparison condition as that you can check any kind of data with that so yeah this one and now we have the data select the way we can specify what data we want to check but we cannot directly access the product category because first off we only have the line item available so first off we need to check that the line item is actually a product line item because only then the system knows what kind of feeds those product line item has and exposes to the user so we check the line item type and make sure it actually is a product line item so we select line item type here and select that the product the line item is a product line item in this system as you can see we also have delivery line items once you've checked that rules knows that in that situation the line item will be a product line item and it will allow you to make use of the fields that are specific to product line items so we should have now a feed that references a product which is called commerce product define and if you see it now there's some new stuff and there's also the commerce product feed about references the product um but now when we look into the product we have the same situation again we see the general product properties but we cannot access the field of the product and this is as Dupal commerce has multiple product types and the default product type is just one of possible multiple ones as the system is prepared for multiple ones and Dupal commerce just has a default one so we again need to check whether it's the default product type and once we have done that we are able to access the fields as well so I guess that's the first important lesson lesson you have to learn that you're using rules that you often need to check the so-called entity bundle the product type or the node type in order to be able to access all that fields or you can also use that entity has field condition to do that and once we have done so we check here again whether the product type is the default product we should be able to use data comparison with all the fields that are in our default product so let's have a look at the data selector again and try to drill down to our product and to select the category and here it is now all the fields appear so we can select category and just choose to which term we want to compare the category and we have a data selector here as well but now we want to in we want to breed the like bags and bags we want to have the condition match if it's not a belt or a bag so we switch to input mode and now we can select the tag we want to compare it to but we want to have multiple ones we want to compare it so we use the comparison operation is one of instead of equals we change that and once we do so the form switches have to go back to input mode and now you can select multiple values and the condition will evaluate to do once the value is one in one of the multiple values so we just select bags and bag here and say negate so it will evaluate to do if it's not one of those and so far it's a good we have that set up and the text rate will only be applied if it's not a bag or belt but only if it's going to be a product and we might want to have the vat rate also to be applied to delivery line items so for that to work out we need to have a or first we say either if it's a delivery line item or it's a product which is not a bag or belt do it so we add the or then we add a condition to the or where we say okay if it's a delivery line item it's fine so we check again with data comparison condition the line item type and say if it's not a product please apply the vat rate so now we have that but we also need to move all the other conditions below the or before we do that we have to end them together so we create an end element and we can move the conditions below the end element so they ended together and save it so now we'll have it that way that the vat rate is applied if it's either not a product line item or it is a product line item which is not referencing a belt or bag that's it okay so you know actually quite a complex example to begin with um but it just shows that actually what you're trying to do there is um in a UK perspective anyway for a you know you don't want to charge vat on a book oh is it still going sorry yeah so this is just showing it now so it shows it's working yeah but I guess we can keep doing yep okay yeah so basically it allows us to to fix the use case where we've got different types of products with different vat rates and also shipping to different countries going to have different different taxes and that sort of thing so this is just going through showing you that it's working um we've got the rules evaluation log which if you're working with rules it's quite handy to switch on there we go yeah and Drupal Comma shows you whether the vat rate is applied when the other checkout so just put products in the checkout and you see on on the back there's no vat rate where on where some other product has been to this okay so we've got that that's video demo there we are um the the next scenario we came up with and again this is a real customer this is the sort of stuff that that we get put to us every day so they've decided to want to run some promotional discounts they want to do 10 off but only this week and only t-shirts and only on stuff that's been there for a year you know and they'll probably add a few more in there when it actually goes live um so we passed back over for the next demo um which we'll just show you how we can do that and i'll have to bend around back okay so only discount this week only t-shirts and only for products that have been there for more than one year uh Drupal Comma does all that price calculation already with rules so there are some so you see already there are some maybe maybe stop okay i'm not that fast sorry my apologies i've written the wrong i've loaded the wrong one so your live demo is just as good all right okay it's that Drupal Comma calculates already the price of a product using rules so there's an event which is called uh calculate the sale price of of line apps or products and it's fired each time and uh Drupal Comma shows a price and in its user interface it has already integrated some of the uif rules to configure that rules you see here those are the default calculation rules for for the price it also includes already the vat rate stuff here and we just add another rule here to say okay if all those conditions are met we want to apply a discount so we create that rule call it that way and start adding conditions to it and first off um we want to make sure that it only applies to t-shirts and we very much have the same situation again we need to be able to access the fields so we need to verify first that uh the actual thing we are working with here is a product line item and then the reference product in a product line item is the default product type of Drupal Comma so we know it's that thing that it's going to have all that fields so we do so and once you've done so the fields are available you can again use the data comparison to have a look at the category select t-shirts and it will only run for t-shirts okay that's the first term it only applies to t-shirts but now we also want to make sure that it only applies this week so let's do that again let's do use the data comparison and we can um what i'm doing here actually the graded date oh so well it's actually the the condition for making sure that the product is older than a year so we have been looking at the graded date of a product which is just accessible via the data comparison condition as well and we just compare it with the date of a year ago and if it's lower than that the date okay it's an old product let's apply this count then next point again data comparison we can as I said it's very mighty condition you can do a lot of stuff with that and now we use it to compare the current date and make sure it's just valid to this week so we just okay put in the date next monday i think it's 27th and if the date is below that so it's before next monday that the rule will apply and afterwards the condition will give false and it won't apply anymore okay so we all have a discount for that we actually need to apply the discount as well use an action duple commerce has some line item actions which allow you to um older the price so we just use those use the multiply the price unit of line item action to multiply it with 0.7 so it's only 70% of the original price so we have 30% off and we can select in duple commerce that we want to have difference shown as discount so the price component uh is just calculated that way that it calculates the new price calculates the difference and it will show it in a summary that the difference is actually your discount so once we apply it to a shirt that it's that old and that we want to have the discount applied to add it to the card all the the rules get evaluated and run and to check it i've enabled here that the rules evaluation log so you can have a look whether it actually worked that way you wanted to work and you you look for your rule and and have a look whether all the conditions have been evaluated and it fired and yeah all conditions are too it fired so the discount should have been applied so if you go for the checkout process again now you should see the separate price components and there it is you have the discount yeah that's it okay so again this shows you know you can manipulate the prices in many ways using rules and you can extend these conditions um for almost whatever obscure things your clients throw at you so we're going to push on here um so now following on the story of this client their promotion was brilliant it worked lovely but now they're out of stock and now they want us to send them an email or the customers to be sent an email when something's gone out of stock now this is something that yeah it's a brilliant feature on a on an e-commerce site um sometimes you have to plug in third party extensions to do this sometimes people have written modules to do this um but we figured you know what actually you can do this in rules as well so this one does require a few extra bits as well and so before we can start on the rule itself we have to uh we've done that the solution to this one involves the flag module which allows the customer to actually indicate that there's a product they're interested in so the customer can flag the the product to say email me when this is back in stock and then we have the back in stock rule which reacts to something changing on the commerce product and that's something would be the stock level going back up and as a result of that we can look at the people who've flagged that product go through them with the looping process in rules and send an email to them and then very importantly reset that flag so that they don't get another email five minutes later and so this is this is a really good example of how to use it you know what we're trying to do here is build in all these different elements of rules and show you how each of them are applying so this is a really good one of the scheduler and the loops functionality together we won't need the the scalar of this one but still we will go with the loops yeah so back in stock yeah is this one and I guess it also shows very well that you just plug in another module the flag module and you can leverage its functionality to build even more cool stuff with rules so on this site we we already have installed the flag module and we also have reconfigured a flag which is called just available and it's a flag on on product and it just has some link text notify me when a product is back in stock so users can actually see that and toggle that they want to get notified but for displaying the flag on your product display node but tuple combat uses for for showing you the product you actually have to do a little bit of custom tweaking because a field a flag is not a field and tuple combat only display the field of a product on the on the on the display node so you have to do that in your template preprocessor on that side display suite was already installed so I've just used this one and added it via a dynamic code filter just add in and the flag it just brings the flag that's it so if you go on a product and you have looked at it there's the flag if it's out of stock and you can just toggle it so we need to set up the notification rule and for that we get just go to the rules using the faith create a new rule notifications when products are back in stock we react when a commerce product changes to it so after updating an existing commerce product we react and then we need to verify whether the stock level really changed whether it has been out of stock previously and is back in stock now so we we have to start with the obligatory type check we use the data comparison to make sure that our product is the triple commerce default product so we can leverage the fields then we have a look at the unchanged product which is the product before the changes have been applied so it's the old product which should be out of stock so we make sure the stock is empty zero and then we use the same condition to check on the updated product whether it's greater than zero so we have some stock in there okay so far so good now we can use the actions to actually do the notification flag provides some useful actions we can use in rules so we can load all the the users that flag a rule but you can also unflag a flag a flag automatically so we started floating all the users that flagged the product and we get a new variable which we then can leverage the tools so now we have loaded all the maybe pulse it's too fast okay so we have now configured the action for loading all the users and we have them available available in rules but now to be able to leverage that we want to send an email to each of the users so we have to loop over the users now and then rules provide us with an invariable the current user the current state of the loop and you can configure an action to do something on that user so for that you use the loop you configure the loop to loop over the users the list of users and to provide the variable to currently use that's it so once you have done that you get the loop in the interface and you can add actions inside the loop and in this case we just want to see and send an email so you configure this send mail action and we configure it to send the email to the user so we select the current user's email address and for the subject and the message will of course can just input the text using some token replacement i've prepared some text for that so just copy that in and the same for the message you just input your text and use tokens as you are used to them so commerce product title is back in stock get it now the rest of the parameters probably can stay as default and that's it it will loop over it and send the emails but we also want to to reset the flag so we'll add another action for for resetting the flag for each user after he has got the notification so we press add action to add another action inside the loop and now we use the flag or unflag a commerce product action in this case select the flag we want unflag and we have to tell it for which user it should unflag the flag and that's it okay so we'll have a look whether it works the way it should work when i have a look at the product the flag is already flagged so toggle it okay notify me as you see the product has been marked as sold so it should be out of stock the stock field should be zero and once we edit it to be in stock the the rule should fire so we edit it go down to the stock field say we have five items in stock say another the rule should trigger and evaluate and send out the emails if you open the debug log you also see that it really happens so you see the files and it has executed the loop and actually also sent an email and on this side they've configured all email is just go to a certain um millenator address so we can open that and have a look where it's in there and it is as well as a previous test email yeah so tokens got replaced email has been sent the the rule has been evaluated so carrying on our story sorry i know these are going really really fast and there's a lot to take in there all going to be online later they've all got a good voice over with them so uh yeah i hope you're keeping up so far um so next part of the story um again taking the evolution of a typical customer that is a small business obviously um it's working really well now i've had to hire someone to load on stock but i want to make sure that i review the copy and i review the images before these things go on on to the site so this is when we start talking about workflow moderation that sort of thing and so it becomes slightly less commerce and more mainstream maybe and so we're going to show you a quick rule on this one on how to use work the workbench um module with rules so what we're interested in here is the event that gets triggered when an item moves between two different states of the workflow and then we want an action that happens to send an email or a notification of some sort to the site owner to say there's new content ready for you to review okay this one is pretty easy actually because workbench module does all the hard work and we just get an event we need to react up so first of you have to install the workbench module and once it's installed you see there are so many tabs a few published few draft and you can create a new draft so we do so to create a new draft on our site just change something save it and it will be saved as a new draft and it won't be automatically published if you go below we see here that there's the current state of the draft is that it's in draft mode and once you put it you need to review i want to put up a notification so that i know that when my worker has finished it you can set it to need to review and again a notification can have a logo there so we set up the rule for that which just says whenever the man has put the note into need to review state send me an email so you can see at the workbench overview these are the states we have need to refuse one of those so we just copy over the machine name use the data comparison condition and there's also a variable now which says that's the new state and we also have the previous state available we just compare the value of it and you have to compare it with the machine name so i just copy it over and paste it actually would be nice if workbench module would provide a select on for that but yeah fine an issue and once you've done that just use the regular actions send an email use the token replacements as always it's very much the same exactly as you could do it for when someone posts a comment to your blog send you a notification so that's it but let's try it so when you put it draft and put it into needs review the rule should run if you look at the evaluation log there's a lot of stuff that triple commerce runs by default but there's somewhere also our rule should be here it is the event after moderation transition has been triggered and our rule has been executed and fired so let's have a look at the address again and see where there's actually an email and here it is I said pretty straightforward okay well i can't have simple let's move on to something more complicated again so the next one actually is again as the as the shop grows the customer has more and more products on there and they want to be able to process lots of products at once so the next scenario that came up for us was um how do I process loads of orders quickly or loads of products quickly um and so this one is a this is the views by corporations yeah we're going to use the views by corporations module for that and just preconfigure a rule component which we use for marking products for sale or unmarking products for sale and once you have a shop with lots of products and then you really don't want to edit each of the products to do that so let's build a good interface for that first off let's have a look at the product we have already a field for that that marks a product to be for sale the sales item field and also the product overview in triple commerce is already built with a few so we can easily add few spark operations to that but first off let's prepare the component we wanted to execute on each of the products for that we are going to use a rule so that we also can evaluate some conditions before we use the actions as we are going to need this for checking the product types as usual and as input for the component we have to specify some variables the variables that the component works with and as this is a field that lists product and each of the rows resembles a product you have to configure a product as input parameter here and once we do so we have it available in a data comparison as you see it here check the type make sure it's the default product so we can make use of all the fields and just execute an action to set the data value of a field select the product sales items it should be set to yes save it and we also want to check configure access for using this component for permission what allows modules to skip rules permission check and just say okay I want to expose that action to any site builder or site owner what's very useful for doing few spark operations with different kind of permissions level okay then we better clone the component and do the same for unmarking so we have two operations we can run mark the product for sale and unmarking it and we can just clone it and the only thing we need to change is the set a day value action and say oh set the value to no plate okay now we have got two components and let's configure a few spark operations so that it's going to make use of those two components we have to add the few spark operations field here um so for commerce products we are adding the bulk operations they got moved to a new group I think bulk operations so or they were previously there so they found them and now you can configure these bulk operations here and you just check which kind of operations you want to expose and all compatibility rules components will automatically appear here so you just check those and also rearrange it as few spark operations will render the checkbox we want to have that in front of all the other fields so we move it to the top reload the few and it's already here we have the checkboxes and we can execute operations on it so just run run it on the free products confirm and the rules have been evaluated you can check that the the backlog is over there also we can if we look at the product to see whether it's really changed so if we scroll down we should see that the sale item is no mark yes so it's for sale okay right we've got two more and we've just about got time um so we talk about promotion the promotion that we did earlier they want to make it slightly more complicated now um they want to end the promotion when they've sold 100 items and we want to end the promotion so it finishes on a certain day of the week so I don't have to remember to be up at midnight to stop the promotion um so we want to auto unpublish the offer on Tuesday and auto republish it on Monday for example okay so that's pretty similar like the regular discount so we can apply a discount rule once we have marked a product for sale but in addition to that we need some kind of scheduling so we use the rule scalar module for that and we create two components one for activation the activating the promotion and one for disabling the promotion and we will schedule the evaluation of those components so it's happening automatically we don't have to care about that okay let's do so yeah you must be talking about this one I guess I'm I'm explaining it to you okay we have already set up a display note here which says it's dedicated for the promotion and we also want to publish and unpublish this display note automatically together with setting the product for sale and this is the discount rule which I've already prepared it just applies um 30% discount if the product is marked to be for sale so once the product is marked for sale the price will be automatically reduced but let's do the components for activating and disabling the promotion so we again use a rule plugin for the component and just say activate the promotion just call it promotion a tag it so that we can find it again afterwards and as we are dealing with the display note we use the notice parameter so we know which note we want to automatically publish and unpublish and also the note has a reference to the product so we can find the product we want marked for sale as well by the note so it suffices to just have that as a parameter then we add conditions to it first off again we check the content type so we can make use of all the fields of the note so we check the content type to make sure it's actually a product display note and then we use the data comparison and also check the product type so now we can make use of all the fields of the product in order to be able to access the sales item fields so now we can use data comparison to make sure the product is for sale oh no we don't need to make sure it's for sale we just need to we want to set it for sale sure so we we automatically set the product to be on sale so we use the condition to make sure it's a default product and then we have the to feel available and we can set it then let's clone the condition the component to make another one for disabling the promotion so we just clone the other one and rename it then we configure it to set the sales item field to know so the product is not on sale anymore but in addition to that we want to once the promotion has ended we want to schedule that it starts again next Monday and we want to unpublish the content so the display note disappears automatically okay let's do the scheduling but that we have the action of the rules scalar module it expose an action which just says uh evaluate schedule the evaluation of any rules component we configure it to use activate promotion r a and automatically configure it uh at the current date so this is the date when the component runs and adds six days to that so it will run when it's executed and used to midnight it will run six days afterwards it will run at Monday midnight automatically and when you're scheduling that you can put up some identifiers so that you can identify your scheduled tasks and once you schedule multiple tasks with your rules it can be very handy as it enforces that there is always only one uh task with the same identifier so if you scale the task multiple times for the for the same node identifier it will be just a place and yeah then we also say okay pass on the node and then we have to do exactly the same for another component so when they activate promotion component runs we want to schedule that it automatically ends on on Tuesday midnight so we again use the same action but we say okay please run a day after me we also pass on the node configure the identifier and that's it now when this all starts it will automatically loop and it will always scalar it for Tuesday night Monday night Tuesday night Monday night Tuesday night and so on forever but we need to to start the whole process and if you also want you might want to to stop it so for starting it you can manually uh schedule the component once where the schedule link here so you can just say when it should be scheduled input the date let's start it next Monday midnight also we enter the identifier on our node ID so let's just look up the the node ID of our dispar node schedule it and also pass the node's argument okay so now we should have a task in the interface where you see okay it's scheduled for Monday midnight and via gone it will be evaluated automatically at this date yes so far that's it okay great so i'm just very conscious time we've got one more actually that well um we also have um a video where we can see how we can test that but i guess we we could move probably have to skip that and we'll put that one up online and we've got say a few minutes left but the one that we'll say for the end is just one i've felt was so powerful so i'm going to shut up and just get on with it and when one of the things that that we often get asked to do is is abandon carts so customers you know however many percentages of customers on your site actually start an order put items in the basket never finish it and and it's really useful in in e-commerce conversion to be able to get in touch with those people and find out did they forget to come back is there a reason and just contact those customers so again this should be something that's third party it should be something that's a another module maybe but there is a way to do it in rules as you'll see is a common theme here um so i'm going to quickly how long is this one just that interest yeah it's pretty long we've got 10 minutes left and i'm going to run that quite fast all right just so we've got a bit of time so a couple of questions i guess the important thing here you should know up on here is that triple commerce uses orders to to track how far the user has gone in the ordering process so as soon as the customer puts a product into the cart it automatically creates an order and keeps track of what you're doing in that order and you can react up in this with rules as there will be an event after the order has been updated and before each time that the order changes so each time someone adds it to the cart it will change and we can react up in that and we react up in that to schedule that the day after that we want to have a look and see whether the user can be completed the order and that's the way it works so we create a component which receives the order we and then we'll schedule this component to an automatically let's say three days after the order has been graded so when the user actually has started adding something to its shopping bag or cart so we have the the order states here triple commerce uses them to to see in what kind of state the order already is and we want to make sure that this all only runs when the order is still in shopping pattern or kept in the checkout process if it's completed with kibbet and if not we send the user an email and say hey you have an abandoned cart maybe you want to go back to the site and continue ordering and complete the order yeah whatever okay save that that's the email that the user will get okay that's that's all everything we need to do now we just need to schedule that and for that we set up an reaction rule which automatically schedules that as soon as the order is put in the right state so we use the event after updating an existing commerce order here and check in which state the order is so if it's in a cart state or if it's in a checkout state we schedule the rule for evaluation later on so for that we use the data comparison condition to check the order state and we also want to make sure that it all only runs for the current user so when when the admin goes into that and has a look at the order and changes something we don't want that all to be scheduled so we make sure that this only runs when the current site user is really the user that owns the order so we checked it as well okay so make sure it's in cart or shopping bag or checkout state and as action we just schedule the component to run three days later on so we use the evaluate schedule evaluation of components action of the rule scalar module configure the schedule evaluation date to be three days later on we also add an identifier to make the scalar task unique in this case we'll actually see why that can be useful because we can use the identifier to abort the scalar task so in this case we can use it if users continue shopping and to complete the order that we even don't run the task three days later on it would be no problem if we would run then if in the task later on we also check whether the order is still in the shopping cart or checkout state but it's well it's still better to don't run them at all so if the user completes the order we just delete the task and it will never be executed so for that set up another rule as it's pretty similar we just clone the existing rule rename it yeah then we change the data comparisons or attracts if the order is in a different state so we negate that and instead of scheduling the component evaluation there's an action which allows you to delete the schedule task so we use that one and we actually delete the scalar tasks for those orders so as identifier we have to put in the order ID as we used it to scale the task so we put in the same identifier save it and it will automatically delete this task yeah so far so good let's have a test so edit something to the shopping bag so now we have an order and we should have a task for the order to come back three days later on to see whether the user has completed the order and once you check out and complete the order you should see that the task goes away you don't need to check anymore so let's try that set up fset up an example payment here so I don't have to pay anything continue order is completed so the task should be deleted it's gone okay yeah we really are out of time sorry um so there was a load to cram in there and we did have a couple more but we're going to have to stop um we can probably looking at people outside cram in a couple of questions if anyone has any otherwise by all means come and find us later we're here all week yeah any questions okay um we'll also put up a page where all the screencasts are available and so you can have a look at those afterwards we'll put up it at the session page today thanks for it and Cymru yn mynd i'r llunio'r pethau sydd o'n ddweud yma. Mae'r llunio'r ddweud i'r ddweud yn ddweud i'r ddweud i'r ddweud, ac mae'r ddweud i'r ddweud i'r ddweud i'r ddweud i'r ddweud i'r ddweud.