How to create custom behavior events
Using this feature, you can add your own ways for customers to earn points.
- To create a new Custom Behavior Rule, go to Marketing -> Promotions -> Reward Points -> Settings -> Advanced Settings.
- In the Custom Behavior Events field, add a new rule in this format: rulecode, rulename. You can add more rules, each on a new line.
- Insert the following code in the place where points should be charged:
$eventManager = $this->_objectManager->get('Magento\Framework\Event\ManagerInterface');
$eventManager->dispatch('mirasvit_rewards_behavior_rule_process', ['code' => 'rulecode', 'attr' => attribute]);
Example
For example, to create a rule for the event 'user name changed,' insert the following in the Custom Behavior Events field:
customer_change_name, Change customer name rule
Then, insert the following code:
$eventManager = $this->_objectManager->get('Magento\Framework\Event\ManagerInterface');
$eventManager->dispatch('mirasvit_rewards_behavior_rule_process', ['code' => 'customer_change_name', 'attr' => $customer->getName()]);
Note
The variable $customer should be defined