Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author S.Serdyuk
- * @copyright (c) 2013, WebAkula
- * @title Каталог
- * @description ...
- */
- class Catalog_AdminController extends Core_Admin {
- public function init() {
- parent::init();
- $this->_breadcrumbs->addUrl('Каталог', array(), 'catalog', 'index');
- }
- /**
- * @title Главная страница
- * @description Что сюда вывести?
- */
- public function indexAction() {
- }
- /**
- * @title Бренды
- * @description Управление брендами (производителями)
- */
- public function brandsAction() {
- $action = $this->_getParam('action', null);
- $model = new Catalog_Model_Brands;
- $this->_breadcrumbs->addUrl('Бренды', array(), 'catalog', 'brands');
- switch ($action) {
- case 'index': default:
- $category = $this->_getParam('category', null);
- $this->view->list = $model->getList($category);
- $this->render('brands/index');
- break;
- case 'add':
- $this->_breadcrumbs->addNode('Добавление бренда');
- $form = new Catalog_Form_Brands_Add;
- if ($this->getRequest()->isPost()) {
- $model = new Catalog_Model_Brands;
- $data = $this->getRequest()->getPost();
- $data['category_id'] = $this->_getParam('category');
- unset($data['submit']);
- $data['data_id'] = $model->_getNextDataId();
- $model->insert($data);
- $this->_redirect($this->view->adminUrl('catalog', 'categories', array('action' => 'edit', 'id' => $data['category_id'], 'hash' => 'brands')));
- } else {
- $this->view->form = $form;
- $this->view->categoryId = $this->_getParam('category', null);
- }
- $this->render('brands/add');
- break;
- case 'delete':
- $model = new Catalog_Model_Brands();
- $id = $this->_getParam('id');
- $brand = $model->getByDataId($id);
- //Zend_Debug::dump($brand);exit;
- $model->update(array('deleted' => 1), 'data_id=' . $brand['data_id']);
- $model = new Catalog_Model_Products;
- $model->update(array('deleted' => 1), 'brand_id=' . $brand['data_id'] . ' AND category_id=' . $brand['category_id']);
- $this->_redirect($this->view->adminUrl('catalog', 'categories', array('action' => 'edit', 'id' => $brand['category_id'], 'hash' => 'brands')));
- break;
- case 'edit':
- $this->_breadcrumbs->addNode('Редактирование бренда');
- $form = new Catalog_Form_Brands_Edit;
- if ($this->getRequest()->isPost()) {
- $model = new Catalog_Model_Brands;
- $data = $this->getRequest()->getPost();
- $data['category_id'] = $this->_getParam('category');
- unset($data['submit']);
- $data['data_id'] = $model->_getNextDataId();
- $model->insert($data);
- $this->_redirect($this->view->adminUrl('catalog', 'categories', array('action' => 'edit', 'id' => $data['category_id'], 'hash' => 'brands')));
- } else {
- $this->view->form = $form;
- $this->view->categoryId = $this->_getParam('category', null);
- }
- break;
- }
- }
- /**
- * @title Управление категориями
- * @description Полное управление категориями каталога
- */
- public function categoriesAction() {
- $this->view->headScript()->appendFile('/admin_style/js/admin/catalog/categories.js');
- $action = $this->_getParam('action', null);
- $model = new Catalog_Model_Categories;
- switch ($action) {
- /**
- * Основные действия по управлению категориями
- */
- case 'list':
- $this->_breadcrumbs->addNode('Управление категориями');
- $show = $this->_getParam('show', null);
- if (!is_null($show)) {
- $model = new Catalog_Model_Products;
- $this->view->products = $model->getCategory($show);
- }
- $this->render('categories/list');
- break;
- case 'add':
- $this->_breadcrumbs->addUrl('Управление категориями', array(), 'catalog', 'categories')->addNode('Добавление категории');
- $form = new Catalog_Form_Categories_Add;
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- //exit(Zend_Debug::dump($data));
- if ($form->isValid($data)) {
- $properties = $data['properties'];
- $data['data_id'] = $model->_getNextDataId($data['parent_id'], $this->_currentLanguageId);
- $data['ordering'] = $model->_getNextOrdering($data['parent_id'], $this->_currentLanguageId);
- unset($data['submit'], $data['properties'], $data['MAX_FILE_SIZE']);
- $model->insert($data);
- $model = new Catalog_Model_Categories_Properties();
- foreach ($properties as $k => $p) {
- $model->insert(array(
- 'category_id' => $data['data_id'],
- 'property_id' => $k,
- 'default_values' => $p['default_values']
- ));
- }
- $this->_helper->flashMessenger->addMessage(_('Категория добавлена'));
- $this->_redirect($this->view->adminUrl('catalog', 'categories'));
- } else {
- $this->view->form = $form->populate($data);
- }
- } else {
- $parent = $this->_getParam('parent');
- $model = new Catalog_Model_Categories;
- $properties = new Catalog_Model_Properties;
- $data = $model->getByDataId($parent, $this->_currentLanguageId);
- if (!$data) {
- $data['title'] = 'Корневой элемент';
- }
- $this->view->parent = $data;
- $this->view->properties = $properties->getAll($this->_currentLanguageId);
- $path = Core_Helper_Tree::branch($parent, $model->getAll(true, $this->_currentLanguageId));
- $parts = array();
- foreach ($path as $p) {
- $parts[] = $p['title'];
- }
- if (!count($parts)) {
- $parts[] = 'Корневая категория';
- }
- $this->view->path = implode(' / ', array_reverse($parts));
- $this->view->form = $form;
- $this->render('categories/add');
- }
- break;
- case 'add-translation':
- $this->_breadcrumbs->addUrl('Управление категориями', array(), 'catalog', 'categories')->addNode('Добавление перевода');
- $form = new Catalog_Form_Categories_Add;
- $model = new Catalog_Model_Categories;
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- unset($data['submit']);
- $data['lang_id'] = $this->translationParam('lang_id');
- $data['data_id'] = $this->translationParam('data_id');
- //Zend_Debug::dump($data);
- $model->insert($data);
- $this->_redirect($this->view->adminUrl('catalog', 'categories'));
- } else {
- $id = $this->translationParam('data_id');
- $data = $model->getByDataId($id, $this->_currentLanguageId);
- $this->view->parent = $data;
- $this->view->form = $form;
- $this->render('multilingual/categories/add-translation');
- }
- break;
- case 'remove':
- $this->_helper->layout()->disableLayout();
- $id = $this->_getParam('id');
- $model->removeNode($id);
- exit('success');
- break;
- case 'edit':
- $this->_breadcrumbs->addUrl('Управление категориями', array(), 'catalog', 'categories')->addNode('Редактирование категории');
- $form = new Catalog_Form_Categories_Edit();
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- if ($form->isValid($data)) {
- $imgs = Core_Helper_File::receive();
- //exit(Zend_Debug::dump($imgs['images'][0]));
- if (mb_strlen($imgs['images'][0])) {
- $data['img'] = $imgs['images'][0];
- }
- $properties = $data['properties'];
- $props = new Catalog_Model_Categories_Properties;
- $id = $data['data_id'];
- unset($data['properties'], $data['submit'], $data['data_id'], $data['MAX_FILE_SIZE']);
- if (APP_MULTILINGUAL) {
- $model->update($data, array(
- $model->getAdapter()->quoteInto('data_id = ?', $id),
- $model->getAdapter()->quoteInto('lang_id = ?', $this->_currentLanguageId),
- ));
- } else {
- $model->update($data, $model->getAdapter()->quoteInto('data_id = ?', $id));
- }
- foreach ($properties as $id => $data) { //$id - ID строки в таблице catalog_categories_propertie
- if ($data['use']) {
- $props->update(array('default_values' => $data['default_values']), $props->getAdapter()->quoteInto('id = ?', $id));
- } else {
- $props->delete($props->getAdapter()->quoteInto('id = ?', $id));
- }
- }
- } else {
- $this->view->form = $form->populate($data);
- }
- $this->_helper->flashMessenger->addMessage('Категория обновлена');
- $this->_redirect($this->view->adminUrl('catalog', 'categories'));
- } else {
- $id = $this->_getParam('id');
- $data = $model->getByDataId($id, $this->_currentLanguageId);
- //Zend_Debug::dump($data);
- $this->view->form = $form->populate($data);
- $path = Core_Helper_Tree::branch($data['parent_id'], $model->getAll(false, $this->_currentLanguageId));
- $parts = array();
- foreach ($path as $p) {
- $parts[] = $p['title'];
- }
- $this->view->parent = $model->getByDataId($data['parent_id'], $this->_currentLanguageId);
- $this->view->path = implode(' / ', array_reverse($parts));
- $properties = new Catalog_Model_Categories_Properties;
- $this->view->properties = $properties->getCategory($id);
- $properties = new Catalog_Model_Properties;
- $this->view->propertiesList = $properties->getAdditional($id);
- $filters = new Catalog_Model_Filters;
- $this->view->filters = $filters->getCategory($id);
- $this->view->data = $data;
- $brands = new Catalog_Model_Brands;
- $this->view->brands = $brands->getCategory($id, true);
- $this->render('categories/edit');
- }
- break;
- /**
- * Сервисные, вспомогательные действия
- */
- case 'load':
- $model = new Catalog_Model_Categories;
- $list = $model->getJSON($this->_currentLanguageId);
- exit($list);
- break;
- case 'sort':
- $this->_helper->layout()->disableLayout();
- $array = json_decode($this->getRequest()->getPost('data'));
- if (!isset($array->parent)) {
- $model->setRuntimeOrdering($array);
- } else {
- $model->update(array('parent_id' => $array->parent), $model->getAdapter()->quoteInto('data_id = ?', $array->node));
- $model->setRuntimeOrdering($array->list);
- }
- break;
- case 'check-alias':
- $id = $this->_getParam('id');
- if (mb_strlen($this->_getParam('alias')))
- exit(!$model->get($this->_getParam('alias')) ? 'ok' : 'busy');
- exit('ok');
- break;
- case 'add-property':
- $model = new Catalog_Model_Properties;
- $this->_helper->layout()->disableLayout();
- $id = $this->_getParam('id', null);
- $existing = $this->_getParam('existing', false);
- if ($existing) {
- $propId = $this->_getParam('propId');
- } else {
- $data = $this->getRequest()->getPost();
- // exit(Zend_Debug::dump($data));
- unset($data['add_existing_property']);
- $propId = $model->insert($data);
- }
- if (is_null($id)) {
- $list = $model->getAll();
- $checked = false;
- } else {
- $model = new Catalog_Model_Categories_Properties;
- $model->insert(array(
- 'category_id' => $id,
- 'property_id' => $propId,
- 'img' => $data['img']
- ));
- $list = $model->getCategory($id);
- $checked = true;
- }
- exit($this->view->partial('admin/categories/service/categories.phtml', array('properties' => $list, 'checked' => $checked)));
- break;
- case 'add-properties':
- $model = new Catalog_Model_Categories_Properties;
- $this->_helper->layout()->disableLayout();
- $id = $this->_getParam('id', null);
- $data = $this->getRequest()->getPost();
- // exit(Zend_Debug::dump($data));
- $list = json_decode($data['list']);
- $extendProperties = json_decode($data['extendProperties']);
- $extendImages = json_decode($data['extendedImages']);
- //Zend_Debug::dump($extendImages);exit;
- //Zend_Debug::dump($extendProperties, 'ext');
- $catId = $data['extendedCategoryId'];
- foreach ($list as $propId) {
- $insert = array(
- 'category_id' => $id,
- 'property_id' => $propId
- );
- if (in_array($propId, $extendProperties)) {
- $insert['default_values'] = $model->getDefaults($catId, $propId);
- }
- if (in_array($propId, $extendImages)) {
- $insert['img'] = $model->getImg($catId, $propId);
- }
- // Zend_Debug::dump(in_array($extendProperties, $propId), 'in_arr');
- //Zend_Debug::dump($insert, 'ins');
- $model->insert($insert);
- //Zend_Debug::dump();
- }//exit;
- $list = $model->getCategory($id);
- $checked = true;
- exit($this->view->partial('admin/categories/service/categories.phtml', array('properties' => $list, 'checked' => $checked)));
- break;
- case 'unavailable-translations':
- $this->_helper->layout()->disableLayout();
- $model = new Catalog_Model_Categories;
- $translations = $model->getUnavailableTranslations($this->_getParam('id'));
- exit(json_encode($translations));
- break;
- default:
- $this->_breadcrumbs->addNode('Управление категориями');
- $show = $this->_getParam('show', null);
- if (!is_null($show)) {
- $model = new Catalog_Model_Products;
- $this->view->products = $model->getCategory($show);
- }
- $this->render('categories/list');
- break;
- }
- }
- /**
- * @title Характеристики
- * @description Управление динамическими характеристиками
- */
- public function propertiesAction() {
- $action = $this->_getParam('action', null);
- $model = new Catalog_Model_Properties;
- switch ($action) {
- case 'list': default:
- $this->_breadcrumbs->addNode('Список свойств');
- $data = $model->getAll();
- $this->view->list = $data;
- $this->render('properties/list');
- break;
- case 'add-property-image':
- $this->_breadcrumbs->addNode('FOO');
- $this->_helper->layout()->disableLayout();
- //exit('aaaa');
- $files = Core_Helper_File::receive();
- if (mb_strlen($files['images'][0])) {
- exit(json_encode(array('result' => 'success', 'img' => $files['images'][0])));
- } else {
- exit(json_encode(array('result' => 'success', 'img' => null)));
- }
- //Сервисная функция, асинхронная загрузка файла при добавлении свойства
- break;
- case 'change-property-image':
- $data = $this->getRequest()->getPost();
- $img = Core_Helper_File::receive();
- $img = $img['images'][0];
- $model = new Catalog_Model_Categories_Properties;
- $model->update(array('img' => $img), "property_id=" . $data['property_id'] . " AND category_id=" . $data['category_id']);
- exit(json_encode(array('result' => 'success', 'img' => $img)));
- break;
- case 'list-simple':
- $this->_helper->layout()->disableLayout();
- $id = $this->_getParam('id');
- $current = $this->_getParam('current', null);
- $data = $model->getAdditional($id);
- if (!is_null($current)) {
- $curr = $model->getAdditional($current);
- $data = array_diff_assoc($curr, $data);
- }
- //exit(Zend_Debug::dump($data));
- $this->view->list = $data;
- $this->view->current = $current;
- $this->render('properties/list-simple');
- break;
- case 'list-extend-simple':
- $this->_helper->layout()->disableLayout();
- $model = new Catalog_Model_Categories;
- $data = $model->getAll();
- $tree = new Core_Helper_Tree();
- $data = Core_Helper_Tree::build($data, 'parent_id', 'children', 'data_id');
- $this->view->list = $data;
- //Zend_Debug::dump($data);
- $this->render('properties/list-extend-simple');
- break;
- case 'edit':
- $this->_breadcrumbs->addUrl('Свойства', array(), 'catalog', 'properties')->addNode('Редактирование свойства');
- $form = new Catalog_Form_Properties_Edit;
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- if ($form->isValid($data)) {
- $id = $data['id'];
- unset($data['submit'], $data['id']);
- //exit(Zend_Debug::dump($data));
- $model->update($data, 'id=' . $id);
- $this->_helper->flashMessenger->addMessage('Данные обновлены');
- $this->_redirect($this->view->adminUrl('catalog', 'properties'));
- } else {
- $this->view->form = $form->populate($data);
- }
- } else {
- $id = $this->_getParam('id');
- $data = $model->getByPk($id);
- $this->view->form = $form->populate($data);
- }
- $this->render('properties/edit');
- break;
- case 'delete':
- $id = $this->_getParam('id');
- $model->update(array('deleted' => 1), 'id=' . $id);
- $this->_redirect($this->view->adminUrl('catalog', 'properties'));
- break;
- case 'load':
- $this->_helper->layout()->disableLayout();
- $parent = $this->_getParam('id');
- $properties = new Catalog_Model_Categories_Properties;
- $propertiesList = $properties->getCategory($parent);
- /**
- * Собираем доступные динамические характеристики
- */
- foreach ($propertiesList as &$v) {
- if (in_array($v['type'], array(Core_Input::TYPE_CHECKBOX, Core_Input::TYPE_RADIO, Core_Input::TYPE_SELECT))) {
- $values = explode(',', $v['default_values']);
- foreach ($values as $k => $val) {
- if (!mb_strlen($val)) {
- unset($values[$k]);
- }
- }
- if (count($values)) {
- array_walk($values, function(&$val, $key) {
- $val = trim($val);
- if (!mb_strlen($val)) {
- unset($values[$key]);
- }
- });
- switch ($v['type']) {
- case Core_Input::TYPE_SELECT:
- array_unshift($values, 'Выбрать');
- break;
- case Core_Input::TYPE_CHECKBOX:
- $v['element'] = 'formMultiCheckbox';
- break;
- case Core_Input::TYPE_RADIO:
- //No individual actions
- break;
- }
- $v['values'] = array_combine(array_values($values), array_values($values));
- } else {
- switch ($v['type']) {
- case Core_Input::TYPE_RADIO: case Core_Input::TYPE_SELECT:
- $v['values'] = array('1' => 'Да', '0' => 'Нет');
- break;
- case Core_Input::TYPE_CHECKBOX:
- $v['values'] = array('Да' => '1');
- break;
- }
- }
- }
- if (!isset($v['element']))
- $v['element'] = 'form' . ucfirst($v['type']);
- }
- $data = $this->view->partial('admin/categories/service/properties-ajax.phtml', array('properties' => $propertiesList));
- exit($data);
- break;
- }
- }
- /**
- * @title Управление записями
- * @description Управление материалами каталога
- *
- */
- public function productsAction() {
- $action = $this->_getParam('action');
- $model = new Catalog_Model_Products;
- switch ($action) {
- case 'add':
- $form = new Catalog_Form_Product_Add;
- $this->view->headScript()->appendFile('/admin_style/js/admin/catalog/attendant.js');
- $this->view->metagenerator()->enable();
- $this->_breadcrumbs->addNode('Добавление товара');
- $parent = $this->_getParam('parent', false);
- $ajax = $this->_getParam('ajax', false);
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- // if ($form->isValid($data)) {
- //exit(Zend_Debug::dump($data));
- $langId = null;
- if (APP_MULTILINGUAL) {
- $langId = $this->_currentLanguageId;
- }
- $properties = $data['properties'];
- $meta = $data['meta'];
- $imgAlts = $data['img_alt'];
- $additionals = $data['additionals'];
- $files = Core_Helper_File::receive();
- $moduleId = $model->getModuleId();
- unset($data['meta'], $data['properties'], $data['img_alt'], $data['img_file'], $data['submit'], $data['additionals']);
- $id = $model->_getNextDataId($langId);
- $data['ordering'] = $model->_getNextOrdering($langId);
- $data['data_id'] = $id;
- $data['lang_id'] = $langId;
- $model->insert($data);
- $meta['module_id'] = $moduleId;
- $meta['data_id'] = $id;
- if (APP_MULTILINGUAL) {
- $meta['lang_id'] = $langId;
- }
- $model = new Core_Model_Meta;
- $model->insert($meta);
- if (count($files['images'])) {
- $images = new Core_Model_Data_Images;
- foreach ($files['images'] as $i => $v) {
- $images->insert(array(
- 'module_id' => $moduleId,
- 'data_id' => $id,
- 'alt' => $imgAlts[$i],
- 'lang_id' => $langId,
- 'title' => $imgAlts[$i],
- 'file_path' => $v
- ));
- }
- }
- if (count($files['files'])) {
- $images = new Core_Model_Data_Files;
- foreach ($files['files'] as $i => $v) {
- $images->insert(array(
- 'module_id' => $moduleId,
- 'data_id' => $id,
- 'lang_id' => $langId,
- 'title' => $imgAlts[$i],
- 'file_path' => $v
- ));
- }
- }
- if (count($properties)) {
- //exit(Zend_Debug::dump($properties));
- $model = new Catalog_Model_Products_Properties;
- foreach ($properties as $propertyId => $property) {
- if (is_array($property)) {
- foreach ($property as $val) {
- $model->insert(array(
- 'product_id' => $id,
- 'property_id' => $propertyId,
- 'value' => $val
- ));
- }
- } else {
- $model->insert(array(
- 'product_id' => $id,
- 'property_id' => $propertyId,
- 'value' => $property
- ));
- }
- }
- }
- $additionals = explode(',', $additionals);
- $model = new Catalog_Model_Products_Attendant;
- foreach ($additionals as $v) {
- $model->insert(array(
- 'parent_id' => $id,
- 'attendant_id' => $v
- ));
- }
- $this->_helper->flashMessenger->addMessage('Данные добавлены');
- $this->_redirect($this->view->adminUrl('catalog', 'categories', array('show' => $data['category_id'])));
- // } else {
- // $this->view->form = $form->populate($data);
- // }
- } else {
- $categories = new Catalog_Model_Categories;
- $this->view->isNewProduct = true;
- if ($parent) {
- Catalog_Plugin_Metagenerator::setCategory($parent);
- $this->view->category = $categories->getByDataId($parent, $this->_currentLanguageId);
- $path = Core_Helper_Tree::branch($parent, $categories->getAll(true, $this->_currentLanguageId));
- $properties = new Catalog_Model_Categories_Properties;
- $parts = array();
- foreach ($path as $p) {
- $parts[] = $p['title'];
- }
- if (!count($parts)) {
- $parts[] = 'Корневая категория';
- }
- $this->view->path = implode(' / ', array_reverse($parts));
- $propertiesList = $properties->getCategory($parent);
- /**
- * Собираем доступные динамические характеристики
- */
- // Zend_Debug::dump($propertiesList);
- foreach ($propertiesList as &$v) {
- if (in_array($v['type'], array(Core_Input::TYPE_CHECKBOX, Core_Input::TYPE_RADIO, Core_Input::TYPE_SELECT))) {
- $values = explode(',', $v['default_values']);
- foreach ($values as $k => $val) {
- if (!mb_strlen($val)) {
- unset($values[$k]);
- }
- }
- if (count($values)) {
- array_walk($values, function(&$val, $key) {
- $val = trim($val);
- if (!mb_strlen($val)) {
- unset($values[$key]);
- }
- });
- switch ($v['type']) {
- case Core_Input::TYPE_SELECT:
- array_unshift($values, 'Выбрать');
- break;
- case Core_Input::TYPE_CHECKBOX:
- $v['element'] = 'formMultiCheckbox';
- break;
- case Core_Input::TYPE_RADIO:
- //No individual actions
- break;
- }
- $v['values'] = array_combine(array_values($values), array_values($values));
- } else {
- switch ($v['type']) {
- case Core_Input::TYPE_RADIO: case Core_Input::TYPE_SELECT:
- $v['values'] = array('1' => 'Да', '0' => 'Нет');
- break;
- case Core_Input::TYPE_CHECKBOX:
- $v['values'] = array('Да' => '1');
- break;
- }
- }
- }
- if (!isset($v['element']))
- $v['element'] = 'form' . ucfirst($v['type']);
- }
- if ($ajax) {
- $data = $this->view->partial('admin/categories/service/properties-ajax.phtml', array('properties' => $propertiesList));
- exit($data);
- } else {
- $this->view->properties = $propertiesList;
- }
- /**
- * /Подготовили и передали во view
- */
- } else {
- $list = $categories->getJSON();
- $this->view->list = $list;
- }
- }
- $this->view->parent = $parent;
- $this->view->form = $form;
- $this->render('products/add');
- break;
- case 'check-alias':
- $model = new Core_Model_Meta;
- $id = $this->_getParam('id');
- if (mb_strlen($this->_getParam('alias')))
- exit(!$model->checkAlias($this->_getParam('alias')) ? 'ok' : 'busy');
- exit('ok');
- break;
- case 'loadcategory':
- //exit('Мультиязычный вывод товаров в разработке!');
- $this->_helper->layout()->disableLayout();
- $id = $this->_getParam('id');
- //Патч для рассылки, убираем лишние кнопки, дабы не плодить views.
- //Если передан параметр nocontrols - просто вывести список товаров с галочками
- $noControls = (bool) $this->_getParam('nocontrols');
- $data = $model->getAdminCategory($id, $this->_currentLanguageId);
- $content = $this->view->partial('admin/products/list-ajax.phtml', array('list' => $data, 'noControls' => $noControls));
- exit($content);
- break;
- case 'add-color':
- $this->_breadcrumbs->addNode('Добавление цвета для продукта');
- $this->view->headScript()->appendFile('/admin_style/js/jquery.validate.pack.js');
- $this->view->headScript()->appendFile('/admin_style/js/admin/meta_generator/init.js');
- $form = new Catalog_Form_Product_AddColor;
- $properties = new Catalog_Model_Products_Properties;
- if ($this->getRequest()->isPost()) {
- $model = new Catalog_Model_Products;
- $data = $this->getRequest()->getPost();
- $properties = $data['properties'];
- $meta = $data['meta'];
- $imgAlts = $data['img_alt'];
- $additionals = $data['additionals'];
- $files = Core_Helper_File::receive();
- $moduleId = $model->getModuleId();
- unset($data['meta'], $data['properties'], $data['img_alt'], $data['img_file'], $data['submit'], $data['additionals']);
- $id = $model->_getNextDataId();
- $data['ordering'] = $model->_getNextOrdering();
- $data['data_id'] = $id;
- $data['parent_id'] = (int) $_GET['id'];
- $info = $model->getByDataId($data['parent_id']);
- $data['category_id'] = $info['category_id'];
- //exit(Zend_Debug::dump($data));
- $model->insert($data);
- $meta['module_id'] = $moduleId;
- $meta['data_id'] = $id;
- $model = new Core_Model_Meta;
- $model->insert($meta);
- if (count($files['images'])) {
- $images = new Core_Model_Data_Images;
- foreach ($files['images'] as $i => $v) {
- $images->insert(array(
- 'module_id' => $moduleId,
- 'data_id' => $id,
- 'alt' => $imgAlts[$i],
- 'title' => $imgAlts[$i],
- 'file_path' => $v
- ));
- }
- }
- if (count($files['files'])) {
- $images = new Core_Model_Data_Files;
- foreach ($files['files'] as $i => $v) {
- $images->insert(array(
- 'module_id' => $moduleId,
- 'data_id' => $id,
- 'title' => $imgAlts[$i],
- 'file_path' => $v
- ));
- }
- }
- if (count($properties)) {
- //exit(Zend_Debug::dump($properties));
- $model = new Catalog_Model_Products_Properties;
- foreach ($properties as $propertyId => $property) {
- if (is_array($property)) {
- foreach ($property as $val) {
- $model->insert(array(
- 'product_id' => $id,
- 'property_id' => $propertyId,
- 'value' => $val
- ));
- }
- } else {
- $model->insert(array(
- 'product_id' => $id,
- 'property_id' => $propertyId,
- 'value' => $property
- ));
- }
- }
- }
- $this->_helper->flashMessenger->addMessage('Данные добавлены');
- $this->_redirect($this->view->adminUrl('catalog', 'products', array('action' => 'edit', 'id' => (int) $_GET['id'], 'hash' => 'colours')));
- } else {
- //exit('aaa');
- // echo $this->view->adminUrl('catalog', 'products', array('action'=>'edit', 'id'=>2, 'hash'=>'colours'));
- // exit;
- $id = $this->_getParam('id');
- $data = $model->getByDataId($id);
- $meta = new Core_Model_Meta;
- $data['meta'] = $meta->getMeta($id);
- $images = new Core_Model_Data_Images;
- $this->view->images = $images->getData($id);
- $files = new Core_Model_Data_Files();
- $this->view->files = $files->getData($id);
- $this->view->form = $form->populate($data);
- $propertiesList = $properties->getProduct($id);
- $this->view->properties = $propertiesList;
- $this->view->isColorOf = $id;
- $this->render('products/add-color');
- }
- break;
- case 'edit':
- $this->view->headScript()->appendFile('/admin_style/js/admin/catalog/attendant.js');
- $this->view->metagenerator()->enable();
- $form = new Catalog_Form_Product_Edit;
- $properties = new Catalog_Model_Products_Properties;
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- // exit(Zend_Debug::dump($data));
- // if ($form->isValid($data)) {
- $dataId = $data['data_id'];
- $propertiesList = $data['properties'];
- $langId = null;
- if (APP_MULTILINGUAL) {
- $langId = $this->_currentLanguageId;
- }
- // exit(Zend_Debug::dump($propertiesList));
- $meta = new Core_Model_Meta;
- $moduleId = $meta->getModuleId();
- $aliasExists = $meta->checkAlias($data['meta']['alias'], $dataId, null, $langId) && mb_strlen($data['meta_alias']);
- if (!$aliasExists) {
- $files = Core_Helper_File::receive();
- $imgAlts = $data['img_alt'];
- // exit(Zend_Debug::dump($files));
- if (APP_MULTILINGUAL) {
- $meta->update($data['meta'], array(
- $meta->getAdapter()->quoteInto('data_id = ?', $dataId),
- $meta->getAdapter()->quoteInto('module_id = ?', $moduleId),
- $meta->getAdapter()->quoteInto('lang_id = ?', $langId)
- ));
- } else {
- $meta->update($data['meta'], array(
- $meta->getAdapter()->quoteInto('data_id = ?', $dataId),
- $meta->getAdapter()->quoteInto('module_id = ?', $moduleId)
- ));
- }
- $additionals = explode(',', $data['additionals']);
- unset($data['submit'], $data['properties'], $data['meta'], $data['img_file'], $data['img_alt'], $data['additionals']);
- $model->update($data, $model->getAdapter()->quoteInto('data_id = ?', $dataId)); //Обновляем основную информацию о товаре
- $properties->delete($properties->getAdapter()->quoteInto('product_id = ?', $dataId));
- if (count($propertiesList)) {
- $properties->delete('product_id = ' . $dataId);
- //exit(Zend_Debug::dump($properties));
- foreach ($propertiesList as $propertyId => $property) {
- if (is_array($property)) {
- foreach ($property as $val) {
- $properties->insert(array(
- 'product_id' => $dataId,
- 'property_id' => $propertyId,
- 'value' => $val
- ));
- }
- } else {
- $properties->insert(array(
- 'product_id' => $dataId,
- 'property_id' => $propertyId,
- 'value' => $property
- ));
- }
- }
- }
- if (count($files['images'])) {
- $images = new Core_Model_Data_Images;
- foreach ($files['images'] as $i => $v) {
- $images->insert(array(
- 'module_id' => $moduleId,
- 'data_id' => $dataId,
- 'lang_id' => $langId,
- 'alt' => $imgAlts[$i],
- 'title' => $imgAlts[$i],
- 'file_path' => $v
- ));
- }
- }
- if (count($files['files'])) {
- $images = new Core_Model_Data_Files;
- foreach ($files['files'] as $i => $v) {
- $images->insert(array(
- 'module_id' => $moduleId,
- 'data_id' => $dataId,
- 'lang_id' => $langId,
- 'title' => $imgAlts[$i],
- 'file_path' => $v
- ));
- }
- }
- $model = new Catalog_Model_Products_Attendant;
- $model->delete('parent_id = ' . $dataId);
- foreach ($additionals as $v) {
- $model->insert(array(
- 'parent_id' => $dataId,
- 'attendant_id' => $v
- ));
- }
- $this->_helper->flashMessenger->addMessage('Данные обновлены');
- $this->_redirect($this->view->adminUrl('catalog', 'categories', array('show' => $data['category_id'])));
- } else {
- echo "ALIAS!";
- }
- //$meta->update($data['meta'], $v);
- // } else {
- // $this->vire->form = $form->populate($data);
- // }
- //Zend_Debug::dump($data);
- } else {
- $id = $this->_getParam('id');
- $data = $model->getByDataId($id, $this->_currentLanguageId);
- $this->view->isColorOf = (bool) $this->_getParam('isColorOf');
- $this->view->colors = $model->getColors($id);
- $meta = new Core_Model_Meta;
- $data['meta'] = $meta->getMeta($id, $this->_currentLanguageId);
- $images = new Core_Model_Data_Images;
- $this->view->images = $images->getData($id, $this->_currentLanguageId);
- $files = new Core_Model_Data_Files();
- $this->view->files = $files->getData($id, $this->_currentLanguageId);
- $this->view->form = $form->populate($data);
- $propertiesList = $properties->getProduct($id, $this->_currentLanguageId);
- $this->view->properties = $propertiesList;
- $this->view->data = $data;
- $attendant = new Catalog_Model_Products_Attendant();
- $attendant = $attendant->getProduct($id);
- $this->view->attendant = $attendant;
- $attIds = array();
- foreach ($attendant as $v) {
- $attIds[] = $v['data_id'];
- }
- $this->view->additionalsList = implode(',', $attIds);
- $this->render('products/edit');
- }
- break;
- case 'delete':
- $id = $this->_getParam('id');
- $model = new Catalog_Model_Products;
- $data = $model->getByDataId($id);
- $model->del($id);
- $this->_redirect($this->view->adminUrl('catalog', 'categories', array('show' => $data['category_id'])));
- exit;
- break;
- case 'delete-color':
- $id = $this->_getParam('id');
- $model = new Catalog_Model_Products;
- $data = $model->getByDataId($id);
- $model->del($id);
- $this->_redirect($this->view->adminUrl('catalog', 'products', array('action' => 'edit', 'id' => $data['parent_id'], 'hash' => 'colours')));
- exit;
- break;
- }
- }
- /**
- * @title Настройки модуля
- * @description Управление настройками модуля
- */
- public function settingsAction() {
- $action = $this->_getParam('action', 'index');
- $form = new Catalog_Form_Settings;
- $model = new Catalog_Model_Settings();
- $this->_breadcrumbs->addNode('Настройки модуля');
- switch ($action) {
- case 'index': default:
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- unset($data['submit']);
- //exit(Zend_Debug::dump($data));
- foreach ($data as $prop => $value) {
- $model->update(array('value' => $value), "prop='$prop'");
- }
- $this->_helper->flashMessenger->addMessage('Настройки успешно обновлены');
- $this->_redirect($this->view->adminUrl('catalog', 'settings'));
- } else {
- $this->view->message = array_pop(array_merge($this->_helper->flashMessenger->getMessages(), $this->_helper->flashMessenger->getCurrentMessages()));
- $this->view->form = $form;
- }
- $this->render('settings/index');
- break;
- }
- }
- /**
- * @title Поиск по каталогу
- * @description Поиск внутри админки
- * @service
- */
- public function searchAction() {
- if ($this->getRequest()->isXMLHttpRequest()) {
- $this->_helper->layout()->disableLayout();
- $model = new Catalog_Model_Products;
- $phrase = urldecode($this->_getParam('q'));
- $data = $model->search($phrase);
- exit(json_encode($data));
- }
- }
- /**
- * @title Фильтры
- * @description Управление фильтрами
- */
- public function filtersAction() {
- $this->_breadcrumbs->addNode('Управление фильтрами');
- $action = $this->_getParam('action');
- $model = new Catalog_Model_Filters();
- switch ($action) {
- case 'delete':
- $id = $this->_getParam('id');
- $model = new Catalog_Model_Filters;
- $model->delete('id = ' . $id);
- $model = new Catalog_Model_Filters_Values;
- $model->delete('filter_id=' . $id);
- $this->_redirect($_SERVER['HTTP_REFERER']);
- break;
- case 'create':
- $step = $this->_getParam('step', 1);
- switch ($step) {
- case 1:
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- $categoryId = $this->_getParam('cat');
- $data['category_id'] = $categoryId;
- $id = $model->insert($data); //ИД фильтра
- $this->_redirect($this->view->adminUrl('catalog', 'filters', array('action' => 'create', 'step' => 2, 'id' => $id, 'cat' => $categoryId)));
- } else {
- $cat = $this->_getParam('cat');
- $settings = new Catalog_Model_Settings();
- $props = new Catalog_Model_Categories_Properties;
- $list = $props->getCategory($cat);
- if ($settings->enable_price) {
- $list[] = array('title' => 'Цена',
- 'property_id' => 'price');
- }
- if ($settings->enable_colors) {
- $list[] = array('title' => 'Цвета',
- 'property_id' => 'color');
- }
- //exit(Zend_Debug::dump($list));
- $this->view->fields = $list;
- $this->render('filters/create/step1');
- }
- break;
- case 2:
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- $categoryId = $this->_getParam('cat');
- $id = $this->_getParam('id');
- $this->_redirect($this->view->adminUrl('catalog', 'filters', array(
- 'action' => 'create',
- 'step' => 3,
- 'id' => $id,
- 'cat' => $categoryId,
- 'field' => $data['field']
- )));
- //exit(Zend_Debug::dump($data));
- } else {
- $id = $this->_getParam('id');
- $info = $model->getByPk($id);
- $cat = $this->_getParam('cat');
- $settings = new Catalog_Model_Settings();
- $props = new Catalog_Model_Categories_Properties;
- $list = $props->getCategory($cat);
- if ($settings->enable_price) {
- $list[] = array('title' => 'Цена',
- 'property_id' => 'price');
- }
- if ($settings->enable_colors) {
- $list[] = array('title' => 'Цвета',
- 'property_id' => 'color');
- }
- //exit(Zend_Debug::dump($list));
- $this->view->fields = $list;
- $this->view->info = $info;
- $this->render('filters/create/step2');
- }
- break;
- case 3:
- $filters = new Catalog_Model_Filters();
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- if (!isset($data['price_hidden'])) {
- $redirectToCategory = isset($data['end']);
- unset($data['end']);
- // exit(Zend_Debug::dump($data));
- $data['property_id'] = $this->_getParam('field');
- $data['filter_id'] = $this->_getParam('id');
- $model = new Catalog_Model_Filters_Values();
- $id = $model->insert($data);
- //exit(var_dump($id));
- if (!$redirectToCategory) {
- $this->_redirect($_SERVER['HTTP_REFERER']);
- } else {
- }
- } else {
- $data['property_id'] = -1; //-1 Статично для цены
- $data['filter_id'] = $this->_getParam('id');
- $priceType = $data['price_type'];
- unset($data['price_type'], $data['price_hidden']);
- switch ($priceType) {
- case 'auto':
- $model = new Catalog_Model_Filters_Values();
- $id = $model->insert($data);
- $this->_redirect($this->view->adminUrl('catalog', 'categories', array(
- 'action' => 'edit',
- 'id' => $this->_getParam('cat')
- )));
- break;
- }
- }
- } else {
- //exit(Zend_Debug::dump('aaa'));
- $props = new Catalog_Model_Categories_Properties;
- $properties = new Catalog_Model_Properties;
- $cat = $this->_getParam('cat'); //ID категории
- $prop = $this->_getParam('field'); //ID поля
- $id = $this->_getParam('id'); //ID фильтра
- if ($prop == 'price') {
- $this->render('filters/create/price/type');
- } elseif ($prop == 'color') {
- $data['property_id'] = $this->_getParam('field');
- $data['filter_id'] = '-2'; //-2 статично для цветовых решений
- $model = new Catalog_Model_Filters_Values();
- $id = $model->insert($data);
- $this->_redirect($this->view->adminUrl('catalog', 'categories', array(
- 'action' => 'edit',
- 'id' => $this->_getParam('cat')
- )));
- } else {
- $defaults = $props->getDefaults($cat, $prop);
- $this->view->defaults = $defaults;
- $this->view->filter = $filters->getByPk($id);
- $this->view->property = $properties->getByPk($prop);
- $this->render('filters/create/step3');
- }
- }
- break;
- }
- break;
- case 'edit':
- if ($this->getRequest()->isPost()) {
- } else {
- $this->view->form = true;
- }
- $this->render('filters/edit');
- break;
- }
- }
- /**
- * @title Управление цветами
- * @description Цветовые решения для продуктов
- */
- public function coloursAction() {
- $this->_breadcrumbs->addNode('Управление цветами');
- $action = $this->_getParam('action');
- $model = new Catalog_Model_Colours;
- switch ($action) {
- case 'index': default:
- $data = $model->getAll();
- $this->view->list = $data;
- $this->render('colours/list');
- break;
- case 'add':
- $this->view->headScript()->appendFile('/admin_style/js/jscolor/jscolor.js');
- $form = new Catalog_Form_Colours_Add;
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- if ($form->isValid($data)) {
- unset($data['submit']);
- $model->insert($data);
- $this->_redirect($this->view->adminUrl('catalog', 'colours'));
- } else {
- $this->view->form = $form->populate($data);
- }
- } else {
- $this->view->form = $form;
- }
- $this->render('colours/add');
- break;
- case 'delete':
- $id = $this->_getParam('id');
- $model->delete('id=' . $id);
- $this->_redirect($this->view->adminUrl('catalog', 'colours'));
- break;
- case 'edit':
- $this->view->headScript()->appendFile('/admin_style/js/jscolor/jscolor.js');
- $form = new Catalog_Form_Colours_Edit;
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost();
- $id = $data['id'];
- unset($data['id'], $data['submit']);
- $model->update($data, 'id=' . $id);
- $this->_redirect($this->view->adminUrl('catalog', 'colours'));
- } else {
- $id = $this->_getParam('id');
- $this->view->form = $form->populate($model->getByPk($id));
- $this->render('colours/add');
- }
- break;
- }
- }
- /**
- * @title Автоматический генератор мета-тегов
- * @description Управление автоматической генерацией мета-данных
- * @service
- */
- public function metageneratorAction() {
- $action = $this->_getParam('action');
- switch ($action) {
- case 'product-template':
- $this->_helper->layout()->disableLayout();
- $id = $this->_getParam('category');
- $model = new Catalog_Model_Categories;
- exit(json_encode($model->getMetaTemplate($id)));
- break;
- }
- }
- protected function _recursive($array) {
- static $return = array();
- foreach ($array as $k => $v) {
- foreach ($v->children as $cid => $c) {
- $return[] = array(
- 'title' => $c->title,
- 'parent_title' => $v->title,
- 'parent_id' => str_replace('f', '', $v->key),
- 'id' => str_replace('f', '', $c->key),
- 'link' => mb_strlen($c->href) ? $c->href : '',
- 'ordering' => $cid
- );
- }
- $this->_recursive($v);
- }
- return $return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement