/** * @return int Total of shop groups */ public static function getTotalShopGroup($active = true) { return count(ShopGroup::getShopGroups($active)); }
public static function list_groups() { $groups = ShopGroup::getShopGroups(false); $table = new Cli\Table(); $table->setHeaders(array('id', 'name', 'share customers', 'share orders', 'share stock', 'active', 'deleted')); foreach ($groups as $group) { $fields = $group->getFields(); $table->addRow(array($fields['id_shop_group'], $fields['name'], $fields['share_customer'], $fields['share_order'], $fields['share_stock'], $fields['active'], $fields['deleted'])); } $table->display(); }
public function renderForm() { if (!($obj = $this->loadObject(true))) { return; } $this->fields_form = array('legend' => array('title' => $this->l('Shop'), 'icon' => 'icon-shopping-cart'), 'input' => array(array('type' => 'text', 'label' => $this->l('Shop name'), 'desc' => array($this->l('This field does not refer to the shop name visible in the front office.'), sprintf($this->l('Follow %sthis link%s to edit the shop name used on the Front Office.'), '<a href="' . $this->context->link->getAdminLink('AdminStores') . '#store_fieldset_general">', '</a>')), 'name' => 'name', 'required' => true))); $display_group_list = true; if ($this->display == 'edit') { $group = new ShopGroup($obj->id_shop_group); if ($group->share_customer || $group->share_order || $group->share_stock) { $display_group_list = false; } } if ($display_group_list) { $options = array(); foreach (ShopGroup::getShopGroups() as $group) { if ($this->display == 'edit' && ($group->share_customer || $group->share_order || $group->share_stock) && ShopGroup::hasDependency($group->id)) { continue; } $options[] = array('id_shop_group' => $group->id, 'name' => $group->name); } if ($this->display == 'add') { $group_desc = $this->l('Warning: You won\'t be able to change the group of this shop if this shop belongs to a group with one of these options activated: Share Customers, Share Quantities or Share Orders.'); } else { $group_desc = $this->l('You can only move your shop to a shop group with all "share" options disabled -- or to a shop group with no customers/orders.'); } $this->fields_form['input'][] = array('type' => 'select', 'label' => $this->l('Shop group'), 'desc' => $group_desc, 'name' => 'id_shop_group', 'options' => array('query' => $options, 'id' => 'id_shop_group', 'name' => 'name')); } else { $this->fields_form['input'][] = array('type' => 'hidden', 'name' => 'id_shop_group', 'default' => $group->name); $this->fields_form['input'][] = array('type' => 'textShopGroup', 'label' => $this->l('Shop group'), 'desc' => $this->l('You can\'t edit the shop group because the current shop belongs to a group with the "share" option enabled.'), 'name' => 'id_shop_group', 'value' => $group->name); } $categories = Category::getRootCategories($this->context->language->id); $this->fields_form['input'][] = array('type' => 'select', 'label' => $this->l('Category root'), 'desc' => $this->l('This is the root category of the store that you\'ve created. To define a new root category for your store,') . ' <a href="' . $this->context->link->getAdminLink('AdminCategories') . '&addcategoryroot" target="_blank">' . $this->l('Please click here') . '</a>', 'name' => 'id_category', 'options' => array('query' => $categories, 'id' => 'id_category', 'name' => 'name')); if (Tools::isSubmit('id_shop')) { $shop = new Shop((int) Tools::getValue('id_shop')); $id_root = $shop->id_category; } else { $id_root = $categories[0]['id_category']; } $id_shop = (int) Tools::getValue('id_shop'); self::$currentIndex = self::$currentIndex . '&id_shop_group=' . (int) (Tools::getValue('id_shop_group') ? Tools::getValue('id_shop_group') : (isset($obj->id_shop_group) ? $obj->id_shop_group : Shop::getContextShopGroupID())); $shop = new Shop($id_shop); $selected_cat = Shop::getCategories($id_shop); if (empty($selected_cat)) { // get first category root and preselect all these children $root_categories = Category::getRootCategories(); $root_category = new Category($root_categories[0]['id_category']); $children = $root_category->getAllChildren($this->context->language->id); $selected_cat[] = $root_categories[0]['id_category']; foreach ($children as $child) { $selected_cat[] = $child->id; } } if (Shop::getContext() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) { $root_category = new Category($shop->id_category); } else { $root_category = new Category($id_root); } $this->fields_form['input'][] = array('type' => 'categories', 'name' => 'categoryBox', 'label' => $this->l('Associated categories'), 'tree' => array('id' => 'categories-tree', 'selected_categories' => $selected_cat, 'root_category' => $root_category->id, 'use_search' => true, 'use_checkbox' => true), 'desc' => $this->l('By selecting associated categories, you are choosing to share the categories between shops. Once associated between shops, any alteration of this category will impact every shop.')); /*$this->fields_form['input'][] = array( 'type' => 'switch', 'label' => $this->l('Enabled'), 'name' => 'active', 'required' => true, 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1 ), array( 'id' => 'active_off', 'value' => 0 ) ), 'desc' => $this->l('Enable or disable your store?') );*/ $themes = Theme::getThemes(); if (!isset($obj->id_theme)) { foreach ($themes as $theme) { if (isset($theme->id)) { $id_theme = $theme->id; break; } } } $this->fields_form['input'][] = array('type' => 'theme', 'label' => $this->l('Theme'), 'name' => 'theme', 'values' => $themes); $this->fields_form['submit'] = array('title' => $this->l('Save')); if (Shop::getTotalShops() > 1 && $obj->id) { $disabled = array('active' => false); } else { $disabled = false; } $import_data = array('carrier' => $this->l('Carriers'), 'cms' => $this->l('CMS pages'), 'contact' => $this->l('Contact information'), 'country' => $this->l('Countries'), 'currency' => $this->l('Currencies'), 'discount' => $this->l('Discount prices'), 'employee' => $this->l('Employees'), 'image' => $this->l('Images'), 'lang' => $this->l('Languages'), 'manufacturer' => $this->l('Manufacturers'), 'module' => $this->l('Modules'), 'hook_module' => $this->l('Module hooks'), 'meta_lang' => $this->l('Meta'), 'product' => $this->l('Products'), 'product_attribute' => $this->l('Combinations'), 'scene' => $this->l('Scenes'), 'stock_available' => $this->l('Available quantities for sale'), 'store' => $this->l('Stores'), 'warehouse' => $this->l('Warehouses'), 'webservice_account' => $this->l('Webservice accounts'), 'attribute_group' => $this->l('Attribute groups'), 'feature' => $this->l('Features'), 'group' => $this->l('Customer groups'), 'tax_rules_group' => $this->l('Tax rules groups'), 'supplier' => $this->l('Suppliers'), 'referrer' => $this->l('Referrers/affiliates'), 'zone' => $this->l('Zones'), 'cart_rule' => $this->l('Cart rules')); // Hook for duplication of shop data $modules_list = Hook::getHookModuleExecList('actionShopDataDuplication'); if (is_array($modules_list) && count($modules_list) > 0) { foreach ($modules_list as $m) { $import_data['Module' . ucfirst($m['module'])] = Module::getModuleName($m['module']); } } asort($import_data); if (!$this->object->id) { $this->fields_import_form = array('radio' => array('type' => 'radio', 'label' => $this->l('Import data'), 'name' => 'useImportData', 'value' => 1), 'select' => array('type' => 'select', 'name' => 'importFromShop', 'label' => $this->l('Choose the shop (source)'), 'options' => array('query' => Shop::getShops(false), 'name' => 'name')), 'allcheckbox' => array('type' => 'checkbox', 'label' => $this->l('Choose data to import'), 'values' => $import_data), 'desc' => $this->l('Use this option to associate data (products, modules, etc.) the same way for each selected shop.')); } $this->fields_value = array('id_shop_group' => Tools::getValue('id_shop_group') ? Tools::getValue('id_shop_group') : isset($obj->id_shop_group) ? $obj->id_shop_group : Shop::getContextShopGroupID(), 'id_category' => Tools::getValue('id_category') ? Tools::getValue('id_category') : isset($obj->id_category) ? $obj->id_category : (int) Configuration::get('PS_HOME_CATEGORY'), 'id_theme_checked' => isset($obj->id_theme) ? $obj->id_theme : $id_theme); $ids_category = array(); $shops = Shop::getShops(false); foreach ($shops as $shop) { $ids_category[$shop['id_shop']] = $shop['id_category']; } $this->tpl_form_vars = array('disabled' => $disabled, 'checked' => Tools::getValue('addshop') !== false ? true : false, 'defaultShop' => (int) Configuration::get('PS_SHOP_DEFAULT'), 'ids_category' => $ids_category); if (isset($this->fields_import_form)) { $this->tpl_form_vars = array_merge($this->tpl_form_vars, array('form_import' => $this->fields_import_form)); } return parent::renderForm(); }
private function fetchShopGroups() { $groupList = array(); //$groupList[] = array('id' => '0', 'name' => $this->l('Choose your group')); foreach (ShopGroup::getShopGroups(true) as $group) { $groupList[] = array('id' => $group->id, 'name' => $group->name); } $this->context->smarty->assign(array('shop_groups' => $groupList)); }