示例#1
0
 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();
 }
示例#2
0
文件: Cart.php 项目: met-mw/SCMS
 public function setItemCount($catalogueItemId, $count)
 {
     /** @var Item $oCatalogueItem */
     $oCatalogueItem = DataSource::factory(Item::cls(), $catalogueItemId);
     if ($oCatalogueItem) {
         $_SESSION[self::SESSION_SECTION_NAME][$oCatalogueItem->getPrimaryKey()] = $count;
     }
 }
示例#3
0
文件: Category.php 项目: met-mw/SCMS
 public function getItems()
 {
     /** @var Item[] $aItems */
     $aItems = $this->findRelationCache($this->getPrimaryKeyName(), Item::cls());
     if (empty($aItems)) {
         $oItems = DataSource::factory(Item::cls());
         $oItems->builder()->where("category_id={$this->getPrimaryKey()}");
         $aItems = $oItems->findAll();
         foreach ($aItems as $oItem) {
             $this->addRelationCache($this->getPrimaryKeyName(), $oItem);
             $oItem->addRelationCache('category_id', $this);
         }
     }
     return $aItems;
 }
示例#4
0
 public function actionItem()
 {
     if (CoreFunctions::isAJAX() && !$this->EmployeeAuthentication->authenticated()) {
         SCMSNotificationLog::instance()->pushError('Нет доступа!');
         $this->Response->send();
         return;
     }
     $this->needAuthenticate();
     $categoryId = Param::post('catalogue-item-id', false)->asInteger(false);
     $name = Param::post('catalogue-item-name')->noEmpty('Заполните поле "Наименование"')->asString();
     $description = Param::post('catalogue-item-description')->asString();
     $parentCategoryId = Param::post('catalogue-item-parent_id')->asInteger(true, 'Поле "Родительская категория" заполнено неверно.');
     $price = Param::post('catalogue-item-price', true)->asNumber(true, "Поле \"Цена\" заполнено неверно.");
     $count = Param::post('catalogue-item-count', true)->asInteger(true, "Поле \"Количество\" заполнено неверно.");
     $thumbnail = Param::post('catalogue-item-thumbnail', false)->asString();
     $priority = Param::post('catalogue-item-priority', false)->asString();
     $active = (int) Param::post('catalogue-item-active', false)->exists();
     $accept = Param::post('catalogue-item-accept', false);
     if (CoreFunctions::isAJAX() && SCMSNotificationLog::instance()->hasProblems()) {
         $this->Response->send();
         return;
     }
     /** @var Item $oItem */
     $oItem = DataSource::factory(Item::cls(), $categoryId == 0 ? null : $categoryId);
     $oItem->name = $name;
     $oItem->description = $description;
     $oItem->category_id = $parentCategoryId;
     $oItem->price = $price;
     $oItem->count = $count;
     $oItem->thumbnail = $thumbnail;
     $oItem->priority = $priority;
     $oItem->active = $active;
     if ($oItem->isNew()) {
         $oItem->deleted = false;
     }
     $oItem->commit();
     if (!SCMSNotificationLog::instance()->hasProblems()) {
         SCMSNotificationLog::instance()->pushMessage("Позиция \"{$oItem->name}\" успешно " . ($categoryId == 0 ? 'добавлена' : 'отредактирована') . ".");
     }
     $redirect = "/admin/modules/catalogue/edit/?id={$oItem->getPrimaryKey()}";
     if ($accept->exists()) {
         $redirect = '/admin/modules/catalogue/' . ($oItem->category_id == 0 ? '' : "?parent_pk={$oItem->category_id}");
     } elseif ($categoryId != 0) {
         $redirect = '';
     }
     $this->Response->send($redirect);
 }
示例#5
0
 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();
 }
