public function saveSelectedCombinationToSession($combination)
    {
        if (!empty($combination)) {
            $items = Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS];
            $itemIsExist = false;

            if(!empty($items)) {
                foreach ($items as $key => $item) {
                    if ($item['productId'] == $combination->product_id) {
                        $items[$key]['combinationId'] = $combination->id;
                        $itemIsExist = true;
                    }
                }
            }
            if (!$itemIsExist) {
                $items[] = [
                    'productId' => $combination->product_id,
                    'combinationId' => $combination->id,
                ];
            }

            Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS] = $items;

            return true;
        }

        return false;
    }
public function saveSelectedCombinationToSession($combination)
    {
        if (!empty($combination)) {
            $items = Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS];
            $itemIsExist = false;

            if(!empty($items)) {
                foreach ($items as $key => $item) {
                    if ($item['productId'] == $combination->product_id) {
                        $items[$key]['combinationId'] = $combination->id;
                        $itemIsExist = true;
                    }
                }
            }
            if (!$itemIsExist) {
                $items[] = [
                    'productId' => $combination->product_id,
                    'combinationId' => $combination->id,
                ];
            }

            Yii::$app->session[self::SESSION_KEY_SELECTED_COMBINATIONS] = $items;

            return true;
        }

        return false;
    }
public function saveSelectedCombinationToSession ( $ combination ) { if ( ! empty ( $ combination ) ) { $ items = Yii :: $ app -> session [ self :: SESSION_KEY_SELECTED_COMBINATIONS ] ; $ itemIsExist = false ; if ( ! empty ( $ items ) ) { foreach ( $ items as $ key => $ item ) { if ( $ item [ 'productId' ] == $ combination -> product_id ) { $ items [ $ key ] [ 'combinationId' ] = $ combination -> id ; $ itemIsExist = true ; } } } if ( ! $ itemIsExist ) { $ items [ ] = [ 'productId' => $ combination -> product_id , 'combinationId' => $ combination -> id , ] ; } Yii :: $ app -> session [ self :: SESSION_KEY_SELECTED_COMBINATIONS ] = $ items ; return true ; } return false ; }
Saves last selected product combinations to session.

@param Combination $combination
@return bool
Saves last selected product combinations to session .