public function actionShow()
    {
        $this->registerStaticSeoData();
        $cart = \Yii::$app->cart;
        $items = $cart->getOrderItems();

        /*EMPTY CART*/
        if (empty($items)) {
            return $this->render('empty-cart');
        }
        /*CART IS NOT EMPTY*/
        else {
            /*FOR GUEST*/
            if (\Yii::$app->user->isGuest) {
                $user = new User();
                $profile = new Profile();
                $address = new UserAddress();
                $order = new Order();

                $products = [];
                $orderProductViewModels = [];
                foreach ($items as $item) {
                    $product = Product::findOne($item['id']);
                    if (!empty($product)) {
                        $product->count = $item['count'];
                        $product->combinationId = $item['combinationId'];
                        if (!empty($item['additionalProducts'])) {
                            foreach ($item['additionalProducts'] as $additionalProduct) {
                                $product->additionalProducts[] = [
                                    'product' => Product::findOne($additionalProduct['productId']),
                                    'number' => $additionalProduct['number']
                                ];
                            }
                        }
                        $products[] = $product;
                        $orderProductViewModels[] = new OrderProductViewModel([
                            'product_id' => $item['id'],
                            'combination_id' => $item['combinationId'],
                            'count' => $item['count'],
                        ]);
                    }
                }
                $view = 'show-for-guest';
            }
            /*FOR USER*/
            else {
                $user = User::findOne(\Yii::$app->user->id) ?? new User();
                $profile = Profile::find()->where(['user_id' => \Yii::$app->user->id])->one() ?? new Profile();
                $address = new UserAddress();
                $order = Order::find()
                        ->where(['user_id' => \Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
                        ->one() ?? new Order();
                $products = OrderProduct::find()->where(['order_id' => $order->id])->all();
                $orderProductViewModels = $products;
                $view = 'show';
            }
            return $this->render($view, [
                'products' => $products,
                'order' => $order,
                'profile' => $profile,
                'user' => $user,
                'address' => $address,
                'orderProductViewModels' => $orderProductViewModels
            ]);
        }
    }
public function actionShow()
    {
        $this->registerStaticSeoData();
        $cart = \Yii::$app->cart;
        $items = $cart->getOrderItems();

        /*EMPTY CART*/
        if (empty($items)) {
            return $this->render('empty-cart');
        }
        /*CART IS NOT EMPTY*/
        else {
            /*FOR GUEST*/
            if (\Yii::$app->user->isGuest) {
                $user = new User();
                $profile = new Profile();
                $address = new UserAddress();
                $order = new Order();

                $products = [];
                $orderProductViewModels = [];
                foreach ($items as $item) {
                    $product = Product::findOne($item['id']);
                    if (!empty($product)) {
                        $product->count = $item['count'];
                        $product->combinationId = $item['combinationId'];
                        if (!empty($item['additionalProducts'])) {
                            foreach ($item['additionalProducts'] as $additionalProduct) {
                                $product->additionalProducts[] = [
                                    'product' => Product::findOne($additionalProduct['productId']),
                                    'number' => $additionalProduct['number']
                                ];
                            }
                        }
                        $products[] = $product;
                        $orderProductViewModels[] = new OrderProductViewModel([
                            'product_id' => $item['id'],
                            'combination_id' => $item['combinationId'],
                            'count' => $item['count'],
                        ]);
                    }
                }
                $view = 'show-for-guest';
            }
            /*FOR USER*/
            else {
                $user = User::findOne(\Yii::$app->user->id) ?? new User();
                $profile = Profile::find()->where(['user_id' => \Yii::$app->user->id])->one() ?? new Profile();
                $address = new UserAddress();
                $order = Order::find()
                        ->where(['user_id' => \Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
                        ->one() ?? new Order();
                $products = OrderProduct::find()->where(['order_id' => $order->id])->all();
                $orderProductViewModels = $products;
                $view = 'show';
            }
            return $this->render($view, [
                'products' => $products,
                'order' => $order,
                'profile' => $profile,
                'user' => $user,
                'address' => $address,
                'orderProductViewModels' => $orderProductViewModels
            ]);
        }
    }
public function actionShow ( ) { $ this -> registerStaticSeoData ( ) ; $ cart = \ Yii :: $ app -> cart ; $ items = $ cart -> getOrderItems ( ) ; /*EMPTY CART*/ if ( empty ( $ items ) ) { return $ this -> render ( 'empty-cart' ) ; } /*CART IS NOT EMPTY*/ else { /*FOR GUEST*/ if ( \ Yii :: $ app -> user -> isGuest ) { $ user = new User ( ) ; $ profile = new Profile ( ) ; $ address = new UserAddress ( ) ; $ order = new Order ( ) ; $ products = [ ] ; $ orderProductViewModels = [ ] ; foreach ( $ items as $ item ) { $ product = Product :: findOne ( $ item [ 'id' ] ) ; if ( ! empty ( $ product ) ) { $ product -> count = $ item [ 'count' ] ; $ product -> combinationId = $ item [ 'combinationId' ] ; if ( ! empty ( $ item [ 'additionalProducts' ] ) ) { foreach ( $ item [ 'additionalProducts' ] as $ additionalProduct ) { $ product -> additionalProducts [ ] = [ 'product' => Product :: findOne ( $ additionalProduct [ 'productId' ] ) , 'number' => $ additionalProduct [ 'number' ] ] ; } } $ products [ ] = $ product ; $ orderProductViewModels [ ] = new OrderProductViewModel ( [ 'product_id' => $ item [ 'id' ] , 'combination_id' => $ item [ 'combinationId' ] , 'count' => $ item [ 'count' ] , ] ) ; } } $ view = 'show-for-guest' ; } /*FOR USER*/ else { $ user = User :: findOne ( \ Yii :: $ app -> user -> id ) ?? new User ( ) ; $ profile = Profile :: find ( ) -> where ( [ 'user_id' => \ Yii :: $ app -> user -> id ] ) -> one ( ) ?? new Profile ( ) ; $ address = new UserAddress ( ) ; $ order = Order :: find ( ) -> where ( [ 'user_id' => \ Yii :: $ app -> user -> id , 'status' => OrderStatus :: STATUS_INCOMPLETE ] ) -> one ( ) ?? new Order ( ) ; $ products = OrderProduct :: find ( ) -> where ( [ 'order_id' => $ order -> id ] ) -> all ( ) ; $ orderProductViewModels = $ products ; $ view = 'show' ; } return $ this -> render ( $ view , [ 'products' => $ products , 'order' => $ order , 'profile' => $ profile , 'user' => $ user , 'address' => $ address , 'orderProductViewModels' => $ orderProductViewModels ] ) ; } }
Renders cart view with all order products.
@return mixed
Renders cart view with all order products .