Example #1
0
 public function actionRemoveFromCart()
 {
     $result = 0;
     $product_id = Yii::$app->request->post('product_id');
     $quantity = Yii::$app->request->post('quantity', true);
     if ($product = Product::findOne(['id' => $product_id, 'is_active' => 1])) {
         Yii::$app->session->get('cart')->remove($product, $quantity);
         $result = Yii::$app->session->get('cart')->totalValue();
         $result = I18n::currency($result);
     }
     return $result;
 }
Example #2
0
 public function actionDetail()
 {
     $slug = Yii::$app->request->get('slug');
     if ($product = Product::findOne(['slug' => $slug, 'is_active' => 1])) {
         $this->link_canonical = $product->getLink();
         if (!Redirect::compareUrl($this->link_canonical)) {
             $this->redirect($this->link_canonical);
         }
         $product_images = ProductImage::find()->where(['product_id' => $product->id])->all();
         if ($this->is_mobile && !$this->is_tablet) {
             $product_image_suffix = ProductImage::$image_resizes['mobile'];
         } else {
             if ($this->is_tablet) {
                 $product_image_suffix = ProductImage::$image_resizes['tablet'];
             } else {
                 $product_image_suffix = ProductImage::$image_resizes['desktop'];
             }
         }
         return $this->render('detail', ['product' => $product, 'product_images' => $product_images, 'product_image_suffix' => $product_image_suffix]);
     } else {
         Redirect::go();
     }
 }
Example #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.');
     }
 }