Exemplo n.º 1
0
 /**
  * Display a product
  * 		- Detail info of a product
  * 		- Related products
  * @param string $product_id
  */
 public function actionProduct($product_id = null)
 {
     $product = Product::findOne($product_id);
     if (!$product) {
         throw new HttpException(404, Yii::t('shop', "The requested product not found!"));
     }
     // TODO: Calculate related products
     $this->render('product', ['product' => $product]);
 }
Exemplo n.º 2
0
 /**
  * Add a product into the Cart
  * @param integer $id The product ID
  * @throws NotFoundHttpException
  * @return \yii\web\Response
  */
 public function actionAdd($id, $quantity = 1)
 {
     $model = Product::findOne($id);
     if ($model) {
         Yii::$app->cart->put($model, $quantity);
         Yii::$app->session->addFlash('success', "Successfully update your cart!");
         return $this->redirect(Yii::$app->user->returnUrl ? Yii::$app->user->returnUrl : ['view']);
     }
     throw new NotFoundHttpException();
 }
Exemplo n.º 3
0
 /**
  * Finds the Product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }