public function beforeRender() { parent::beforeRender(); $this->template->projectName = $this->baseDataService->getProjectName(); $this->template->categories = $this->categoryService->getRoot(); $this->template->currentCategory = $this->currentCategory; }
private function createProduct(ProductForm $form) { $values = $form->getValues(); $product = new Product($values->name, $values->price); $product->setDescription($values->description); if ($values->discountType === ProductForm::DISCOUNT_PERCENT) { $product->setDiscountPercent($values->discountPercent); } else { $product->setNominalDiscount($values->nominalDiscount); } $product->setCategories($this->categoryService->getByIds($values->categories)); /** @var FileUpload $fileUpload */ foreach ($values->imagesUpload as $fileUpload) { $this->productImageService->create($product, $fileUpload); } try { if (!$form->hasErrors()) { $this->productService->create($product); $this->flashMessage(sprintf('Product %s has been created.', $product->getName())); $this->redirect(':Admin:Product:List:'); } } catch (EntityDuplicateException $e) { $form->addError(sprintf('Product with name %s already exists.', $product->getName())); } }
public function render() { $this->template->categories = $this->categoryService->getRoot(); $this->template->editedCategory = $this->editedCategory; $this->template->rootCategoryKey = CategoriesForm::ROOT_CATEGORY_KEY; $this->template->setFile(__DIR__ . '/CategoriesFormControl.latte'); $this->template->render(); }
public function beforeRender() { parent::beforeRender(); $this->template->categories = $this->categoryService->getRoot(); $this->template->currentCategory = $this->currentCategory; $this->template->cart = $this->currentCartService->getCurrentCart(); $this->template->user = $this->user; }
private function addDeleteContainer() { $deleteContainer = $this->addContainer('delete'); foreach ($this->categoryService->getAll() as $category) { if (!$category->hasProducts()) { $deleteContainer->addSubmit($category->getId(), 'x'); } } }
/** * @param string $path */ public function actionDefault($path) { $category = $this->categoryService->getByPath($path); if ($category === null) { // todo CategoryAlias throw new BadRequestException(sprintf('Category with path %s not found.', $path)); } $this->setCurrentCategory($category); }
public function render() { $this->template->product = $this->editedProduct; $this->template->categories = $this->categoryService->getRoot(); $this->template->formDiscountPercentKey = ProductForm::DISCOUNT_PERCENT; $this->template->formDiscountNominalKey = ProductForm::DISCOUNT_NOMINAL; $this->template->imagesDir = $this->imagesDir; $this->template->setFile(__DIR__ . '/ProductFormControl.latte'); $this->template->render(); }
private function manageCategories(ArrayHash $values, ManageCategoriesForm $form) { /** @var Container $deleteContainer */ $deleteContainer = $form->getComponent('delete'); foreach ($this->categoryService->getAll() as $category) { /** @var SubmitButton $deleteSubmit */ $deleteSubmit = $deleteContainer->getComponent($category->getId(), false); if ($deleteSubmit !== null && $deleteSubmit->isSubmittedBy()) { $this->flashMessage(sprintf('Category %s has been deleted.', $category->getName())); $this->categoryService->remove($category); $this->redirect('this'); } } }
private function addParentCategoryControl() { $parentCategoryItems = [self::ROOT_CATEGORY_KEY => '']; foreach ($this->categoryService->getAll() as $category) { if ($this->editedCategory !== null) { if ($category->isSelfOrSubcategoryOf($this->editedCategory)) { continue; } } $parentCategoryItems[$category->getId()] = ''; } $parentCategoryControl = $this->addRadioList('parentCategory', 'Parent category', $parentCategoryItems); $parentCategoryControl->setRequired(); $parentCategoryControl->setDefaultValue($this->editedCategory !== null && $this->editedCategory->hasParent() ? $this->editedCategory->getParent()->getId() : self::ROOT_CATEGORY_KEY); }
private function createCategory(CategoriesForm $form) { $values = $form->getValues(); $category = new Category($values->name); if ($values->parentCategory !== CategoriesForm::ROOT_CATEGORY_KEY) { $parentCategory = $this->categoryService->getById($values->parentCategory); $category->setParent($parentCategory); } try { if (!$form->hasErrors()) { $this->categoryService->create($category); $this->flashMessage(sprintf('Category %s has been created.', $category->getName())); $this->redirect(':Admin:Category:List:'); } } catch (EntityDuplicateException $e) { $form->addError(sprintf('Category with name %s already exists.', $category->getName())); } }
private function updateProduct(ProductForm $form) { $values = $form->getValues(); $this->product->setName($values->name); $this->product->setOriginalPrice($values->price); $this->product->setDescription($values->description); if ($values->discountType === ProductForm::DISCOUNT_PERCENT) { $this->product->setDiscountPercent($values->discountPercent); } else { $this->product->setNominalDiscount($values->nominalDiscount); } $this->product->setCategories($this->categoryService->getByIds($values->categories)); if ($this->product->hasImages()) { $fixedOrders = $this->fixOrders($values->images); foreach ($values->images as $imageId => $imageData) { $imageId = (int) $imageId; $image = $this->productImageService->getById($imageId); if ((bool) $imageData->remove) { $this->productImageService->delete($image); } else { $image->setDescription($imageData->description === '' ? null : $imageData->description); $image->setOrder($fixedOrders[$imageId]); } } } /** @var FileUpload $fileUpload */ foreach ($values->imagesUpload as $fileUpload) { $this->productImageService->create($this->product, $fileUpload); } try { if (!$form->hasErrors()) { $this->productService->update($this->product); $this->flashMessage(sprintf('Product %s has been updated.', $this->product->getName())); $this->redirect(':Admin:Product:List:'); } } catch (EntityDuplicateException $e) { $form->addError(sprintf('Product with name %s already exists.', $this->product->getName())); } }
private function addCategoriesControl() { $categoryIds = iterator_to_array($this->categoryService->getAll()); $categoryIds = array_map(function (Category $category) { return $category->getId(); }, $categoryIds); $control = $this->addCheckboxList('categories', 'Categories', array_flip($categoryIds)); if ($this->editedProduct !== null) { $checkedIds = iterator_to_array($this->editedProduct->getCategories()); $checkedIds = array_map(function (Category $category) { return $category->getId(); }, $checkedIds); $control->setDefaultValue($checkedIds); } }
public function renderDefault() { $this->template->categories = $this->categoryService->getRoot(); }