Exemplo n.º 1
0
/**
 * @param unknown_type $message
 * @param Db $db
 * @return void|boolean
 */
function processMessage($message, $db)
{
    //$message = Tools::jsonDecode('{"id_event":5,"date_event":"2012-03-14 13:07:18","reference":"274","id_customer":"10687"}', true);
    //$message = Tools::jsonDecode($response->body->ReceiveMessageResult->Message->Body, true);
    $message = Tools::jsonDecode($message, true);
    $id_event = $message['id_event'];
    if ($id_event == ONLINE_ORDER) {
        VBRewards::addRewardPoints($message['id_customer'], $id_event, 0, 100, 'Online payment bonus - Order no ' . $message['reference'], $message['reference'], $message['date_event']);
        return;
    }
    if ($id_event == EVENT_REGISTRATION) {
        VBRewards::addRewardPoints($message['id_customer'], $id_event, 0, 50, 'Registration/Sign-up', $message['reference'], $message['date_event']);
        return;
    }
    if (isset($message['first_order']) && $message['first_order']) {
        VBRewards::addRewardPoints($message['id_customer'], $id_event, 7, 50, 'First Order Bonus - Order no ' . $message['reference'], $message['reference'], $message['date_event']);
        return;
    }
    if (isset($message['first_review']) && $message['first_review']) {
        VBRewards::addRewardPoints($message['id_customer'], $id_event, 9, 50, 'Product Review - First review bonus', $message['reference'], $message['date_event']);
        return;
    }
    $res = $db->ExecuteS("select le.id_event, le.name as 'event_name', r.id_rule, r.name as 'rule_name', re.execute_sequence\n\t\t\t\t\t\t\tfrom vb_rules r\n\t\t\t\t\t\t\tinner join vb_loyalty_rule_events re on (r.id_rule = re.id_rule)\n\t\t\t\t\t\t\tinner join vb_loyalty_events le on le.id_event = re.id_event\n\t\t\t\t\t\t\twhere le.id_event = " . $message['id_event'] . " order by le.id_event, re.execute_sequence");
    foreach ($res as $rule_row) {
        if ($rule_row['id_rule'] == 9 || $rule_row['id_rule'] == 7) {
            continue;
        }
        $rewards_rule = RewardRules::getRule($rule_row['rule_name']);
        $rewards_rule->init($db);
        $rewards_rule->processEvent($db, $message);
        echo PHP_EOL;
    }
    return false;
}
Exemplo n.º 2
0
 public function processEvent($db, $message)
 {
     echo "processing order_cancelled";
     $id_customer = $message['id_customer'];
     $id_event = $message['id_event'];
     $date_add = $message['date_event'];
     $order = new Order((int) $message['reference']);
     //remove ordervalue reward
     $valid_order_rule = RewardRules::getRule('valid_order');
     $valid_order_rule->init($db);
     $valid_order_rule->processCancel($db, $message);
     //remove ordervalue reward
     $first_order_bonus_rule = RewardRules::getRule('first_order_bonus');
     $first_order_bonus_rule->init($db);
     $first_order_bonus_rule->processCancel($db, $message);
     //remove ordervalue reward
     $order_value_bonus_rule = RewardRules::getRule('order_value_bonus');
     $order_value_bonus_rule->init($db);
     $order_value_bonus_rule->processCancel($db, $message);
     //remove ordervalue reward
     $referral_order_points_rule = RewardRules::getRule('referral_order_points');
     $referral_order_points_rule->init($db);
     $referral_order_points_rule->processCancel($db, $message);
     //remove ordervalue reward
     $referral_order_bonus_rule = RewardRules::getRule('referral_order_bonus');
     $referral_order_bonus_rule->init($db);
     $referral_order_bonus_rule->processCancel($db, $message);
 }
Exemplo n.º 3
0
function processMessage($response, $db)
{
    echo $response->body->ReceiveMessageResult->Message->Body . PHP_EOL;
    //$message = Tools::jsonDecode('{"id_event":5,"date_event":"2012-03-14 13:07:18","reference":"274","id_customer":"10687"}', true);
    $message = Tools::jsonDecode($response->body->ReceiveMessageResult->Message->Body, true);
    $id_event = $message['id_event'];
    $res = $db->ExecuteS("select le.id_event, le.name as 'event_name', r.id_rule, r.name as 'rule_name', re.execute_sequence\n\t\t\t\t\t\t\tfrom vb_rules r\n\t\t\t\t\t\t\tinner join vb_loyalty_rule_events re on (r.id_rule = re.id_rule)\n\t\t\t\t\t\t\tinner join vb_loyalty_events le on le.id_event = re.id_event\n\t\t\t\t\t\t\twhere le.id_event = " . $message['id_event'] . " order by le.id_event, re.execute_sequence");
    foreach ($res as $rule_row) {
        $rewards_rule = RewardRules::getRule($rule_row['rule_name']);
        $rewards_rule->init($db);
        $rewards_rule->processEvent($db, $message);
        echo PHP_EOL;
    }
    return true;
}