findCollection($id); $variants = $collection->variants; $variant = current($variants); return $this->redirect([ 'view', 'collection_id' => $collection->product_id, 'variant_id' => $variant->product_variant_id, ]); } public function actionView($collection_id, $variant_id) { $collection = $this->findCollection($collection_id, $variant_id); $variants = $collection->variants; $variants = ArrayHelper::index($variants, 'product_variant_id'); $variant = $variants[ $variant_id ]; $projects = Project::find() ->joinWith('productToProject') ->joinWith('lang', true, 'INNER JOIN') ->with('image') ->where([ 'product_to_project.product_variant_id' => $variant->product_variant_id ]) ->all(); return $this->render('view', [ 'collection' => $collection, 'variants' => $variants, 'variant' => $variant, 'projects' => $projects, ]); } /** * @param $id * * @return Product * @throws NotFoundHttpException */ private function findCollection($id, $variant_id = NULL) { $model = Product::find() ->joinWith('variants.lang', true, 'INNER JOIN') ->joinWith('lang', true, 'INNER JOIN') ->joinWith('brand.lang', true, 'INNER JOIN') ->with('productSpec.lang') ->where([ 'product.product_id' => $id ]) ->andFilterWhere([ 'product_variant.product_variant_id' => $variant_id ]) ->one(); if(empty( $model )) { throw new NotFoundHttpException(); } return $model; } }