Exemple #1
0
 public function actionLanding()
 {
     $packages = Package::find()->where(['enable' => 1])->limit(4)->orderBy('position')->all();
     $toppups = Topup::find()->where(['enable' => 1])->limit(4)->orderBy('position')->all();
     $this->layout = 'unify/front_page';
     $temp = new HybrizyCartForm();
     $session = Yii::$app->user->isGuest ? $temp->loadSession('Hybrizy') : $temp->loadFromTable();
     if ($session == false) {
         $cart = ['totalCount' => 0];
     } else {
         $cart = $session;
     }
     return $this->render('landing', ['packages' => $packages, 'toppups' => $toppups, 'cart' => $cart]);
 }
Exemple #2
0
 public function actionRemovePackage($id, $modelClass, $quantity = 1)
 {
     $cart = new HybrizyCartForm();
     $cartItems = $cart->loadSession('Hybrizy');
     //        $cartItems = $cart->getResult();
     $itemId = $modelClass . '-' . $id;
     if (array_key_exists($itemId, $cartItems['data'])) {
         $item = $cartItems['data'][$itemId];
         $price = $cartItems['data'][$itemId]['price'];
         if ($item['count'] == 1) {
             $cartItems['totalCount'] = $cartItems['totalCount'] - 1;
             unset($cartItems['data'][$itemId]);
         } else {
             $item['count'] = $item['count'] - 1;
             $cartItems['data'][$itemId] = $item;
             $cartItems['totalCount'] = $cartItems['totalCount'] - 1;
         }
         if ($cartItems['grandTotal'] > 0) {
             $cartItems['grandTotal'] = $cartItems['grandTotal'] - $price;
         }
         if ($cartItems['grandTotal'] == 0 && count($cartItems['data']) == 0) {
             $cart->resetSession();
             if (!\Yii::$app->user->isGuest) {
                 $cart->resetUserDb();
             }
             $output = \Yii::$app->controller->renderPartial('@frontend/views/site/_cart_list', ['items' => ['totalCount' => 0]], true);
             return ['html' => $output, 'grandTotal' => 0, 'subTotal' => 0];
         }
     }
     $cart->cart = $cartItems;
     $cart->saveSession();
     if (!\Yii::$app->user->isGuest) {
         $cart->saveTodb();
     }
     $cartArray = $cart->getResult();
     $output = \Yii::$app->controller->renderPartial('@frontend/views/site/_cart_list', ['items' => $cartArray], true);
     return ['html' => $output, 'totalCount' => $cartArray['totalCount']];
 }