/controllers/admin/AdminShopController.php
PHP | 865 lines | 668 code | 101 blank | 96 comment | 114 complexity | 5d4426de3c249b660475b3ff6ad28db9 MD5 | raw file
- <?php
- /*
- * 2007-2015 PrestaShop
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@prestashop.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
- * versions in the future. If you wish to customize PrestaShop for your
- * needs please refer to http://www.prestashop.com for more information.
- *
- * @author PrestaShop SA <contact@prestashop.com>
- * @copyright 2007-2015 PrestaShop SA
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * International Registered Trademark & Property of PrestaShop SA
- */
- /**
- * @property Shop $object
- */
- class AdminShopControllerCore extends AdminController
- {
- public function __construct()
- {
- $this->bootstrap = true;
- $this->context = Context::getContext();
- $this->table = 'shop';
- $this->className = 'Shop';
- $this->multishop_context = Shop::CONTEXT_ALL;
-
- $this->id_shop_group = (int)Tools::getValue('id_shop_group');
- /* if $_GET['id_shop'] is transmitted, virtual url can be loaded in config.php, so we wether transmit shop_id in herfs */
- if ($this->id_shop = (int)Tools::getValue('shop_id')) {
- $_GET['id_shop'] = $this->id_shop;
- }
- $this->list_skip_actions['delete'] = array((int)Configuration::get('PS_SHOP_DEFAULT'));
- $this->fields_list = array(
- 'id_shop' => array(
- 'title' => $this->l('Shop ID'),
- 'align' => 'center',
- 'class' => 'fixed-width-xs'
- ),
- 'name' => array(
- 'title' => $this->l('Shop name'),
- 'filter_key' => 'a!name',
- 'width' => 200,
- ),
- 'shop_group_name' => array(
- 'title' => $this->l('Shop group'),
- 'width' => 150,
- 'filter_key' => 'gs!name'
- ),
- 'category_name' => array(
- 'title' => $this->l('Root category'),
- 'width' => 150,
- 'filter_key' => 'cl!name'
- ),
- 'url' => array(
- 'title' => $this->l('Main URL for this shop'),
- 'havingFilter' => 'url',
- ),
- /*'active' => array(
- 'title' => $this->l('Enabled'),
- 'align' => 'center',
- 'active' => 'status',
- 'type' => 'bool',
- 'orderby' => false,
- 'filter_key' => 'active',
- 'width' => 50,
- )*/
- );
- parent::__construct();
- }
- public function viewAccess($disable = false)
- {
- return Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE');
- }
- public function initPageHeaderToolbar()
- {
- parent::initPageHeaderToolbar();
- if (!$this->display && $this->id_shop_group) {
- if ($this->id_object) {
- $this->loadObject();
- }
- if (!$this->id_shop_group && $this->object && $this->object->id_shop_group) {
- $this->id_shop_group = $this->object->id_shop_group;
- }
- $this->page_header_toolbar_btn['edit'] = array(
- 'desc' => $this->l('Edit this shop group'),
- 'href' => $this->context->link->getAdminLink('AdminShopGroup').'&updateshop_group&id_shop_group='
- .$this->id_shop_group,
- );
- $this->page_header_toolbar_btn['new'] = array(
- 'desc' => $this->l('Add new shop'),
- 'href' => $this->context->link->getAdminLink('AdminShop').'&add'.$this->table.'&id_shop_group='
- .$this->id_shop_group,
- );
- }
- }
- public function initToolbar()
- {
- parent::initToolbar();
- if ($this->display != 'edit' && $this->display != 'add') {
- if ($this->id_object) {
- $this->loadObject();
- }
- if (!$this->id_shop_group && $this->object && $this->object->id_shop_group) {
- $this->id_shop_group = $this->object->id_shop_group;
- }
- $this->toolbar_btn['new'] = array(
- 'desc' => $this->l('Add new shop'),
- 'href' => $this->context->link->getAdminLink('AdminShop').'&add'.$this->table.'&id_shop_group='
- .$this->id_shop_group,
- );
- }
- }
- public function initContent()
- {
- parent::initContent();
- $this->addJqueryPlugin('cooki-plugin');
- $data = Shop::getTree();
- foreach ($data as $key_group => &$group) {
- foreach ($group['shops'] as $key_shop => &$shop) {
- $current_shop = new Shop($shop['id_shop']);
- $urls = $current_shop->getUrls();
- foreach ($urls as $key_url => &$url) {
- $title = $url['domain'].$url['physical_uri'].$url['virtual_uri'];
- if (strlen($title) > 23) {
- $title = substr($title, 0, 23).'...';
- }
- $url['name'] = $title;
- $shop['urls'][$url['id_shop_url']] = $url;
- }
- }
- }
- $shops_tree = new HelperTreeShops('shops-tree', $this->l('Multistore tree'));
- $shops_tree->setNodeFolderTemplate('shop_tree_node_folder.tpl')->setNodeItemTemplate('shop_tree_node_item.tpl')
- ->setHeaderTemplate('shop_tree_header.tpl')->setActions(array(
- new TreeToolbarLink(
- 'Collapse All',
- '#',
- '$(\'#'.$shops_tree->getId().'\').tree(\'collapseAll\'); return false;',
- 'icon-collapse-alt'),
- new TreeToolbarLink(
- 'Expand All',
- '#',
- '$(\'#'.$shops_tree->getId().'\').tree(\'expandAll\'); return false;',
- 'icon-expand-alt')
- ))
- ->setAttribute('url_shop_group', $this->context->link->getAdminLink('AdminShopGroup'))
- ->setAttribute('url_shop', $this->context->link->getAdminLink('AdminShop'))
- ->setAttribute('url_shop_url', $this->context->link->getAdminLink('AdminShopUrl'))
- ->setData($data);
- $shops_tree = $shops_tree->render(null, false, false);
- if ($this->display == 'edit') {
- $this->toolbar_title[] = $this->object->name;
- } elseif (!$this->display && $this->id_shop_group) {
- $group = new ShopGroup($this->id_shop_group);
- $this->toolbar_title[] = $group->name;
- }
- $this->context->smarty->assign(array(
- 'toolbar_scroll' => 1,
- 'toolbar_btn' => $this->toolbar_btn,
- 'title' => $this->toolbar_title,
- 'shops_tree' => $shops_tree
- ));
- }
- public function renderList()
- {
- $this->addRowAction('edit');
- $this->addRowAction('delete');
- $this->_select = 'gs.name shop_group_name, cl.name category_name, CONCAT(\'http://\', su.domain, su.physical_uri, su.virtual_uri) AS url';
- $this->_join = '
- LEFT JOIN `'._DB_PREFIX_.'shop_group` gs
- ON (a.id_shop_group = gs.id_shop_group)
- LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
- ON (a.id_category = cl.id_category AND cl.id_lang='.(int)$this->context->language->id.')
- LEFT JOIN '._DB_PREFIX_.'shop_url su
- ON a.id_shop = su.id_shop AND su.main = 1
- ';
- $this->_group = 'GROUP BY a.id_shop';
- if ($id_shop_group = (int)Tools::getValue('id_shop_group')) {
- $this->_where = 'AND a.id_shop_group = '.$id_shop_group;
- }
- return parent::renderList();
- }
- public function displayAjaxGetCategoriesFromRootCategory()
- {
- if (Tools::isSubmit('id_category')) {
- $selected_cat = array((int)Tools::getValue('id_category'));
- $children = Category::getChildren((int)Tools::getValue('id_category'), $this->context->language->id);
- foreach ($children as $child) {
- $selected_cat[] = $child['id_category'];
- }
- $helper = new HelperTreeCategories('categories-tree', null, (int)Tools::getValue('id_category'), null, false);
- $this->content = $helper->setSelectedCategories($selected_cat)->setUseSearch(true)->setUseCheckBox(true)
- ->render();
- }
- parent::displayAjax();
- }
- public function postProcess()
- {
- if (Tools::isSubmit('id_category_default')) {
- $_POST['id_category'] = Tools::getValue('id_category_default');
- }
- /*if ((Tools::isSubmit('status') ||
- Tools::isSubmit('status'.$this->table) ||
- (Tools::isSubmit('submitAdd'.$this->table) && Tools::getValue($this->identifier) && !Tools::getValue('active'))) &&
- $this->loadObject() && $this->loadObject()->active)
- {