public function actionShow($id) { $this->good = $this->goods->get($id); if (!$this->good) { $this->flashMessage('Výrobek se nepodařilo načíst.', 'danger'); $this->redirect(':Front:Catalog:default'); } $goodsSimilar = array(); $goodsSameManufacturer = $this->goods->createSelectionInstance()->where("manufacturer_id = ?", $this->good->manufacturer->id)->order('id DESC')->limit(2); $goodCG = $this->good->related('category_goods'); $goodCategoryIds = array(); foreach ($goodCG as $cg) { $goodCategoryIds[] = $cg->category->id; } $goodsSimilarCG = $this->categoryGoods->createSelectionInstance()->where('category_id IN ?', $goodCategoryIds); foreach ($goodsSimilarCG as $cg) { if ($cg->good->id == $this->good->id) { continue; } $goodsSimilar[] = $cg->good; } foreach ($goodsSameManufacturer as $good) { if ($good->id == $this->good->id) { continue; } $goodsSimilar[] = $good; } $this->goodsSimilar = array_unique($goodsSimilar); }
public function renderFilter($categoryId = null, $manufacturerId = null) { $this->template->goodsRecommended = array(); $this->template->goodsOther = array(); $this->template->selectedCategoryId = $categoryId; $this->template->selectedSubcategoryId = $categoryId; $this->template->selectedManufacturerId = $manufacturerId; if ($categoryId && $manufacturerId) { $category = $this->category->createSelectionInstance()->get($categoryId); $manufacturer = $this->manufacturer->get($manufacturerId); if (!$category || !$manufacturer) { $this->flashMessage('Kategorie nebo výrobce nebyl nalezen.', 'warning'); } else { $parentCategory = $category->parent ? $this->category->createSelectionInstance()->get($category->parent) : null; $this->template->filterName = ($parentCategory ? $parentCategory->name . ' - ' : '') . $category->name . " od " . $manufacturer->name; $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($category->description)]; $in = $category . ','; $subcategories = $category->related('category.parent'); foreach ($subcategories as $subcategory) { $in .= $subcategory . ','; } $in = rtrim($in, ','); $sql = "SELECT g.id\n\t\t\t\t\t\tFROM category_goods cg\n\t\t\t\t\t\tJOIN goods g ON cg.`goods_id` = g.id\n\t\t\t\t\t\tJOIN category c ON cg.`category_id` = c.id\n\t\t\t\t\t\tWHERE cg.`category_id` IN ({$in}) AND g.`manufacturer_id` = {$manufacturerId} AND g.recommended = "; $this->template->goodsRecommended = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "1 GROUP BY id")->fetchPairs()); $this->template->goodsOther = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "0 GROUP BY id")->fetchPairs()); if ($category->parent) { $this->template->selectedCategoryId = $category->parent; $this->template->selectedSubCategoryId = $categoryId; } else { $this->template->selectedCategoryId = $categoryId; } } } elseif ($categoryId) { $category = $this->category->createSelectionInstance()->get($categoryId); if (!$category) { $this->flashMessage('Kategorie nebyla nalezena.', 'warning'); } else { $parentCategory = $category->parent ? $this->category->createSelectionInstance()->get($category->parent) : null; $this->template->filterName = ($parentCategory ? $parentCategory->name . ' - ' : '') . $category->name; $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($category->description)]; $in = $category . ','; $subcategories = $category->related('category.parent'); foreach ($subcategories as $subcategory) { $in .= $subcategory . ','; } $in = rtrim($in, ','); $sql = "SELECT g.id\n\t\t\t\t\t\tFROM category_goods cg\n\t\t\t\t\t\tJOIN goods g ON cg.`goods_id` = g.id\n\t\t\t\t\t\tJOIN category c ON cg.`category_id` = c.id\n\t\t\t\t\t\tWHERE cg.`category_id` IN ({$in}) AND g.recommended = "; $this->template->goodsRecommended = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "1 GROUP BY id")->fetchPairs()); $this->template->goodsOther = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "0 GROUP BY id")->fetchPairs()); if ($category->parent) { $this->template->selectedCategoryId = $category->parent; $this->template->selectedSubCategoryId = $categoryId; } else { $this->template->selectedCategoryId = $categoryId; } } } elseif ($manufacturerId) { $manufacturer = $this->manufacturer->get($manufacturerId); if (!$manufacturer) { $this->flashMessage('Výrobce nebyl nalezen.', 'warning'); } else { $this->template->filterName = $manufacturer->name; $this->template->goodsRecommended = $this->good->where('manufacturer_id = ? AND recommended != 0', $manufacturerId)->order('id DESC'); $this->template->goodsOther = $this->good->createSelectionInstance()->where('manufacturer_id = ? AND recommended = 0', $manufacturerId)->order('id DESC'); $this->template->selectedManufacturer = $manufacturerId; $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($manufacturer->description)]; } } else { $this->redirect("default"); } }