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', '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; } $this->context->smarty->assign(array('toolbar_scroll' => 1, 'toolbar_btn' => $this->toolbar_btn, 'title' => $this->toolbar_title, 'shops_tree' => $shops_tree)); }
/** * Render an area to determinate shop association * * @return string */ public function renderAssoShop($disable_shared = false, $template_directory = null) { if (!Shop::isFeatureActive()) { return; } $assos = array(); if ((int) $this->id) { $sql = 'SELECT `id_shop`, `' . bqSQL($this->identifier) . '` FROM `' . _DB_PREFIX_ . bqSQL($this->table) . '_shop` WHERE `' . bqSQL($this->identifier) . '` = ' . (int) $this->id; foreach (Db::getInstance()->executeS($sql) as $row) { $assos[$row['id_shop']] = $row['id_shop']; } } else { switch (Shop::getContext()) { case Shop::CONTEXT_SHOP: $assos[Shop::getContextShopID()] = Shop::getContextShopID(); break; case Shop::CONTEXT_GROUP: foreach (Shop::getShops(false, Shop::getContextShopGroupID(), true) as $id_shop) { $assos[$id_shop] = $id_shop; } break; default: foreach (Shop::getShops(false, null, true) as $id_shop) { $assos[$id_shop] = $id_shop; } break; } } /*$nb_shop = 0; foreach ($tree as &$value) { $value['disable_shops'] = (isset($value[$disable_shared]) && $value[$disable_shared]); $nb_shop += count($value['shops']); }*/ $tree = new HelperTreeShops('shop-tree', 'Shops'); if (isset($template_directory)) { $tree->setTemplateDirectory($template_directory); } $tree->setSelectedShops($assos); $tree->setAttribute('table', $this->table); return $tree->render(); }
/** * @param Offer $obj * @throws Exception * @throws PrestaShopException * @throws SmartyException */ public function initFormShops($obj) { $offer = $obj; $data = $this->createTemplate($this->tpl_form); // Selected shops $selected_shops = array(); $shops = AphOffer::getShopsLight($this->context->language->id, $offer->id); if (!empty($shops)) { foreach ($shops as $shop) { $selected_shops[] = $shop['id_shop']; } } // Generate category selection tree $tree = new HelperTreeShops('shops-tree', $this->l('Seleziona negozio')); $tree->setNodeFolderTemplate('tree_node_folder.tpl'); $tree->setAttribute('selected_shops', $selected_shops); $tree->setSelectedShops($selected_shops); $data->assign('shop_tree', $tree->render()); $data->assign(array('offer' => $offer, 'link' => $this->context->link, 'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP)); $this->tpl_form_vars['custom_form'] = $data->fetch(); }