Example #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();
     }
 }
Example #2
0
 public function getStock($id)
 {
     return StockModel::findOne($id);
 }
Example #3
0
 /**
  * Finds the Stock model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Stock the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Stock::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }