Ejemplo n.º 1
0
 public function save($validate = true)
 {
     if ($validate && !$this->validate()) {
         return false;
     }
     foreach ($this->prices as $ct_id => $value) {
         $model = Price::findOne(['product_id' => $this->id, 'price_category_id' => $ct_id]);
         $model = $model ?: new Price(['product_id' => $this->id, 'price_category_id' => $ct_id]);
         $model->price = $value;
         if (!$model->save()) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Finds the Price model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $product_id
  * @param integer $price_category_id
  * @return Price the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($product_id, $price_category_id)
 {
     if (($model = Price::findOne(['product_id' => $product_id, 'price_category_id' => $price_category_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }