public function actionList(int $productId, int $languageId)
    {

        $product = Product::findOne($productId);
        $products = Product::find()->joinWith('translations')->orderBy('title')->all();
        $relatedProducts = $product->relatedProducts;
        $newRelatedProduct = new RelatedProduct();

        $selectedLanguage = Language::findOne($languageId);
        $languages = Language::find()->all();

        if (\Yii::$app->request->isPost && $newRelatedProduct->load(\Yii::$app->request->post())) {
            if (empty(RelatedProduct::find()
                ->where(['product_id' => $productId, 'related_product_id' => $newRelatedProduct->related_product_id])->one())
            ) {

                $newRelatedProduct->product_id = $productId;
                if ($newRelatedProduct->validate()) $newRelatedProduct->save();
                \Yii::$app->session->setFlash('info', \Yii::t('shop', 'Relation product has added successfully'));
            } else {
                \Yii::$app->session->setFlash('info', \Yii::t('shop', 'Such relation product already exists for this product'));
            }

            return $this->redirect(\Yii::$app->request->referrer);
        }

        return $this->render('../product/save', [
            'viewName' => '../related-product/list',
            'selectedLanguage' => $selectedLanguage,
            'product' => $product,
            'languages' => $languages,

            'params' => [
                'product' => $product,
                'products' => $products,
                'relatedProducts' => $relatedProducts,
                'newRelatedProduct' => $newRelatedProduct,
                'languages' => $languages,
                'selectedLanguage' => $selectedLanguage,
            ]
        ]);
    }
public function actionList(int $productId, int $languageId)
    {

        $product = Product::findOne($productId);
        $products = Product::find()->joinWith('translations')->orderBy('title')->all();
        $relatedProducts = $product->relatedProducts;
        $newRelatedProduct = new RelatedProduct();

        $selectedLanguage = Language::findOne($languageId);
        $languages = Language::find()->all();

        if (\Yii::$app->request->isPost && $newRelatedProduct->load(\Yii::$app->request->post())) {
            if (empty(RelatedProduct::find()
                ->where(['product_id' => $productId, 'related_product_id' => $newRelatedProduct->related_product_id])->one())
            ) {

                $newRelatedProduct->product_id = $productId;
                if ($newRelatedProduct->validate()) $newRelatedProduct->save();
                \Yii::$app->session->setFlash('info', \Yii::t('shop', 'Relation product has added successfully'));
            } else {
                \Yii::$app->session->setFlash('info', \Yii::t('shop', 'Such relation product already exists for this product'));
            }

            return $this->redirect(\Yii::$app->request->referrer);
        }

        return $this->render('../product/save', [
            'viewName' => '../related-product/list',
            'selectedLanguage' => $selectedLanguage,
            'product' => $product,
            'languages' => $languages,

            'params' => [
                'product' => $product,
                'products' => $products,
                'relatedProducts' => $relatedProducts,
                'newRelatedProduct' => $newRelatedProduct,
                'languages' => $languages,
                'selectedLanguage' => $selectedLanguage,
            ]
        ]);
    }
public function actionList ( int $ productId , int $ languageId ) { $ product = Product :: findOne ( $ productId ) ; $ products = Product :: find ( ) -> joinWith ( 'translations' ) -> orderBy ( 'title' ) -> all ( ) ; $ relatedProducts = $ product -> relatedProducts ; $ newRelatedProduct = new RelatedProduct ( ) ; $ selectedLanguage = Language :: findOne ( $ languageId ) ; $ languages = Language :: find ( ) -> all ( ) ; if ( \ Yii :: $ app -> request -> isPost && $ newRelatedProduct -> load ( \ Yii :: $ app -> request -> post ( ) ) ) { if ( empty ( RelatedProduct :: find ( ) -> where ( [ 'product_id' => $ productId , 'related_product_id' => $ newRelatedProduct -> related_product_id ] ) -> one ( ) ) ) { $ newRelatedProduct -> product_id = $ productId ; if ( $ newRelatedProduct -> validate ( ) ) $ newRelatedProduct -> save ( ) ; \ Yii :: $ app -> session -> setFlash ( 'info' , \ Yii :: t ( 'shop' , 'Relation product has added successfully' ) ) ; } else { \ Yii :: $ app -> session -> setFlash ( 'info' , \ Yii :: t ( 'shop' , 'Such relation product already exists for this product' ) ) ; } return $ this -> redirect ( \ Yii :: $ app -> request -> referrer ) ; } return $ this -> render ( '../product/save' , [ 'viewName' => '../related-product/list' , 'selectedLanguage' => $ selectedLanguage , 'product' => $ product , 'languages' => $ languages , 'params' => [ 'product' => $ product , 'products' => $ products , 'relatedProducts' => $ relatedProducts , 'newRelatedProduct' => $ newRelatedProduct , 'languages' => $ languages , 'selectedLanguage' => $ selectedLanguage , ] ] ) ; }
Shows all related products for current product
@param int $productId
@param int $languageId
@return string|\yii\web\Response
Shows all related products for current product