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'); }
protected function createComponentItemForm() { $form = new UI\Form(); $form->addText('name', 'Název výrobku:')->setRequired(); $categories = $this->category->order('name')->fetchPairs('id', 'name'); $manufacturers = $this->manufacturer->order('name')->fetchPairs('id', 'name'); $manufacturers[null] = '--- Žádný výrobce ---'; $form->addCheckboxList('category_id', 'Kategorie', $categories); $form['category_id']->setAttribute('class', 'small'); $form->addSelect('manufacturer_id', 'Výrobce', $manufacturers)->setDefaultValue(''); $form->addCheckbox('showPrice', 'Zobrazovat cenu?')->addCondition($form::EQUAL, TRUE)->toggle('price'); $form->addText('price', 'Cena za ks včetně DPH')->setType('number')->setDefaultValue(0)->setOption('id', 'price')->addRule($form::RANGE, 'Cena nemůže být záp**ná.', array(0, 1000000000)); $form->addCheckbox('recommended', 'Je zboží doporučené?'); $form->addCheckbox('new', 'Je to novinka?'); $form->addCheckbox('clearance_sale', 'Doprodej?'); $form->addCheckbox('stock', 'Skladem?'); $form->addCheckbox('order', 'Na objednávku?'); $form->addUpload('photo', 'Přidat obrázek výrobku:'); $form->addTextArea('description', 'Popis:')->setAttribute('class', 'tinyMCE'); $form->addSubmit('save', 'Uložit')->setAttribute('class', 'btn btn-primary'); $form->onSuccess[] = array($this, 'itemFormSucceeded'); return $form; }
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"); } }