public function removeItem(int $productId, int $combinationId = null)
    {
        if (!\Yii::$app->user->isGuest) {
            $order = Order::find()->where([
                'user_id' => \Yii::$app->user->id,
                'status' => OrderStatus::STATUS_INCOMPLETE
            ])->one();
            if (!empty($order)) {
                $orderProduct = OrderProduct::find()->where([
                    'product_id' => $productId,
                    'combination_id' => $combinationId,
                    'order_id' => $order->id
                ])->one();
                if (!empty($orderProduct)) {
                    $orderProduct->delete();
                }
            }
        } else {
            $session = Yii::$app->session;
            if ($session->has(self::SESSION_KEY)) {
                $products = $session[self::SESSION_KEY];
                foreach ($products as $key => $product) {
                    if ($product['id'] == $productId && $product['combinationId'] == $combinationId)
                        unset($_SESSION[self::SESSION_KEY][$key]);
                }
            }
        }
        $this->trigger(self::EVENT_AFTER_REMOVE_PRODUCT);
    }
public function removeItem(int $productId, int $combinationId = null)
    {
        if (!\Yii::$app->user->isGuest) {
            $order = Order::find()->where([
                'user_id' => \Yii::$app->user->id,
                'status' => OrderStatus::STATUS_INCOMPLETE
            ])->one();
            if (!empty($order)) {
                $orderProduct = OrderProduct::find()->where([
                    'product_id' => $productId,
                    'combination_id' => $combinationId,
                    'order_id' => $order->id
                ])->one();
                if (!empty($orderProduct)) {
                    $orderProduct->delete();
                }
            }
        } else {
            $session = Yii::$app->session;
            if ($session->has(self::SESSION_KEY)) {
                $products = $session[self::SESSION_KEY];
                foreach ($products as $key => $product) {
                    if ($product['id'] == $productId && $product['combinationId'] == $combinationId)
                        unset($_SESSION[self::SESSION_KEY][$key]);
                }
            }
        }
        $this->trigger(self::EVENT_AFTER_REMOVE_PRODUCT);
    }
public function removeItem ( int $ productId , int $ combinationId = null ) { if ( ! \ Yii :: $ app -> user -> isGuest ) { $ order = Order :: find ( ) -> where ( [ 'user_id' => \ Yii :: $ app -> user -> id , 'status' => OrderStatus :: STATUS_INCOMPLETE ] ) -> one ( ) ; if ( ! empty ( $ order ) ) { $ orderProduct = OrderProduct :: find ( ) -> where ( [ 'product_id' => $ productId , 'combination_id' => $ combinationId , 'order_id' => $ order -> id ] ) -> one ( ) ; if ( ! empty ( $ orderProduct ) ) { $ orderProduct -> delete ( ) ; } } } else { $ session = Yii :: $ app -> session ; if ( $ session -> has ( self :: SESSION_KEY ) ) { $ products = $ session [ self :: SESSION_KEY ] ; foreach ( $ products as $ key => $ product ) { if ( $ product [ 'id' ] == $ productId && $ product [ 'combinationId' ] == $ combinationId ) unset ( $ _SESSION [ self :: SESSION_KEY ] [ $ key ] ) ; } } } $ this -> trigger ( self :: EVENT_AFTER_REMOVE_PRODUCT ) ; }
Removes item from order.
@param $productId integer
@param $combinationId integer
Removes item from order .