public function actionIndex() { $this->needAuthenticate(); $isCategory = Param::get('is_category')->asInteger(true, "Недопустимое значение параметра."); $id = Param::get('id', false)->asInteger(false); $parentId = Param::get('parent_pk', false)->asInteger(false); /** @var Category $oCategories */ $oCategories = DataSource::factory(Category::cls()); $oCategories->builder()->where('deleted=0'); /** @var Category[] $aCategories */ $aCategories = $oCategories->findAll(); if ($isCategory == 1) { $viewCatalogueEdit = new ViewCategoryEdit(); /** @var Category $oCategory */ $oCategory = DataSource::factory(Category::cls(), $id); $viewCatalogueEdit->oCategory = $oCategory; $viewCatalogueEdit->aCategories = $aCategories; $viewCatalogueEdit->parentId = $oCategory->isNew() ? $parentId : $oCategory->category_id; } else { $viewCatalogueEdit = new ViewItemEdit(); /** @var Item $oItem */ $oItem = DataSource::factory(Item::cls(), $id); $viewCatalogueEdit->oItem = $oItem; $viewCatalogueEdit->aCategories = $aCategories; $viewCatalogueEdit->parentId = $oItem->isNew() ? $parentId : $oItem->category_id; } // Подготовка хлебных крошек $viewBreadcrumbs = new ViewBreadcrumbs(); $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Каталог', '/modules/catalogue')]; if ($parentId) { $breadcrumbsParentPK = $parentId; } elseif ($isCategory == 1 && isset($oCategory)) { $breadcrumbsParentPK = $oCategory->category_id; } elseif (!$isCategory && isset($oItem)) { $breadcrumbsParentPK = $oItem->category_id; } else { $breadcrumbsParentPK = 0; } $catalogueEditBreadcrumbs = []; while ($breadcrumbsParentPK) { /** @var Category $oParentCategory */ $oParentCategory = DataSource::factory(Category::cls(), $breadcrumbsParentPK); $catalogueEditBreadcrumbs[] = new Breadcrumb($oParentCategory->name, "?parent_pk={$oParentCategory->getPrimaryKey()}", true); $breadcrumbsParentPK = $oParentCategory->category_id; } $viewBreadcrumbs->Breadcrumbs = array_merge($viewBreadcrumbs->Breadcrumbs, array_reverse($catalogueEditBreadcrumbs)); if ($id && isset($oCategory)) { $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb("Редактирование \"{$oCategory->name}\"", ''); } elseif ($id && isset($oItem)) { $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb("Редактирование \"{$oItem->name}\"", ''); } else { $lastBreadcrumb = 'Добавление новой ' . ($isCategory == 1 ? 'категории' : 'позиции'); $viewBreadcrumbs->Breadcrumbs[] = new Breadcrumb($lastBreadcrumb, ''); } $viewCatalogueEdit->backUrl = CoreFunctions::buildUrlByBreadcrumbs($viewBreadcrumbs->Breadcrumbs, 1); $this->Frame->bindView('breadcrumbs', $viewBreadcrumbs); $this->Frame->bindView('content', $viewCatalogueEdit); $this->Frame->render(); }
public function getParentCategory() { /** @var Category[] $aCategories */ $aCategories = $this->findRelationCache('category_id', Category::cls()); if (empty($aCategories)) { $oCategories = DataSource::factory(Category::cls()); $oCategories->builder()->where("{$oCategories->getPrimaryKeyName()}={$this->category_id}"); $aCategories = $oCategories->findAll(); foreach ($aCategories as $oCategory) { $this->addRelationCache('category_id', $oCategory); $oCategory->addRelationCache($oCategory->getPrimaryKeyName(), $this); } } return isset($aCategories[0]) ? $aCategories[0] : null; }
public function actionIndex() { $this->needAuthenticate(); $parentCategoryId = Param::get('parent_pk', false); if ($parentCategoryId->exists()) { $parentCategoryId = $parentCategoryId->asInteger(true, 'Недопустимое значение параметра!'); /** @var Category $oParentCategoryFact */ $oParentCategoryFact = DataSource::factory(Category::cls(), $parentCategoryId); if ($oParentCategoryFact->isNew()) { SCMSNotificationLog::instance()->pushError('Недопустимое значение параметра!'); $this->Frame->render(); return; } } else { $parentCategoryId = 0; } $pageNumber = Param::get('catalogue-page', false)->asInteger(false); $itemsPerPage = Param::get('catalogue-items-per-page', false)->asInteger(false); $manifest = $this->ModuleInstaller->getManifest($this->ModuleDirectory); $dataGridView = new ViewDataGrid(); $retriever = new CatalogueRetriever(); $dataGrid = new DataGrid('catalogue', '/admin/modules/catalogue/', 'id', $manifest['meta']['alias'], $pageNumber, $itemsPerPage, $manifest['meta']['description']); $dataGrid->addHiddenField('parent_pk', $parentCategoryId); $dataGrid->getMenu()->addElement(new DataGrid\Menu\Item('Добавить категорию', '/admin/modules/catalogue/edit/?is_category=1' . ($parentCategoryId ? "&parent_pk={$parentCategoryId}" : '')))->addElement(new DataGrid\Menu\Item('Добавить позицию', '/admin/modules/catalogue/edit/?is_category=0' . ($parentCategoryId ? "&parent_pk={$parentCategoryId}" : ''))); $dataGrid->addAction(new Action('id', '/admin/modules/catalogue/edit/', 'edit', '', ['is_category'], ['class' => 'glyphicon glyphicon-pencil'], 'Редактировать'))->addAction(new Action('id', '/admin/modules/catalogue/delete/', 'delete', '', ['is_category'], ['class' => 'glyphicon glyphicon-trash'], 'Удалить', true)); $dataGrid->addHeader(new Header('id', '№', null, ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center'], true, Param::get('catalogue-filter-id', false)->asString(false)))->addHeader(new Header('is_category', 'Тип', new ViewChange('', [[0, '<span class="glyphicon glyphicon-file"></span>'], [1, '<span class="glyphicon glyphicon-folder-open"></span>']]), ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center'], true, Param::get('catalogue-filter-is_category', false)->asString(false)))->addHeader(new Header('name', 'Наименование', new ViewCondition(new ViewDefault(), [['field' => 'is_category', 'value' => 1, 'view' => new ViewLink('/admin/modules/catalogue/?parent_pk={label}', false, 'id')]]), ['class' => 'text-center'], [], true, Param::get('catalogue-filter-name', false)->asString(false)))->addHeader(new Header('description', 'Описание', new ViewCutString(20, true, ['class' => 'content-to-modal', 'style' => 'cursor: pointer;'], ['style' => 'display: none;']), ['class' => 'text-center'], ['class' => 'modal-display-field'], true, Param::get('catalogue-filter-description', false)->asString(false)))->addHeader(new Header('thumbnail', 'Миниатюра', new ViewCondition(new ViewImageLink(true, ['class' => 'fancybox'], ['class' => 'img-rounded', 'style' => 'height: 20px;']), [['field' => 'thumbnail', 'value' => '/public/assets/images/system/no-image.svg', 'view' => new ViewStub('<span class="glyphicon glyphicon-picture"></span>')]]), ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center']))->addHeader(new Header('price', '<span class="glyphicon glyphicon-ruble" title="Цена"></span>', new ViewMoney('<span class="glyphicon glyphicon-ruble"></span>'), ['class' => 'text-center'], ['class' => 'text-center'], true, Param::get('catalogue-filter-price', false)->asString(false)))->addHeader(new Header('count', '<span class="glyphicon glyphicon-inbox" title="Количество"></span>', null, ['class' => 'text-center'], ['class' => 'text-center'], true, Param::get('catalogue-filter-count', false)->asString(false)))->addHeader(new Header('priority', '<span class="glyphicon glyphicon-sort-by-attributes" title="Приоритет"></span>', null, ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center'], true, Param::get('catalogue-filter-priority', false)->asString(false)))->addHeader(new Header('active', '<span class="glyphicon glyphicon-asterisk" title="Активность"></span>', new ViewSwitch(), ['class' => 'text-center', 'style' => 'width: 50px;'], ['class' => 'text-center'], true, Param::get('catalogue-filter-active', false)->asString(false))); $categoriesAndItems = $retriever->getCategoriesAndItems($parentCategoryId, $dataGrid->getFilterConditions('childs'), $dataGrid->Pagination->getLimit(), $dataGrid->Pagination->getOffset()); $dataSet = new ArrayDataSet($categoriesAndItems); $dataGrid->addDataSet($dataSet); $dataGridView->dataGrid = $dataGrid; // Подготовка хлебных крошек $viewBreadcrumbs = new ViewBreadcrumbs(); $viewBreadcrumbs->Breadcrumbs = [new Breadcrumb('Панель управления', '/admin'), new Breadcrumb('Каталог', '/modules/catalogue')]; $breadcrumbsParentPK = $parentCategoryId; $categoryBreadcrumbs = []; while ($breadcrumbsParentPK) { /** @var Category $oParentCategory */ $oParentCategory = DataSource::factory(Category::cls(), $breadcrumbsParentPK); $categoryBreadcrumbs[] = new Breadcrumb($oParentCategory->name, "?parent_pk={$oParentCategory->getPrimaryKey()}", true); $breadcrumbsParentPK = $oParentCategory->category_id; } $viewBreadcrumbs->Breadcrumbs = array_merge($viewBreadcrumbs->Breadcrumbs, array_reverse($categoryBreadcrumbs)); $this->Frame->bindView('breadcrumbs', $viewBreadcrumbs); $this->Frame->bindView('content', $dataGridView); $this->Frame->render(); }
public function actionCategory() { if (CoreFunctions::isAJAX() && !$this->EmployeeAuthentication->authenticated()) { SCMSNotificationLog::instance()->pushError('Нет доступа!'); $this->Response->send(); return; } $this->needAuthenticate(); $categoryId = Param::post('catalogue-category-id', false)->asInteger(false); $name = Param::post('catalogue-category-name')->noEmpty('Заполните поле "Наименование"')->asString(); $description = Param::post('catalogue-category-description')->asString(); $parentCategoryId = Param::post('catalogue-category-parent_id')->asInteger(true, 'Поле "Родительская категория" заполнено неверно.'); $thumbnail = Param::post('catalogue-category-thumbnail', false)->asString(); $priority = Param::post('catalogue-category-priority', false)->asString(); $active = (int) Param::post('catalogue-category-active', false)->exists(); $accept = Param::post('catalogue-category-accept', false); if (CoreFunctions::isAJAX() && SCMSNotificationLog::instance()->hasProblems()) { $this->Response->send(); return; } /** @var Category $oCategory */ $oCategory = DataSource::factory(Category::cls(), $categoryId == 0 ? null : $categoryId); $oCategory->name = $name; $oCategory->description = $description; $oCategory->category_id = $parentCategoryId; $oCategory->thumbnail = $thumbnail; $oCategory->priority = $priority; $oCategory->active = $active; if ($oCategory->isNew()) { $oCategory->deleted = false; } $oCategory->commit(); if (!SCMSNotificationLog::instance()->hasProblems()) { SCMSNotificationLog::instance()->pushMessage("Категория \"{$oCategory->name}\" успешно " . ($categoryId == 0 ? 'добавлена' : 'отредактирована') . "."); } $redirect = "/admin/modules/catalogue/edit/?id={$oCategory->getPrimaryKey()}"; if ($accept->exists()) { $redirect = '/admin/modules/catalogue/' . ($oCategory->category_id == 0 ? '' : "?parent_pk={$oCategory->category_id}"); } elseif ($categoryId != 0) { $redirect = ''; } $this->Response->send($redirect); }
public function categoryDeepDelete(Category $oCategory) { $oChildCategories = DataSource::factory(Category::cls()); $oChildCategories->builder()->where("category_id={$oCategory->getPrimaryKey()}"); /** @var Category[] $aChildCategories */ $aChildCategories = $oChildCategories->findAll(); foreach ($aChildCategories as $oChildCategory) { $this->categoryDeepDelete($oChildCategory); } /** @var Item $oItems */ $oItems = DataSource::factory(Item::cls()); $oItems->builder()->where("category_id={$oCategory->getPrimaryKey()}"); /** @var Item[] $aItems */ $aItems = $oItems->findAll(); foreach ($aItems as $oItem) { $oItem->deleted = true; $oItem->commit(); } $oCategory->deleted = true; $oCategory->commit(); }
public function actionIndex() { $action = Param::request('action', false)->asString(false); $categoryId = 0; switch ($action) { case 'show-item': $itemId = Param::get('item_id', false)->asInteger(false); /** @var Item $oItem */ $oItem = DataSource::factory(Item::cls(), $itemId); $view = new ViewItem(); if (!$oItem->isNew()) { $categoryId = $oItem->category_id; $view->oItem = $oItem; } else { SCMSNotificationLog::instance()->pushError("Товар не найден."); } break; case 'add-to-cart': $id = Param::get('id', true)->noEmpty('Товар не найден.')->asInteger(true, 'Неизвестный товар.'); $count = Param::get('count', true)->noEmpty('Количество должно быть указано.')->asInteger(true, 'Не указано количество товара.'); /** @var Item $oItem */ $oItem = DataSource::factory(Item::cls(), $id); if (!$oItem) { SCMSNotificationLog::instance()->pushError('Товар, который Вы пытаетесь добавить в корзину не существует.'); } if (!$count) { SCMSNotificationLog::instance()->pushError('Количество товара должно быть больше нуля.'); } if (SCMSNotificationLog::instance()->hasProblems()) { $this->Response->send(); return; } $this->cart->addItem($id, $count); SCMSNotificationLog::instance()->pushMessage("Товар \"{$oItem->name}\" в количестве {$count} (шт.) успешно добавлен в корзину. Теперь Вы можете перейти к оформлению заказа или продолжить покупки."); $this->Response->send('', ['totalCount' => $this->cart->getTotalCount()]); return; break; case 'show-cart': $view = new ViewCart(); $cart = $this->cart; $DataGrid = new DataGrid(); $aItemsInCart = $this->cart->getItems(); $DataGrid->setCaption(empty($aItemsInCart) ? 'В Вашей корзине ещё нет ни одного товара' : 'Список товаров')->setAttributes(['class' => 'table table-condensed'])->addColumn((new Column())->setDisplayName('№')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->switchOnCounter())->addColumn((new Column())->setDisplayName('Наименование')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setValueName('name'))->addColumn((new Column())->setDisplayName('Цена')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setFooterAttributes(['style' => 'text-align: center; vertical-align: middle;', 'class' => 'text-success'])->setCallback(function (Item $oItem) { echo $oItem->price, '<span class="glyphicon glyphicon-ruble"></span>'; })->setFooterCallback(function (array $aItems) { ?> Итого:<?php }))->addColumn((new Column())->setDisplayName('Количество')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setFooterAttributes(['style' => 'text-align: center; vertical-align: middle;', 'class' => 'text-danger'])->setCallback(function (Item $oItem) use($cart) { ?> <input type="number" min="1" class="form-control input-sm text-center catalogue-item-count" value="<?php echo $cart->getCountById($oItem->getPrimaryKey()); ?> " /><?php })->setFooterCallback(function (array $aItems) use($cart) { echo $cart->getTotalCount(); }))->addColumn((new Column())->setDisplayName('Сумма')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setFooterAttributes(['style' => 'text-align: center; vertical-align: middle;', 'class' => 'text-danger'])->setCallback(function (Item $oItem) use($cart) { echo $cart->getCountById($oItem->getPrimaryKey()) * $oItem->price, '<span class="glyphicon glyphicon-ruble"></span>'; })->setFooterCallback(function (array $aItems) use($cart) { /** @var Item[] $aItems */ $totalPrice = 0; foreach ($aItems as $oItem) { $totalPrice += $cart->getCountById($oItem->getPrimaryKey()) * $oItem->price; } echo $totalPrice, '<span class="glyphicon glyphicon-ruble"></span>'; }))->addColumn((new Column())->setDisplayName('<span class="glyphicon glyphicon-option-horizontal"></span>')->setHeaderAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setBodyAttributes(['style' => 'text-align: center; vertical-align: middle;'])->setCallback(function (Item $oItem) { echo '<a href="/catalogue?action=remove-from-cart?id=' . $oItem->getPrimaryKey() . '" class="btn btn-danger btn-xs catalogue-cart-remove" title="Удалить товар из конзины"><span class="glyphicon glyphicon-remove"></span></a>'; }))->setDataSet($aItemsInCart); $view->DataGrid = $DataGrid; $view->goodCount = $cart->getTotalCount(); $view->render(); return; break; case 'set-cart-items': $items = Param::get('items')->asArray(); foreach ($items as $itemId => $count) { $this->cart->setItemCount($itemId, $count); } $this->Response->send('', ['totalCount' => $this->cart->getTotalCount()]); return; break; case 'order': break; default: $categoryId = Param::get('category_id', false)->asInteger(false); if (!$categoryId) { $categoryId = 0; } $oCategories = DataSource::factory(Category::cls()); $oCategories->builder()->where('deleted=0')->whereAnd()->where('active=1')->whereAnd()->where("category_id={$categoryId}"); $aCategories = $oCategories->findAll(); $oItems = DataSource::factory(Item::cls()); $oItems->builder()->where('deleted=0')->whereAnd()->where('active=1')->whereAnd()->where("category_id={$categoryId}"); $aItems = $oItems->findAll(); $view = new ViewCatalogue(); $view->categoriesPerRow = 4; $view->itemsPerRow = 4; $view->aCategories = $aCategories; $view->aItems = $aItems; } // Подготовка хлебных крошек $breadcrumbsParentPK = $categoryId; $categoryBreadcrumbs = []; while ($breadcrumbsParentPK) { /** @var Category $oParentCategory */ $oParentCategory = DataSource::factory(Category::cls(), $breadcrumbsParentPK); $categoryBreadcrumbs[] = new Breadcrumb($oParentCategory->name, "?category_id={$oParentCategory->getPrimaryKey()}", true); $breadcrumbsParentPK = $oParentCategory->category_id; } $this->BreadcrumbsView->Breadcrumbs = array_merge($this->BreadcrumbsView->Breadcrumbs, array_reverse($categoryBreadcrumbs)); if (isset($oItem)) { $this->BreadcrumbsView->Breadcrumbs[] = new Breadcrumb($oItem->name, ''); } $view->backUrl = CoreFunctions::buildUrlByBreadcrumbs($this->BreadcrumbsView->Breadcrumbs, 1); $this->Frame->bindView('breadcrumbs', $this->BreadcrumbsView); $view->render(); }