Example #1
0
 public function add($data)
 {
     $item = new CartOrderItems();
     $item->setAttributes($data);
     if ($item->validate()) {
         foreach ($this->items as $it) {
             if ($it->item_id == $item->item_id && $it->relation == $item->relation) {
                 $it->count += $item->count;
                 return true;
             }
         }
         $this->items[] = $item;
         return true;
     }
     return false;
 }
Example #2
0
 public function getSum()
 {
     return CartOrderItems::find()->where(['order_id' => $this->id])->sum('price*count');
 }