Ejemplo n.º 1
0
 /**
  * Добавить правило скидки
  * @param discountRule $discountRule правило скидки
  */
 public function appendDiscountRule(discountRule $discountRule)
 {
     foreach ($this->rules as $rule) {
         if ($rule->getId() == $discountRule->getId()) {
             return;
         }
     }
     $this->rules[] = $discountRule;
     $value = array();
     foreach ($this->rules as $rule) {
         $value[] = $rule->getId();
     }
     $this->object->discount_rules_id = $value;
     $this->commit();
 }
 public function getRules($discountTypeId = false, $discountId = false)
 {
     $items = discountRule::getList($discountTypeId);
     if ($discountId) {
         $discount = discount::get($discountId);
         $discountRules = $discount->getDiscountRules();
         $discountRulesId = array();
         foreach ($discountRules as $rule) {
             $discountRulesId[] = $rule->getObject()->rule_type_id;
         }
         foreach ($items as $i => $rule) {
             $items[$i] = array('attribute:id' => $rule->id, 'attribute:name' => $rule->name);
             if (in_array($rule->id, $discountRulesId)) {
                 $items[$i]['attribute:selected'] = 'selected';
             }
         }
     }
     return array('items' => array('nodes:item' => $items));
 }