private function saveProductToDataBase($productId, $count, $attributesAndValues = null, $additionalProducts = null, $combinationId = null)
    {
        $order = $this->getIncompleteOrderFromDB();

        if (\Yii::$app->getModule('shop')->enableCombinations) {
            if (!empty($attributesAndValues)) {
                $combination = $this->getCombination($attributesAndValues, $productId);
                if (!empty($combination)) {
                    $orderProduct = $this->getOrderProduct($order->id, $productId, $combination->id);
                }
                else {
                    throw new Exception(\Yii::t('cart', 'Such attributes combination does not exist'));
                }
            }
            else if(!empty($combinationId)) {
                $orderProduct = $this->getOrderProduct($order->id, $productId, $combinationId);
            }
            else {
                $orderProduct = $this->getOrderProduct($order->id, $productId, null);
            }
        } else {
            $orderProduct = new OrderProduct();
            $orderProduct->product_id = $productId;
            $orderProduct->order_id = $order->id;
        }

        $orderProduct->count += $count;
        if ($orderProduct->validate()) {
            $orderProduct->save();

            if (!empty($additionalProducts)) {
                foreach ($additionalProducts as $additionalProduct) {
                    $orderProductAdditionalProduct = OrderProductAdditionalProduct::find()
                        ->where(['order_product_id' => $orderProduct->id, 'additional_product_id' => $additionalProduct['productId']])
                        ->one();
                    if (empty($orderProductAdditionalProduct)) {
                        $orderProductAdditionalProduct = new OrderProductAdditionalProduct();
                        $orderProductAdditionalProduct->order_product_id = $orderProduct->id;
                        $orderProductAdditionalProduct->additional_product_id = $additionalProduct['productId'];
                        $orderProductAdditionalProduct->number = $additionalProduct['number'];
                        if ($orderProductAdditionalProduct->validate()) $orderProductAdditionalProduct->save();
                    }
                    else {
                        $orderProductAdditionalProduct->number += $additionalProduct['number'];
                        if ($orderProductAdditionalProduct->validate()) $orderProductAdditionalProduct->save();

                    }
                }
            }
        } else die(var_dump($orderProduct->errors));
    }
private function saveProductToDataBase($productId, $count, $attributesAndValues = null, $additionalProducts = null, $combinationId = null)
    {
        $order = $this->getIncompleteOrderFromDB();

        if (\Yii::$app->getModule('shop')->enableCombinations) {
            if (!empty($attributesAndValues)) {
                $combination = $this->getCombination($attributesAndValues, $productId);
                if (!empty($combination)) {
                    $orderProduct = $this->getOrderProduct($order->id, $productId, $combination->id);
                }
                else {
                    throw new Exception(\Yii::t('cart', 'Such attributes combination does not exist'));
                }
            }
            else if(!empty($combinationId)) {
                $orderProduct = $this->getOrderProduct($order->id, $productId, $combinationId);
            }
            else {
                $orderProduct = $this->getOrderProduct($order->id, $productId, null);
            }
        } else {
            $orderProduct = new OrderProduct();
            $orderProduct->product_id = $productId;
            $orderProduct->order_id = $order->id;
        }

        $orderProduct->count += $count;
        if ($orderProduct->validate()) {
            $orderProduct->save();

            if (!empty($additionalProducts)) {
                foreach ($additionalProducts as $additionalProduct) {
                    $orderProductAdditionalProduct = OrderProductAdditionalProduct::find()
                        ->where(['order_product_id' => $orderProduct->id, 'additional_product_id' => $additionalProduct['productId']])
                        ->one();
                    if (empty($orderProductAdditionalProduct)) {
                        $orderProductAdditionalProduct = new OrderProductAdditionalProduct();
                        $orderProductAdditionalProduct->order_product_id = $orderProduct->id;
                        $orderProductAdditionalProduct->additional_product_id = $additionalProduct['productId'];
                        $orderProductAdditionalProduct->number = $additionalProduct['number'];
                        if ($orderProductAdditionalProduct->validate()) $orderProductAdditionalProduct->save();
                    }
                    else {
                        $orderProductAdditionalProduct->number += $additionalProduct['number'];
                        if ($orderProductAdditionalProduct->validate()) $orderProductAdditionalProduct->save();

                    }
                }
            }
        } else die(var_dump($orderProduct->errors));
    }
private function saveProductToDataBase ( $ productId , $ count , $ attributesAndValues = null , $ additionalProducts = null , $ combinationId = null ) { $ order = $ this -> getIncompleteOrderFromDB ( ) ; if ( \ Yii :: $ app -> getModule ( 'shop' ) -> enableCombinations ) { if ( ! empty ( $ attributesAndValues ) ) { $ combination = $ this -> getCombination ( $ attributesAndValues , $ productId ) ; if ( ! empty ( $ combination ) ) { $ orderProduct = $ this -> getOrderProduct ( $ order -> id , $ productId , $ combination -> id ) ; } else { throw new Exception ( \ Yii :: t ( 'cart' , 'Such attributes combination does not exist' ) ) ; } } else if ( ! empty ( $ combinationId ) ) { $ orderProduct = $ this -> getOrderProduct ( $ order -> id , $ productId , $ combinationId ) ; } else { $ orderProduct = $ this -> getOrderProduct ( $ order -> id , $ productId , null ) ; } } else { $ orderProduct = new OrderProduct ( ) ; $ orderProduct -> product_id = $ productId ; $ orderProduct -> order_id = $ order -> id ; } $ orderProduct -> count += $ count ; if ( $ orderProduct -> validate ( ) ) { $ orderProduct -> save ( ) ; if ( ! empty ( $ additionalProducts ) ) { foreach ( $ additionalProducts as $ additionalProduct ) { $ orderProductAdditionalProduct = OrderProductAdditionalProduct :: find ( ) -> where ( [ 'order_product_id' => $ orderProduct -> id , 'additional_product_id' => $ additionalProduct [ 'productId' ] ] ) -> one ( ) ; if ( empty ( $ orderProductAdditionalProduct ) ) { $ orderProductAdditionalProduct = new OrderProductAdditionalProduct ( ) ; $ orderProductAdditionalProduct -> order_product_id = $ orderProduct -> id ; $ orderProductAdditionalProduct -> additional_product_id = $ additionalProduct [ 'productId' ] ; $ orderProductAdditionalProduct -> number = $ additionalProduct [ 'number' ] ; if ( $ orderProductAdditionalProduct -> validate ( ) ) $ orderProductAdditionalProduct -> save ( ) ; } else { $ orderProductAdditionalProduct -> number += $ additionalProduct [ 'number' ] ; if ( $ orderProductAdditionalProduct -> validate ( ) ) $ orderProductAdditionalProduct -> save ( ) ; } } } } else die ( var_dump ( $ orderProduct -> errors ) ) ; }
Saves product to database if the corresponding property is true.

@param integer $productId
@param integer $count
@param array|null $attributesAndValues
@param array|null $additionalProducts
@param null $combinationId
@throws Exception
Saves product to database if the corresponding property is true .