Ejemplo n.º 1
0
    /**
     * 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();
 }