Пример #1
0
 public function build($data)
 {
     $this->data = $data;
     $promotion = new Promotion($data['name']);
     if ($data['has_code']) {
         $this->activators['code']->code($data['submitted_code'])->usageLimitPerCode($data['usage_limit_per_code'])->usageLimitPerUser($data['usage_limit_per_user']);
     }
     $this->activators['date_range']->start($data['start'])->end($data['end']);
     $promotion->setActivators($this->activators);
     $rules = array();
     foreach ($data['rules'] as $index => $rule) {
         $name = $rule['component_name'];
         $current = clone $this->rules[$name]['object'];
         $current->initialize($rule['operator'], $rule['value']);
         $rules[] = $current;
     }
     $promotion->setRules($rules);
     $actions = array();
     foreach ($data['actions'] as $index => $action) {
         $name = $action['component_name'];
         $current = clone $this->actions[$name]['object'];
         // Quite hacky, because all actions are stored in the same table
         // the argument column has type ambiguity.
         $current->initialize(intval($action['argument']));
         $actions[] = $current;
     }
     $promotion->setActions($actions);
     return $promotion;
 }
Пример #2
0
 public function testSettingActivators()
 {
     $promotion = new Promotion('Lala');
     $codeActivator = new CodeActivator();
     $codeActivator->code('XYZ');
     $promotion->setActivators(array($codeActivator));
     $this->assertFalse($promotion->isEligible(new TestPromotionSubject()));
 }