public function getCost() {
        $totalCost = 0;
        if (Yii::$app->user->isGuest) {
            //Gets products from session
            $session = Yii::$app->session;
            $products = $session[self::SESSION_KEY];

            if (!empty($products)) {
                foreach ($products as $product) {

                    if (!empty($product['combinationId'])) {
                        $combination = Combination::findOne($product['combinationId']);
                        if (!empty($combination)) $totalCost += $combination->price->discountPriceFloor * $product['count'];
                    } else {
                        $productFromDb = Product::findOne($product['id']);
                        if (!empty($productFromDb))
                            $totalCost += $productFromDb->price->discountPriceFloor * $product['count'];
                    }

                    if (!empty($product['additionalProducts'])) {
                        foreach ($product['additionalProducts'] as $additionalProduct) {
                            if ((int)$additionalProduct['productId']) {
                                $product = Product::findOne($additionalProduct['productId']);
                                if (!empty($product)) {
                                    $totalCost += $product->price->discountPriceFloor * $additionalProduct['number'];
                                }
                            }
                        }
                    }
                }
            }
        } else {
            //Gets products from incomplete order in DB
            $order = Order::find()
                ->where(['user_id' => Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
                ->one();
            if (!empty($order)) {
                $orderProducts = OrderProduct::find()->where(['order_id' => $order->id])->all();
                if (!empty($orderProducts)) {
                    foreach ($orderProducts as $product) {
                        if (\Yii::$app->getModule('shop')->enableCombinations && !empty($product->combination)) {
                            $totalCost += $product->count * $product->combination->price->discountPriceFloor;
                        } else {
                            $totalCost += $product->count * $product->product->price->discountPriceFloor;
                        }
                        if (!empty($product->orderProductAdditionalProducts)) {
                            foreach ($product->orderProductAdditionalProducts as $orderProductAdditionalProduct) {
                                $totalCost += $orderProductAdditionalProduct->additionalProduct->price->discountPriceFloor *
                                    $orderProductAdditionalProduct->number;
                            }
                        }
                    }
                }
            }
        }
        return $totalCost;
    }
public function getCost() {
        $totalCost = 0;
        if (Yii::$app->user->isGuest) {
            //Gets products from session
            $session = Yii::$app->session;
            $products = $session[self::SESSION_KEY];

            if (!empty($products)) {
                foreach ($products as $product) {

                    if (!empty($product['combinationId'])) {
                        $combination = Combination::findOne($product['combinationId']);
                        if (!empty($combination)) $totalCost += $combination->price->discountPriceFloor * $product['count'];
                    } else {
                        $productFromDb = Product::findOne($product['id']);
                        if (!empty($productFromDb))
                            $totalCost += $productFromDb->price->discountPriceFloor * $product['count'];
                    }

                    if (!empty($product['additionalProducts'])) {
                        foreach ($product['additionalProducts'] as $additionalProduct) {
                            if ((int)$additionalProduct['productId']) {
                                $product = Product::findOne($additionalProduct['productId']);
                                if (!empty($product)) {
                                    $totalCost += $product->price->discountPriceFloor * $additionalProduct['number'];
                                }
                            }
                        }
                    }
                }
            }
        } else {
            //Gets products from incomplete order in DB
            $order = Order::find()
                ->where(['user_id' => Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
                ->one();
            if (!empty($order)) {
                $orderProducts = OrderProduct::find()->where(['order_id' => $order->id])->all();
                if (!empty($orderProducts)) {
                    foreach ($orderProducts as $product) {
                        if (\Yii::$app->getModule('shop')->enableCombinations && !empty($product->combination)) {
                            $totalCost += $product->count * $product->combination->price->discountPriceFloor;
                        } else {
                            $totalCost += $product->count * $product->product->price->discountPriceFloor;
                        }
                        if (!empty($product->orderProductAdditionalProducts)) {
                            foreach ($product->orderProductAdditionalProducts as $orderProductAdditionalProduct) {
                                $totalCost += $orderProductAdditionalProduct->additionalProduct->price->discountPriceFloor *
                                    $orderProductAdditionalProduct->number;
                            }
                        }
                    }
                }
            }
        }
        return $totalCost;
    }
public function getCost ( ) { $ totalCost = 0 ; if ( Yii :: $ app -> user -> isGuest ) { //Gets products from session $ session = Yii :: $ app -> session ; $ products = $ session [ self :: SESSION_KEY ] ; if ( ! empty ( $ products ) ) { foreach ( $ products as $ product ) { if ( ! empty ( $ product [ 'combinationId' ] ) ) { $ combination = Combination :: findOne ( $ product [ 'combinationId' ] ) ; if ( ! empty ( $ combination ) ) $ totalCost += $ combination -> price -> discountPriceFloor * $ product [ 'count' ] ; } else { $ productFromDb = Product :: findOne ( $ product [ 'id' ] ) ; if ( ! empty ( $ productFromDb ) ) $ totalCost += $ productFromDb -> price -> discountPriceFloor * $ product [ 'count' ] ; } if ( ! empty ( $ product [ 'additionalProducts' ] ) ) { foreach ( $ product [ 'additionalProducts' ] as $ additionalProduct ) { if ( ( int ) $ additionalProduct [ 'productId' ] ) { $ product = Product :: findOne ( $ additionalProduct [ 'productId' ] ) ; if ( ! empty ( $ product ) ) { $ totalCost += $ product -> price -> discountPriceFloor * $ additionalProduct [ 'number' ] ; } } } } } } } else { //Gets products from incomplete order in DB $ order = Order :: find ( ) -> where ( [ 'user_id' => Yii :: $ app -> user -> id , 'status' => OrderStatus :: STATUS_INCOMPLETE ] ) -> one ( ) ; if ( ! empty ( $ order ) ) { $ orderProducts = OrderProduct :: find ( ) -> where ( [ 'order_id' => $ order -> id ] ) -> all ( ) ; if ( ! empty ( $ orderProducts ) ) { foreach ( $ orderProducts as $ product ) { if ( \ Yii :: $ app -> getModule ( 'shop' ) -> enableCombinations && ! empty ( $ product -> combination ) ) { $ totalCost += $ product -> count * $ product -> combination -> price -> discountPriceFloor ; } else { $ totalCost += $ product -> count * $ product -> product -> price -> discountPriceFloor ; } if ( ! empty ( $ product -> orderProductAdditionalProducts ) ) { foreach ( $ product -> orderProductAdditionalProducts as $ orderProductAdditionalProduct ) { $ totalCost += $ orderProductAdditionalProduct -> additionalProduct -> price -> discountPriceFloor * $ orderProductAdditionalProduct -> number ; } } } } } } return $ totalCost ; }
Gets cost of user's incomplete order without discounts
@return mixed
Gets cost of user s incomplete order without discounts