Esempio n. 1
0
 public static function editField($id, $value, $productId)
 {
     $stock = Stock::findOne($id);
     if ($productAmount = $stock->getProducts()->where(['product_id' => $productId, 'stock_id' => $id])->one()) {
         $productAmount->amount = $value;
         $productAmount->save();
     } else {
         $productAmount = new StockToProduct();
         $productAmount->amount = $value;
         $productAmount->product_id = $productId;
         $productAmount->stock_id = $id;
         $productAmount->save();
     }
 }
Esempio n. 2
0
 public function minusAmountInStock($stock, $count)
 {
     if ($profuctInStock = StockToProduct::find()->where(['product_id' => $this->id, 'stock_id' => $stock])->one()) {
         if ($profuctInStock->amount >= $count) {
             $profuctInStock->amount = $profuctInStock->amount - $count;
         } else {
             return 'На складе всего ' . $profuctInStock->amount . ' единиц товара. Пытались снять ' . $count;
         }
     } else {
         return 'На складе нету такого товара. Пытались снять ' . $count;
     }
     return $profuctInStock->save();
 }