示例#6
0
    public function currentRender()
    {
        ?>
        <form action="/admin/modules/catalogue/save/item/<?php 
        echo $this->parentId ? "?parent_pk={$this->parentId}" : '';
        ?>
" method="post" id="catalogue-item-edit-form">
            <fieldset>
                <legend><?php 
        if ($this->oItem->isNew()) {
            ?>
Добавление позиции<?php 
        } else {
            ?>
Редактирование позиции "<?php 
            echo $this->oItem->name;
            ?>
"<?php 
        }
        ?>
</legend>
                <input type="hidden" id="catalogue-item-id" name="catalogue-item-id" value="<?php 
        echo $this->oItem->getPrimaryKey();
        ?>
" />

                <div class="row">
                    <div class="col-lg-6">
                        <div class="row">
                            <div class="col-lg-2">
                                <div class="form-group">
                                    <label for="catalogue-item-number">№</label>
                                    <input class="form-control input-sm" name="catalogue-item-number" id="catalogue-item-number" disabled="disabled" type="number" placeholder="№" value="<?php 
        echo $this->oItem->getPrimaryKey();
        ?>
">
                                    <span class="help-block">Номер</span>
                                </div>
                            </div>
                            <div class="col-lg-10">
                                <div class="form-group">
                                    <label for="catalogue-item-name">Наименование</label>
                                    <input class="form-control input-sm" name="catalogue-item-name" id="catalogue-item-name" type="text" placeholder="Наименование" value="<?php 
        echo $this->oItem->name;
        ?>
" title="Наименование позиции">
                                    <span class="help-block">Наименование позиции</span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label for="catalogue-item-parent_id">Родительская категория</label>
                                    <select class="form-control input-sm" name="catalogue-item-parent_id" id="catalogue-item-parent_id">
                                        <option value="0">Не выбрана</option>
                                        <?php 
        foreach ($this->aCategories as $oCategory) {
            ?>
                                            <option value="<?php 
            echo $oCategory->id;
            ?>
"<?php 
            echo $oCategory->id == $this->parentId ? ' selected="selected"' : '';
            ?>
><?php 
            echo "({$oCategory->id}) {$oCategory->name}";
            ?>
</option>
                                        <?php 
        }
        ?>
                                    </select>
                                    <span class="help-block">Категория, в которой находится данная категория</span>
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div class="form-group">
                                    <label for="catalogue-item-price">Цена</label>
                                    <div class="input-group">
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-ruble"></span></span>
                                        <input class="form-control input-sm" name="catalogue-item-price" id="catalogue-item-price" type="number" min="0" step="0.01" placeholder="Цена" value="<?php 
        echo $this->oItem->price;
        ?>
" title="Стоимость товара">
                                    </div>
                                    <span class="help-block">Стоимость товара</span>
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div class="form-group">
                                    <label for="catalogue-item-count">Количество</label>
                                    <input class="form-control input-sm" name="catalogue-item-count" id="catalogue-item-count" type="number" min="-1" placeholder="Количество" value="<?php 
        echo $this->oItem->count;
        ?>
" title="Количество экземпляров на складе.">
                                    <span class="help-block">Количество экземпляров на складе.</span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="form-group">
                                    <label for="catalogue-item-description">Описание</label>
                                    <textarea class="form-control input-sm" name="catalogue-item-description" id="catalogue-item-description" placeholder="Описание" title="Описание позиции"><?php 
        echo $this->oItem->description;
        ?>
</textarea>
                                    <span class="help-block">Описание позиции</span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label for="catalogue-item-priority">Приоритет</label>
                                    <input class="form-control input-sm" name="catalogue-item-priority" id="catalogue-item-priority" title="Отвечает за порядок вывода элементов в списке позиций." type="number" placeholder="Приоритет" value="<?php 
        echo $this->oItem->priority;
        ?>
">
                                    <span class="help-block">Отвечает за порядок вывода элементов в списке позиций.</span>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label for="catalogue-item-active">Активность</label>
                                    <input class="checkbox" name="catalogue-item-active" id="catalogue-item-active" title="Доступна ли данная позиция в пользовательской части сайта." type="checkbox"<?php 
        echo !$this->oItem->getPrimaryKey() || $this->oItem->active ? ' CHECKED' : '';
        ?>
>
                                    <span class="help-block">Доступна ли данная позиция в пользовательской части сайта.</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="row">
                            <?php 
        $href = $this->oItem->thumbnail == '' ? '/public/assets/images/system/no-image.svg' : $this->oItem->thumbnail;
        ?>
                            <div class="col-lg-5">
                                <div class="form-group">
                                    <label for="catalogue-item-thumbnail">Миниатюра</label>
                                    <div class="input-append">
                                        <input type="hidden" id="catalogue-item-thumbnail" name="catalogue-item-thumbnail" value="<?php 
        echo $href;
        ?>
" />
                                        <a href="/filemanager/dialog.php?type=1&field_id=catalogue-item-thumbnail" class="btn btn-success btn-sm catalogue-item-thumbnail-btn" type="button">Выбрать изображение</a>
                                        <button id="catalogue-item-thumbnail-remove-btn" type="button" class="btn btn-danger btn-sm" title="Убрать изображение"><span class="glyphicon glyphicon-remove"></span></button>
                                    </div>
                                    <hr/>
                                    <span class="help-block">Выбор миниатюры позиции. Данное изображение будет отображаться в пользовательской части сайта в качестве иконки позиции.</span>
                                </div>
                            </div>
                            <div class="col-lg-7 text-center">
                                <a id="catalogue-item-thumbnail-a" href="<?php 
        echo $href;
        ?>
" class="fancybox"><img id="catalogue-item-thumbnail-img" class="fancybox-image" src="<?php 
        echo $href;
        ?>
" alt="Изображение"/></a>
                            </div>
                        </div>
                    </div>
                </div>

                <hr/>
                <a href="<?php 
        echo $this->backUrl;
        ?>
" class="btn btn-warning">Отмена</a>
                <button name="catalogue-item-save" id="catalogue-item-save" type="submit" class="btn btn-primary">Сохранить</button>
                <button name="catalogue-item-accept" id="catalogue-item-accept" type="submit" class="btn btn-success">Применить</button>
            </fieldset>
        </form>
    <?php 
    }
示例#7
0
    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();
    }