<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mothership-ec / cog-mothership-refer-a-friend example snippets
public function createReward(SomeEvent $event)
{
$referrals = $this->get('refer.referral.loader')->getByEmail($event->getEmail());
// Return if no referrals were loaded
if (empty($referrals)) {
return;
}
foreach ($referrals as $referral) {
// Continue if trigger does not apply to event
if (false === $referral->hasTriggered('event.name')) {
continue;
}
// code to create reward
}
}
public function createReward(SomeEvent $event)
{
$referrals = $this->get('refer.referral.loader')->getByEmail($event->getEmail());
// Return if no referrals were loaded
if (empty($referrals)) {
return;
}
foreach ($referrals as $referral) {
// Continue if trigger does not apply to event
if (false === $referral->hasTriggered('event.name')) {
continue;
}
// Default to $valid being true, loop through constraints and validate
$valid = true;
foreach ($referral->getRewardConfig()->getConstraints() as $constraint) {
// Break out of loop if referral is not valid, and set $valid to false
if (false === $constraint->isValid($$referral, $event)) {
$valid = false;
break;
}
}
// Move on to next referral if invalid
if (false === $valid) {
continue;
}
// code to create reward
}
}