Пример #1
0
 /**
  * remove all items
  */
 public function actionClearAll()
 {
     $shoppingCartModel = new ShoppingCart();
     if ($shoppingCartModel->clearAll()) {
         echo Json::encode(['message' => 'remove success', 'redirect' => 'index']);
     } else {
         echo Json::encode(['message' => 'remove fail', 'redirect' => 'index']);
     }
 }
Пример #2
0
 /**
  * remove all items
  */
 public function actionClearAll()
 {
     $shoppingCartModel = Yii::createObject(ShoppingCart::className());
     if ($shoppingCartModel->clearAll()) {
         echo Json::encode(['message' => \Yii::t('cart', 'remove success'), 'redirect' => 'index']);
     } else {
         echo Json::encode(['message' => \Yii::t('cart', 'remove fail'), 'redirect' => 'index']);
     }
 }
Пример #3
0
 /**
  * checkout view
  * @author cangzhou.wu(wucangzhou@gmail.com)
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionCheckout()
 {
     $star_id = (int) Yii::$app->request->get('star_id');
     $shoppingCart = Yii::createObject(ShoppingCart::className());
     $cartItems = $shoppingCart->cartItems;
     if ($star_id) {
         $cartItems = $shoppingCart->serialCartItems();
         if (isset($cartItems[$star_id])) {
             $cartItems = $cartItems[$star_id];
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     return $this->render('index', ['cartItems' => $cartItems]);
 }