public function actionDelete($id) { try { $this->manufacturer->get($id)->delete(); $this->flashMessage('Výrobce odstraněn.', 'success'); } catch (\Exception $e) { $this->flashMessage('Výrobce se nepodařilo smazat, pravděpodobně máte na webu vystavené jeho výrobky.', 'danger'); } $this->redirect('default'); }
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"); } }