Exemplo n.º 1
0
 /**
  * Render shop list
  *
  * @return string
  */
 public function getRenderedShopList()
 {
     if (!Shop::isFeatureActive() || Shop::getTotalShops(false, null) < 2) {
         return '';
     }
     $shop_context = Shop::getContext();
     $context = Context::getContext();
     $tree = Shop::getTree();
     if ($shop_context == Shop::CONTEXT_ALL || $context->controller->multishop_context_group == false && $shop_context == Shop::CONTEXT_GROUP) {
         $current_shop_value = '';
         $current_shop_name = Translate::getAdminTranslation('All shops');
     } elseif ($shop_context == Shop::CONTEXT_GROUP) {
         $current_shop_value = 'g-' . Shop::getContextShopGroupID();
         $current_shop_name = sprintf(Translate::getAdminTranslation('%s group'), $tree[Shop::getContextShopGroupID()]['name']);
     } else {
         $current_shop_value = 's-' . Shop::getContextShopID();
         foreach ($tree as $group_id => $group_data) {
             foreach ($group_data['shops'] as $shop_id => $shop_data) {
                 if ($shop_id == Shop::getContextShopID()) {
                     $current_shop_name = $shop_data['name'];
                     break;
                 }
             }
         }
     }
     $tpl = $this->createTemplate('helpers/shops_list/list.tpl');
     $tpl->assign(array('tree' => $tree, 'current_shop_name' => $current_shop_name, 'current_shop_value' => $current_shop_value, 'multishop_context' => $context->controller->multishop_context, 'multishop_context_group' => $context->controller->multishop_context_group, 'is_shop_context' => $context->controller->multishop_context & Shop::CONTEXT_SHOP, 'is_group_context' => $context->controller->multishop_context & Shop::CONTEXT_GROUP, 'shop_context' => $shop_context, 'url' => $_SERVER['REQUEST_URI'] . ($_SERVER['QUERY_STRING'] ? '&' : '?') . 'setShopContext='));
     return $tpl->fetch();
 }
Exemplo n.º 2
0
 public function getCurrentShopName()
 {
     $shop_context = Shop::getContext();
     $tree = Shop::getTree();
     if ($this->noShopSelection()) {
         $current_shop_name = Translate::getAdminTranslation('All shops');
     } elseif ($shop_context == Shop::CONTEXT_GROUP) {
         $current_shop_name = sprintf(Translate::getAdminTranslation('%s group'), $tree[Shop::getContextShopGroupID()]['name']);
     } else {
         foreach ($tree as $group_id => $group_data) {
             foreach ($group_data['shops'] as $shop_id => $shop_data) {
                 if ($shop_id == Shop::getContextShopID()) {
                     $current_shop_name = $shop_data['name'];
                     break;
                 }
             }
         }
     }
     return $current_shop_name;
 }
Exemplo n.º 3
0
    public static function clearCategory()
    {
        if (version_compare(_PS_VERSION_, '1.5', '<')) {
            return Db::getInstance()->execute('
				DELETE FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
				WHERE `id_shop`=' . (int) Context::getContext()->shop->id);
        }
        $shop_context = Shop::getContext();
        if ($shop_context == Shop::CONTEXT_SHOP) {
            return Db::getInstance()->execute('
				DELETE FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
				WHERE `id_shop`=' . (int) Context::getContext()->shop->id);
        } else {
            $id_shop_group = Shop::getContext() == Shop::CONTEXT_GROUP ? Shop::getContextShopGroupID() : null;
            $shop_ids = Shop::getShops(false, $id_shop_group, true);
            foreach ($shop_ids as $id_shop) {
                Db::getInstance()->execute('
					DELETE FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
					WHERE `id_shop`=' . (int) $id_shop);
            }
        }
    }
Exemplo n.º 4
0
 public function postProcess()
 {
     $id_shops = array();
     if (Tools::isSubmit('mass_csv_form_submit')) {
         if (Shop::getContext() == Shop::CONTEXT_ALL) {
             $shops = Shop::getShops();
             if (!empty($shops)) {
                 foreach ($shops as $s) {
                     $id_shops[] = $s['id_shop'];
                 }
             }
         } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
             $shopid = Shop::getContextShopGroupID(true);
             $shops = ShopGroup::getShopsFromGroup($shopid);
             if (!empty($shops)) {
                 foreach ($shops as $s) {
                     $id_shops[] = $s['id_shop'];
                 }
             }
         }
         if (empty($id_shops)) {
             $id_shops[] = Shop::getContextShopID();
         }
         $id_shops = array_unique($id_shops);
         if (is_uploaded_file($_FILES['csv_file']['tmp_name'])) {
             $mimes = array('application/vnd.ms-excel', 'text/plain', 'text/csv', 'text/tsv');
             if (!in_array($_FILES['csv_file']['type'], $mimes)) {
                 $this->errors[] = Tools::displayError($this->l('Error : Problem with file upload. Please retry or check your file.'));
                 return false;
             }
             if (move_uploaded_file($_FILES['csv_file']['tmp_name'], $this->mod->cache_dir . $_FILES['csv_file']['name'])) {
                 $old_file_name = $_FILES['csv_file']['name'];
                 $csv_content = Tools::file_get_contents($this->mod->cache_dir . $old_file_name);
                 $array = $this->csvToArray($csv_content);
                 if (empty($array)) {
                     $this->errors[] = Tools::displayError($this->l('Error : Problem with file upload. Please retry or check your file.'));
                     parent::postProcess();
                     return false;
                 }
                 foreach ($array as $value) {
                     if (!empty($value[0])) {
                         $new = !empty($value[1]) ? trim($value[1]) : '/';
                         $type = !empty($value[2]) ? trim($value[2]) : '301';
                         $regex = !empty($value[3]) ? (int) $value[3] : 0;
                         $redirect = new Redirect();
                         $redirect->old = trim($value[0]);
                         $redirect->new = $new;
                         $redirect->type = $type;
                         $redirect->regex = (bool) $regex;
                         $redirect->active = true;
                         $redirect->add();
                         /*foreach ($id_shops as $v) {
                               $db->execute('INSERT INTO `'._DB_PREFIX_.'redirect_shop` (`id_redirect_shop`,`id_redirect`, `id_shop`) VALUES (NULL,'.(int)$redirect->id.','.(int)$v.')');
                           }*/
                     }
                 }
             }
             Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminRedirect') . '&conf=4');
         }
     }
     parent::postProcess();
 }
Exemplo n.º 5
0
         Shop::setContext(Shop::CONTEXT_SHOP, $id);
         echo "-Context is set to " . $type . $id . " ";
         break;
     default:
         Shop::setContext(Shop::CONTEXT_ALL, null);
         echo "-Context is set to " . $type . " ";
 }
 //code v2.4.1
 $id_product = (int) Tools::getValue('id_product');
 $id_lang = (int) Context::getContext()->language->id;
 //$product = new Product($id_product, false, $id_lang,$id_shop_source,$context); //version 5.2 - Ne duplique que dans une seule langue
 $product = new Product($id_product, false, null, $id_shop_source, $context);
 //version 5.3  All languages
 //Class product:  function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
 if (empty($product->price) && Shop::getContext() == Shop::CONTEXT_GROUP) {
     $shops = ShopGroup::getShopsFromGroup(Shop::getContextShopGroupID());
     foreach ($shops as $shop) {
         if ($product->isAssociatedToShop($shop['id_shop'])) {
             $product_price = new Product($id_product_old, false, null, $shop['id_shop']);
             $product->price = $product_price->price;
         }
     }
 }
 if (Validate::isLoadedObject($product)) {
     $id_product_old = $product->id;
     for ($i = 1; $i <= $quantity; $i++) {
         echo $i;
         unset($product->id);
         unset($product->id_product);
         $product->indexed = 0;
         $product->active = 0;
Exemplo n.º 6
0
/**
 * for retrocompatibility with old AdminTab, old index.php
 *
 * @return void
 */
function runAdminTab($tab, $ajaxMode = false)
{
    $ajaxMode = (bool) $ajaxMode;
    require_once _PS_ADMIN_DIR_ . '/init.php';
    $cookie = Context::getContext()->cookie;
    if (empty($tab) && !sizeof($_POST)) {
        $tab = 'AdminDashboard';
        $_POST['tab'] = $tab;
        $_POST['token'] = Tools::getAdminTokenLite($tab);
    }
    // $tab = $_REQUEST['tab'];
    if ($adminObj = checkingTab($tab)) {
        Context::getContext()->controller = $adminObj;
        // init is different for new tabs (AdminController) and old tabs (AdminTab)
        if ($adminObj instanceof AdminController) {
            if ($ajaxMode) {
                $adminObj->ajax = true;
            }
            $adminObj->path = dirname($_SERVER["PHP_SELF"]);
            $adminObj->run();
        } else {
            if (!$ajaxMode) {
                require_once _PS_ADMIN_DIR_ . '/header.inc.php';
            }
            $isoUser = Context::getContext()->language->id;
            $tabs = array();
            $tabs = Tab::recursiveTab($adminObj->id, $tabs);
            $tabs = array_reverse($tabs);
            $bread = '';
            foreach ($tabs as $key => $item) {
                $bread .= ' <img src="../img/admin/separator_breadcrumb.png" style="margin-right:5px" alt="&gt;" />';
                if (count($tabs) - 1 > $key) {
                    $bread .= '<a href="?tab=' . $item['class_name'] . '&token=' . Tools::getAdminToken($item['class_name'] . intval($item['id_tab']) . (int) Context::getContext()->employee->id) . '">';
                }
                $bread .= $item['name'];
                if (count($tabs) - 1 > $key) {
                    $bread .= '</a>';
                }
            }
            if (!$ajaxMode && Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && Context::getContext()->controller->multishop_context != Shop::CONTEXT_ALL) {
                echo '<div class="multishop_info">';
                if (Shop::getContext() == Shop::CONTEXT_GROUP) {
                    $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
                    printf(Translate::getAdminTranslation('You are configuring your store for group shop %s'), '<b>' . $shop_group->name . '</b>');
                } elseif (Shop::getContext() == Shop::CONTEXT_SHOP) {
                    printf(Translate::getAdminTranslation('You are configuring your store for shop %s'), '<b>' . Context::getContext()->shop->name . '</b>');
                }
                echo '</div>';
            }
            if (Validate::isLoadedObject($adminObj)) {
                if ($adminObj->checkToken()) {
                    if ($ajaxMode) {
                        // the differences with index.php is here
                        $adminObj->ajaxPreProcess();
                        $action = Tools::getValue('action');
                        // no need to use displayConf() here
                        if (!empty($action) && method_exists($adminObj, 'ajaxProcess' . Tools::toCamelCase($action))) {
                            $adminObj->{'ajaxProcess' . Tools::toCamelCase($action)}();
                        } else {
                            $adminObj->ajaxProcess();
                        }
                        // @TODO We should use a displayAjaxError
                        $adminObj->displayErrors();
                        if (!empty($action) && method_exists($adminObj, 'displayAjax' . Tools::toCamelCase($action))) {
                            $adminObj->{'displayAjax' . $action}();
                        } else {
                            $adminObj->displayAjax();
                        }
                    } else {
                        /* Filter memorization */
                        if (isset($_POST) && !empty($_POST) && isset($adminObj->table)) {
                            foreach ($_POST as $key => $value) {
                                if (is_array($adminObj->table)) {
                                    foreach ($adminObj->table as $table) {
                                        if (strncmp($key, $table . 'Filter_', 7) === 0 || strncmp($key, 'submitFilter', 12) === 0) {
                                            $cookie->{$key} = !is_array($value) ? $value : serialize($value);
                                        }
                                    }
                                } elseif (strncmp($key, $adminObj->table . 'Filter_', 7) === 0 || strncmp($key, 'submitFilter', 12) === 0) {
                                    $cookie->{$key} = !is_array($value) ? $value : serialize($value);
                                }
                            }
                        }
                        if (isset($_GET) && !empty($_GET) && isset($adminObj->table)) {
                            foreach ($_GET as $key => $value) {
                                if (is_array($adminObj->table)) {
                                    foreach ($adminObj->table as $table) {
                                        if (strncmp($key, $table . 'OrderBy', 7) === 0 || strncmp($key, $table . 'Orderway', 8) === 0) {
                                            $cookie->{$key} = $value;
                                        }
                                    }
                                } elseif (strncmp($key, $adminObj->table . 'OrderBy', 7) === 0 || strncmp($key, $adminObj->table . 'Orderway', 12) === 0) {
                                    $cookie->{$key} = $value;
                                }
                            }
                        }
                        $adminObj->displayConf();
                        $adminObj->postProcess();
                        $adminObj->displayErrors();
                        $adminObj->display();
                        include _PS_ADMIN_DIR_ . '/footer.inc.php';
                    }
                } else {
                    if ($ajaxMode) {
                        // If this is an XSS attempt, then we should only display a simple, secure page
                        if (ob_get_level() && ob_get_length() > 0) {
                            ob_clean();
                        }
                        // ${1} in the replacement string of the regexp is required, because the token may begin with a number and mix up with it (e.g. $17)
                        $url = preg_replace('/([&?]token=)[^&]*(&.*)?$/', '${1}' . $adminObj->token . '$2', $_SERVER['REQUEST_URI']);
                        if (false === strpos($url, '?token=') && false === strpos($url, '&token=')) {
                            $url .= '&token=' . $adminObj->token;
                        }
                        // we can display the correct url
                        // die(Tools::jsonEncode(array(Translate::getAdminTranslation('Invalid security token'),$url)));
                        die(Tools::jsonEncode(Translate::getAdminTranslation('Invalid security token')));
                    } else {
                        // If this is an XSS attempt, then we should only display a simple, secure page
                        if (ob_get_level() && ob_get_length() > 0) {
                            ob_clean();
                        }
                        // ${1} in the replacement string of the regexp is required, because the token may begin with a number and mix up with it (e.g. $17)
                        $url = preg_replace('/([&?]token=)[^&]*(&.*)?$/', '${1}' . $adminObj->token . '$2', $_SERVER['REQUEST_URI']);
                        if (false === strpos($url, '?token=') && false === strpos($url, '&token=')) {
                            $url .= '&token=' . $adminObj->token;
                        }
                        $message = Translate::getAdminTranslation('Invalid security token');
                        echo '<html><head><title>' . $message . '</title></head><body style="font-family:Arial,Verdana,Helvetica,sans-serif;background-color:#EC8686">
							<div style="background-color:#FAE2E3;border:1px solid #000000;color:#383838;font-weight:700;line-height:20px;margin:0 0 10px;padding:10px 15px;width:500px">
								<img src="../img/admin/error2.png" style="margin:-4px 5px 0 0;vertical-align:middle">
								' . $message . '
							</div>';
                        echo '<a href="' . htmlentities($url) . '" method="get" style="float:left;margin:10px">
								<input type="button" value="' . Tools::htmlentitiesUTF8(Translate::getAdminTranslation('I understand the risks and I really want to display this page')) . '" style="height:30px;margin-top:5px" />
							</a>
							<a href="index.php" method="get" style="float:left;margin:10px">
								<input type="button" value="' . Tools::htmlentitiesUTF8(Translate::getAdminTranslation('Take me out of here!')) . '" style="height:40px" />
							</a>
						</body></html>';
                        die;
                    }
                }
            }
        }
    }
}
Exemplo n.º 7
0
 /**
  * For a given id_product and id_product_attribute sets the quantity available
  *
  * @param int $id_product
  * @param int $id_product_attribute Optional
  * @param int $delta_quantity The delta quantity to update
  * @param int $id_shop Optional
  */
 public static function setQuantity($id_product, $id_product_attribute, $quantity, $id_shop = null)
 {
     if (!Validate::isUnsignedId($id_product)) {
         return false;
     }
     $context = Context::getContext();
     // if there is no $id_shop, gets the context one
     if ($id_shop === null && Shop::getContext() != Shop::CONTEXT_GROUP) {
         $id_shop = (int) $context->shop->id;
     }
     $depends_on_stock = StockAvailable::dependsOnStock($id_product);
     //Try to set available quantity if product does not depend on physical stock
     if (!$depends_on_stock) {
         $id_stock_available = (int) StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
         if ($id_stock_available) {
             $stock_available = new StockAvailable($id_stock_available);
             $stock_available->quantity = (int) $quantity;
             $stock_available->update();
         } else {
             $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop);
             $stock_available = new StockAvailable();
             $stock_available->out_of_stock = (int) $out_of_stock;
             $stock_available->id_product = (int) $id_product;
             $stock_available->id_product_attribute = (int) $id_product_attribute;
             $stock_available->quantity = (int) $quantity;
             $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
             // if quantities are shared between shops of the group
             if ($shop_group->share_stock) {
                 $stock_available->id_shop = 0;
                 $stock_available->id_shop_group = (int) $shop_group->id;
             } else {
                 $stock_available->id_shop = $id_shop;
                 $stock_available->id_shop_group = Shop::getGroupFromShop($id_shop);
             }
             $stock_available->add();
         }
         Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity));
     }
 }
 public function postProcessCallback()
 {
     $return = false;
     $installed_modules = array();
     foreach ($this->map as $key => $method) {
         if (!Tools::getValue($key)) {
             continue;
         }
         if ($key == 'check') {
             $this->ajaxProcessRefreshModuleList(true);
         } elseif ($key == 'checkAndUpdate') {
             $modules = array();
             $this->ajaxProcessRefreshModuleList(true);
             $modules_on_disk = Module::getModulesOnDisk(true, $this->logged_on_addons, $this->id_employee);
             // Browse modules list
             foreach ($modules_on_disk as $km => $module_on_disk) {
                 if (!Tools::getValue('module_name') && isset($module_on_disk->version_addons) && $module_on_disk->version_addons) {
                     $modules[] = $module_on_disk->name;
                 }
             }
             if (!Tools::getValue('module_name')) {
                 $modules_list_save = implode('|', $modules);
             }
         } elseif (($modules = Tools::getValue($key)) && $key != 'checkAndUpdate') {
             if (strpos($modules, '|')) {
                 $modules_list_save = $modules;
                 $modules = explode('|', $modules);
             }
             if (!is_array($modules)) {
                 $modules = (array) $modules;
             }
         }
         $module_errors = array();
         if (isset($modules)) {
             foreach ($modules as $name) {
                 $module_to_update = array();
                 $module_to_update[$name] = null;
                 $full_report = null;
                 // If Addons module, download and unzip it before installing it
                 if (!file_exists(_PS_MODULE_DIR_ . $name . '/' . $name . '.php') || $key == 'update') {
                     $filesList = array(array('type' => 'addonsNative', 'file' => Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0), array('type' => 'addonsBought', 'file' => Module::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1));
                     foreach ($filesList as $f) {
                         if (file_exists(_PS_ROOT_DIR_ . $f['file'])) {
                             $file = $f['file'];
                             $content = Tools::file_get_contents(_PS_ROOT_DIR_ . $file);
                             if ($xml = @simplexml_load_string($content, null, LIBXML_NOCDATA)) {
                                 foreach ($xml->module as $modaddons) {
                                     if ($name == $modaddons->name) {
                                         $module_to_update[$name]['id'] = $modaddons->id;
                                         $module_to_update[$name]['displayName'] = $modaddons->displayName;
                                         $module_to_update[$name]['need_loggedOnAddons'] = $f['loggedOnAddons'];
                                     }
                                 }
                             }
                         }
                     }
                     $module_upgraded = array();
                     foreach ($module_to_update as $name => $attr) {
                         if (is_null($attr) && $this->logged_on_addons == 0 || $attr['need_loggedOnAddons'] == 1 && $this->logged_on_addons == 0) {
                             $this->errors[] = sprintf(Tools::displayError('You need to be logged in to your PrestaShop Addons account in order to update the %s module. %s'), '<strong>' . $name . '</strong>', '<a href="#" class="addons_connect" data-toggle="modal" data-target="#modal_addons_connect" title="Addons">' . $this->l('Click here to log in.') . '</a>');
                         } elseif (!is_null($attr['id'])) {
                             $download_ok = false;
                             if ($attr['need_loggedOnAddons'] == 0 && file_put_contents(_PS_MODULE_DIR_ . $name . '.zip', Tools::addonsRequest('module', array('id_module' => pSQL($attr['id']))))) {
                                 $download_ok = true;
                             } elseif ($attr['need_loggedOnAddons'] == 1 && $this->logged_on_addons && file_put_contents(_PS_MODULE_DIR_ . $name . '.zip', Tools::addonsRequest('module', array('id_module' => pSQL($attr['id']), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))))) {
                                 $download_ok = true;
                             }
                             if (!$download_ok) {
                                 $this->errors[] = sprintf(Tools::displayError("Module %s can't be upgraded: Error on downloading the latest version."), '<strong>' . $attr['displayName'] . '</strong>');
                             } elseif (!$this->extractArchive(_PS_MODULE_DIR_ . $name . '.zip', false)) {
                                 $this->errors[] = sprintf(Tools::displayError("Module %s can't be upgraded: Error on extracting the latest version"), '<strong>' . $attr['displayName'] . '</strong>');
                             } else {
                                 $module_upgraded[] = $name;
                             }
                         } else {
                             $this->errors[] = sprintf(Tools::displayError("You don’t have the rights to update the %s module. Please make sure you are logged in to the PrestaShop Addons account that purchased the module."), '<strong>' . $name . '</strong>');
                         }
                     }
                     $module_upgraded = implode('|', $module_upgraded);
                 }
                 if (count($this->errors)) {
                     continue;
                 }
                 // Check potential error
                 if (!($module = Module::getInstanceByName(urldecode($name)))) {
                     $this->errors[] = $this->l('Module not found');
                 } elseif (defined('_PS_HOST_MODE_') && in_array($module->name, Module::$hosted_modules_blacklist)) {
                     $this->errors[] = Tools::displayError('You do not have permission to access this module.');
                 } elseif ($key == 'install' && $this->tabAccess['add'] !== '1') {
                     $this->errors[] = Tools::displayError('You do not have permission to install this module.');
                 } elseif ($key == 'install' && defined('_PS_HOST_MODE_') && _PS_HOST_MODE_ && !Module::isModuleTrusted($module->name)) {
                     $this->errors[] = Tools::displayError('You do not have permission to install this module.');
                 } elseif ($key == 'delete' && ($this->tabAccess['delete'] !== '1' || !$module->getPermission('configure'))) {
                     $this->errors[] = Tools::displayError('You do not have permission to delete this module.');
                 } elseif ($key == 'configure' && ($this->tabAccess['edit'] !== '1' || !$module->getPermission('configure') || !Module::isInstalled(urldecode($name)))) {
                     $this->errors[] = Tools::displayError('You do not have permission to configure this module.');
                 } elseif ($key == 'install' && Module::isInstalled($module->name)) {
                     $this->errors[] = Tools::displayError('This module is already installed:') . ' ' . $module->name;
                 } elseif ($key == 'uninstall' && !Module::isInstalled($module->name)) {
                     $this->errors[] = Tools::displayError('This module has already been uninstalled:') . ' ' . $module->name;
                 } else {
                     if ($key == 'update' && !Module::isInstalled($module->name)) {
                         $this->errors[] = Tools::displayError('This module needs to be installed in order to be updated:') . ' ' . $module->name;
                     } else {
                         // If we install a module, force temporary global context for multishop
                         if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && $method != 'getContent') {
                             $shop_id = (int) Context::getContext()->shop->id;
                             Context::getContext()->tmpOldShop = clone Context::getContext()->shop;
                             if ($shop_id) {
                                 Context::getContext()->shop = new Shop($shop_id);
                             }
                         }
                         //retrocompatibility
                         if (Tools::getValue('controller') != '') {
                             $_POST['tab'] = Tools::safeOutput(Tools::getValue('controller'));
                         }
                         $echo = '';
                         if ($key != 'update' && $key != 'checkAndUpdate') {
                             // We check if method of module exists
                             if (!method_exists($module, $method)) {
                                 throw new PrestaShopException('Method of module cannot be found');
                             }
                             // Get the return value of current method
                             $echo = $module->{$method}();
                             // After a successful install of a single module that has a configuration method, to the configuration page
                             if ($key == 'install' && $echo === true && strpos(Tools::getValue('install'), '|') === false && method_exists($module, 'getContent')) {
                                 Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token . '&configure=' . $module->name . '&conf=12');
                             }
                         }
                         // If the method called is "configure" (getContent method), we show the html code of configure page
                         if ($key == 'configure' && Module::isInstalled($module->name)) {
                             $this->bootstrap = isset($module->bootstrap) && $module->bootstrap;
                             if (isset($module->multishop_context)) {
                                 $this->multishop_context = $module->multishop_context;
                             }
                             $back_link = self::$currentIndex . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name;
                             $hook_link = 'index.php?tab=AdminModulesPositions&token=' . Tools::getAdminTokenLite('AdminModulesPositions') . '&show_modules=' . (int) $module->id;
                             $trad_link = 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&lang=';
                             $disable_link = $this->context->link->getAdminLink('AdminModules') . '&module_name=' . $module->name . '&enable=0&tab_module=' . $module->tab;
                             $uninstall_link = $this->context->link->getAdminLink('AdminModules') . '&module_name=' . $module->name . '&uninstall=' . $module->name . '&tab_module=' . $module->tab;
                             $reset_link = $this->context->link->getAdminLink('AdminModules') . '&module_name=' . $module->name . '&reset&tab_module=' . $module->tab;
                             $update_link = $this->context->link->getAdminLink('AdminModules') . '&checkAndUpdate=1&module_name=' . $module->name;
                             $is_reset_ready = false;
                             if (method_exists($module, 'reset')) {
                                 $is_reset_ready = true;
                             }
                             $this->context->smarty->assign(array('module_name' => $module->name, 'module_display_name' => $module->displayName, 'back_link' => $back_link, 'module_hook_link' => $hook_link, 'module_disable_link' => $disable_link, 'module_uninstall_link' => $uninstall_link, 'module_reset_link' => $reset_link, 'module_update_link' => $update_link, 'trad_link' => $trad_link, 'module_languages' => Language::getLanguages(false), 'theme_language_dir' => _THEME_LANG_DIR_, 'page_header_toolbar_title' => $this->page_header_toolbar_title, 'page_header_toolbar_btn' => $this->page_header_toolbar_btn, 'add_permission' => $this->tabAccess['add'], 'is_reset_ready' => $is_reset_ready));
                             // Display checkbox in toolbar if multishop
                             if (Shop::isFeatureActive()) {
                                 if (Shop::getContext() == Shop::CONTEXT_SHOP) {
                                     $shop_context = 'shop <strong>' . $this->context->shop->name . '</strong>';
                                 } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
                                     $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
                                     $shop_context = 'all shops of group shop <strong>' . $shop_group->name . '</strong>';
                                 } else {
                                     $shop_context = 'all shops';
                                 }
                                 $this->context->smarty->assign(array('module' => $module, 'display_multishop_checkbox' => true, 'current_url' => $this->getCurrentUrl('enable'), 'shop_context' => $shop_context));
                             }
                             $this->context->smarty->assign(array('shop_list' => Helper::renderShopList(), 'is_multishop' => Shop::isFeatureActive(), 'multishop_context' => Shop::CONTEXT_ALL | Shop::CONTEXT_GROUP | Shop::CONTEXT_SHOP));
                             if (Shop::isFeatureActive() && isset(Context::getContext()->tmpOldShop)) {
                                 Context::getContext()->shop = clone Context::getContext()->tmpOldShop;
                                 unset(Context::getContext()->tmpOldShop);
                             }
                             // Display module configuration
                             $header = $this->context->smarty->fetch('controllers/modules/configure.tpl');
                             $configuration_bar = $this->context->smarty->fetch('controllers/modules/configuration_bar.tpl');
                             $output = $header . $echo;
                             if (isset($this->_modules_ad[$module->name])) {
                                 $ad_modules = $this->getModulesByInstallation($this->_modules_ad[$module->name]);
                                 foreach ($ad_modules['not_installed'] as $key => &$module) {
                                     if (isset($module->addons_buy_url)) {
                                         $module->addons_buy_url = str_replace('utm_source=v1trunk_api', 'utm_source=back-office', $module->addons_buy_url) . '&utm_medium=related-modules&utm_campaign=back-office-' . strtoupper($this->context->language->iso_code);
                                     }
                                     if (isset($module->description_full) && trim($module->description_full) != '') {
                                         $module->show_quick_view = true;
                                     }
                                 }
                                 $this->context->smarty->assign(array('ad_modules' => $ad_modules, 'currentIndex' => self::$currentIndex));
                                 $ad_bar = $this->context->smarty->fetch('controllers/modules/ad_bar.tpl');
                                 $output .= $ad_bar;
                             }
                             $this->context->smarty->assign('module_content', $output . $configuration_bar);
                         } elseif ($echo === true) {
                             $return = 13;
                             if ($method == 'install') {
                                 $return = 12;
                                 $installed_modules[] = $module->id;
                             }
                         } elseif ($echo === false) {
                             $module_errors[] = array('name' => $name, 'message' => $module->getErrors());
                         }
                         if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && isset(Context::getContext()->tmpOldShop)) {
                             Context::getContext()->shop = clone Context::getContext()->tmpOldShop;
                             unset(Context::getContext()->tmpOldShop);
                         }
                     }
                 }
                 if ($key != 'configure' && Tools::getIsset('bpay')) {
                     Tools::redirectAdmin('index.php?tab=AdminPayment&token=' . Tools::getAdminToken('AdminPayment' . (int) Tab::getIdFromClassName('AdminPayment') . (int) $this->id_employee));
                 }
             }
         }
         if (count($module_errors)) {
             // If error during module installation, no redirection
             $html_error = $this->generateHtmlMessage($module_errors);
             $this->errors[] = sprintf(Tools::displayError('The following module(s) were not installed properly: %s'), $html_error);
             $this->context->smarty->assign('error_module', 'true');
         }
     }
     if ($return) {
         $params = count($installed_modules) ? '&installed_modules=' . implode('|', $installed_modules) : '';
         // If redirect parameter is present and module installed with success, we redirect on configuration module page
         if (Tools::getValue('redirect') == 'config' && Tools::getValue('module_name') != '' && $return == '12' && Module::isInstalled(pSQL(Tools::getValue('module_name')))) {
             Tools::redirectAdmin('index.php?controller=adminmodules&configure=' . Tools::getValue('module_name') . '&token=' . Tools::getValue('token') . '&module_name=' . Tools::getValue('module_name') . $params);
         }
         Tools::redirectAdmin(self::$currentIndex . '&conf=' . $return . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name . '&anchor=' . ucfirst($module->name) . (isset($modules_list_save) ? '&modules_list=' . $modules_list_save : '') . $params);
     }
     if (Tools::getValue('update') || Tools::getValue('checkAndUpdate')) {
         $updated = '&updated=1';
         if (Tools::getValue('checkAndUpdate')) {
             $updated = '';
             if (Tools::getValue('module_name')) {
                 $module = Module::getInstanceByName(Tools::getValue('module_name'));
                 if (!Validate::isLoadedObject($module)) {
                     unset($module);
                 }
             }
         }
         if (isset($module_upgraded) && $module_upgraded != '') {
             Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token . '&updated=1&module_name=' . $module_upgraded);
         } elseif (isset($modules_list_save)) {
             Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token . '&updated=1&module_name=' . $modules_list_save);
         } elseif (isset($module)) {
             Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token . $updated . '&tab_module=' . $module->tab . '&module_name=' . $module->name . '&anchor=' . ucfirst($module->name) . (isset($modules_list_save) ? '&modules_list=' . $modules_list_save : ''));
         }
     }
 }
Exemplo n.º 9
0
 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,') . '&nbsp;<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();
 }
 /**
  * Generic function which allows logo upload
  *
  * @param $field_name
  * @param $logo_prefix
  *
  * @return bool
  */
 protected function updateLogo($field_name, $logo_prefix)
 {
     $id_shop = Context::getContext()->shop->id;
     if (isset($_FILES[$field_name]['tmp_name']) && $_FILES[$field_name]['tmp_name'] && $_FILES[$field_name]['size']) {
         if ($error = ImageManager::validateUpload($_FILES[$field_name], Tools::getMaxUploadSize())) {
             $this->errors[] = $error;
             return false;
         }
         $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
         if (!$tmp_name || !move_uploaded_file($_FILES[$field_name]['tmp_name'], $tmp_name)) {
             return false;
         }
         $ext = $field_name == 'PS_STORES_ICON' ? '.gif' : '.jpg';
         $logo_name = Tools::link_rewrite(Context::getContext()->shop->name) . '-' . $logo_prefix . '-' . (int) Configuration::get('PS_IMG_UPDATE_TIME') . (int) $id_shop . $ext;
         if (Context::getContext()->shop->getContext() == Shop::CONTEXT_ALL || $id_shop == 0 || Shop::isFeatureActive() == false) {
             $logo_name = Tools::link_rewrite(Context::getContext()->shop->name) . '-' . $logo_prefix . '-' . (int) Configuration::get('PS_IMG_UPDATE_TIME') . $ext;
         }
         if ($field_name == 'PS_STORES_ICON') {
             if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name, null, null, 'gif', true)) {
                 $this->errors[] = Tools::displayError('An error occurred while attempting to copy your logo.');
             }
         } else {
             if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name)) {
                 $this->errors[] = Tools::displayError('An error occurred while attempting to copy your logo.');
             }
         }
         $id_shop = null;
         $id_shop_group = null;
         if (!count($this->errors) && @filemtime(_PS_IMG_DIR_ . Configuration::get($field_name))) {
             if (Shop::isFeatureActive()) {
                 if (Shop::getContext() == Shop::CONTEXT_SHOP) {
                     $id_shop = Shop::getContextShopID();
                     $id_shop_group = Shop::getContextShopGroupID();
                     Shop::setContext(Shop::CONTEXT_ALL);
                     $logo_all = Configuration::get($field_name);
                     Shop::setContext(Shop::CONTEXT_GROUP);
                     $logo_group = Configuration::get($field_name);
                     Shop::setContext(Shop::CONTEXT_SHOP);
                     $logo_shop = Configuration::get($field_name);
                     if ($logo_all != $logo_shop && $logo_group != $logo_shop && $logo_shop != false) {
                         @unlink(_PS_IMG_DIR_ . Configuration::get($field_name));
                     }
                 } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
                     $id_shop_group = Shop::getContextShopGroupID();
                     Shop::setContext(Shop::CONTEXT_ALL);
                     $logo_all = Configuration::get($field_name);
                     Shop::setContext(Shop::CONTEXT_GROUP);
                     if ($logo_all != Configuration::get($field_name)) {
                         @unlink(_PS_IMG_DIR_ . Configuration::get($field_name));
                     }
                 }
             } else {
                 @unlink(_PS_IMG_DIR_ . Configuration::get($field_name));
             }
         }
         Configuration::updateValue($field_name, $logo_name, false, $id_shop_group, $id_shop);
         @unlink($tmp_name);
     }
 }
Exemplo n.º 11
0
 public static function renderShopList()
 {
     if (!Shop::isFeatureActive() || Shop::getTotalShops(false, null) < 2) {
         return null;
     }
     $tree = Shop::getTree();
     $context = Context::getContext();
     // Get default value
     $shop_context = Shop::getContext();
     if ($shop_context == Shop::CONTEXT_ALL || $context->controller->multishop_context_group == false && $shop_context == Shop::CONTEXT_GROUP) {
         $value = '';
     } else {
         if ($shop_context == Shop::CONTEXT_GROUP) {
             $value = 'g-' . Shop::getContextShopGroupID();
         } else {
             $value = 's-' . Shop::getContextShopID();
         }
     }
     // Generate HTML
     $url = $_SERVER['REQUEST_URI'] . ($_SERVER['QUERY_STRING'] ? '&' : '?') . 'setShopContext=';
     $shop = new Shop(Shop::getContextShopID());
     // $html = '<a href="#"><i class="icon-home"></i> '.$shop->name.'</a>';
     $html = '<select class="shopList" onchange="location.href = \'' . htmlspecialchars($url) . '\'+$(this).val();">';
     $html .= '<option value="" class="first">' . Translate::getAdminTranslation('All shops') . '</option>';
     foreach ($tree as $gID => $group_data) {
         if (!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP) {
             $html .= '<option class="group" value="g-' . $gID . '"' . (empty($value) && $shop_context == Shop::CONTEXT_GROUP || $value == 'g-' . $gID ? ' selected="selected"' : '') . ($context->controller->multishop_context_group == false ? ' disabled="disabled"' : '') . '>' . Translate::getAdminTranslation('Group:') . ' ' . htmlspecialchars($group_data['name']) . '</option>';
         } else {
             $html .= '<optgroup class="group" label="' . Translate::getAdminTranslation('Group:') . ' ' . htmlspecialchars($group_data['name']) . '"' . ($context->controller->multishop_context_group == false ? ' disabled="disabled"' : '') . '>';
         }
         if (!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_SHOP) {
             foreach ($group_data['shops'] as $sID => $shopData) {
                 if ($shopData['active']) {
                     $html .= '<option value="s-' . $sID . '" class="shop"' . ($value == 's-' . $sID ? ' selected="selected"' : '') . '>' . ($context->controller->multishop_context_group == false ? htmlspecialchars($group_data['name']) . ' - ' : '') . $shopData['name'] . '</option>';
                 }
             }
         }
         if (!(!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP)) {
             $html .= '</optgroup>';
         }
     }
     $html .= '</select>';
     return $html;
 }
Exemplo n.º 12
0
 private function _getContextShop()
 {
     switch ($context_type = Shop::getContext()) {
         case Shop::CONTEXT_SHOP:
             $context_id = Shop::getContextShopID();
             break;
         case Shop::CONTEXT_GROUP:
             $context_id = Shop::getContextShopGroupID();
             break;
     }
     return array($context_type, isset($context_id) ? $context_id : null);
 }
Exemplo n.º 13
0
 public function getConfigFieldsValues()
 {
     $id_shop_group = Shop::getContextShopGroupID();
     $id_shop = Shop::getContextShopID();
     return array('PAYMENTWALL_APP_KEY' => Tools::getValue('PAYMENTWALL_APP_KEY', Configuration::get('PAYMENTWALL_APP_KEY', null, $id_shop_group, $id_shop)), 'PAYMENTWALL_SECRET_KEY' => Tools::getValue('PAYMENTWALL_SECRET_KEY', Configuration::get('PAYMENTWALL_SECRET_KEY', null, $id_shop_group, $id_shop)), 'PAYMENTWALL_WIDGET_TYPE' => Tools::getValue('PAYMENTWALL_WIDGET_TYPE', Configuration::get('PAYMENTWALL_WIDGET_TYPE', null, $id_shop_group, $id_shop)), 'PAYMENTWALL_TEST_MODE' => Tools::getValue('PAYMENTWALL_TEST_MODE', Configuration::get('PAYMENTWALL_TEST_MODE', null, $id_shop_group, $id_shop)), 'PAYMENTWALL_ORDER_STATUS' => Tools::getValue('PAYMENTWALL_ORDER_STATUS', Configuration::get('PAYMENTWALL_ORDER_STATUS', null, $id_shop_group, $id_shop)));
 }
Exemplo n.º 14
0
 public function processDuplicate()
 {
     if (!Module::isInstalled('agilemultipleseller')) {
         parent::processDuplicate();
     } else {
         if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
             $id_product_old = $product->id;
             if (empty($product->price) && Shop::getContext() == Shop::CONTEXT_GROUP) {
                 $shops = ShopGroup::getShopsFromGroup(Shop::getContextShopGroupID());
                 foreach ($shops as $shop) {
                     if ($product->isAssociatedToShop($shop['id_shop'])) {
                         $product_price = new Product($id_product_old, false, null, $shop['id_shop']);
                         $product->price = $product_price->price;
                     }
                 }
             }
             unset($product->id);
             unset($product->id_product);
             $product->indexed = 0;
             $product->active = 0;
             if ($product->add() && Category::duplicateProductCategories($id_product_old, $product->id) && ($combination_images = Product::duplicateAttributes($id_product_old, $product->id)) !== false && GroupReduction::duplicateReduction($id_product_old, $product->id) && Product::duplicateAccessories($id_product_old, $product->id) && Product::duplicateFeatures($id_product_old, $product->id) && Product::duplicateSpecificPrices($id_product_old, $product->id) && Pack::duplicate($id_product_old, $product->id) && Product::duplicateCustomizationFields($id_product_old, $product->id) && Product::duplicateTags($id_product_old, $product->id) && Product::duplicateDownload($id_product_old, $product->id)) {
                 if ($product->hasAttributes()) {
                     Product::updateDefaultAttribute($product->id);
                 }
                 AgileSellerManager::assignObjectOwner('product', $product->id, AgileSellerManager::getObjectOwnerID('product', $id_product_old));
                 if (!Tools::getValue('noimage') && !Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {
                     $this->errors[] = Tools::displayError('An error occurred while copying images.');
                 } else {
                     Hook::exec('actionProductAdd', array('product' => $product));
                     if (in_array($product->visibility, array('both', 'search')) && Configuration::get('PS_SEARCH_INDEXATION')) {
                         Search::indexation(false, $product->id);
                     }
                     $this->redirect_after = self::$currentIndex . (Tools::getIsset('id_category') ? '&id_category=' . (int) Tools::getValue('id_category') : '') . '&conf=19&token=' . $this->token;
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while creating an object.');
             }
         }
     }
 }
Exemplo n.º 15
0
    /**
     * Get Wishlists number products by Customer ID
     *
     * @return array Results
     */
    public static function getInfosByIdCustomer($id_customer)
    {
        if (Shop::getContextShopID()) {
            $shop_restriction = 'AND id_shop = ' . (int) Shop::getContextShopID();
        } elseif (Shop::getContextShopGroupID()) {
            $shop_restriction = 'AND id_shop_group = ' . (int) Shop::getContextShopGroupID();
        } else {
            $shop_restriction = '';
        }
        if (!Validate::isUnsignedId($id_customer)) {
            die(Tools::displayError());
        }
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT SUM(wp.`quantity`) AS nbProducts, wp.`id_wishlist`
		  FROM `' . _DB_PREFIX_ . 'wishlist_product` wp
		INNER JOIN `' . _DB_PREFIX_ . 'wishlist` w ON (w.`id_wishlist` = wp.`id_wishlist`)
		WHERE w.`id_customer` = ' . (int) $id_customer . '
		' . $shop_restriction . '
		GROUP BY w.`id_wishlist`
		ORDER BY w.`name` ASC');
    }
Exemplo n.º 16
0
    protected function _postProcess()
    {
        $languages = Language::getLanguages();
        $result = Db::getInstance()->ExecuteS('SHOW TABLES');
        $existing_tables = array();
        foreach ($result as $row) {
            foreach ($row as $key => $table) {
                array_push($existing_tables, $table);
            }
        }
        //hide or display installation instructions
        if (Tools::getValue('dhl_shi') != "") {
            if (Tools::getValue('dhl_shi') == "inline") {
                Configuration::updateValue('DHL_INSTALL', "none");
            } else {
                Configuration::updateValue('DHL_INSTALL', "inline");
            }
        }
        if (Tools::isSubmit('updateSettings')) {
            if (Tools::getValue('dhl_pack') != $this->_dhl_pack) {
                $query = 'TRUNCATE `' . _DB_PREFIX_ . 'fe_dhl_invalid_dest`';
                Db::getInstance()->Execute($query);
            }
            if (!Configuration::updateValue('DHL_SITE_ID', str_replace(' ', '', Tools::getValue('dhl_site_id'))) || !Configuration::updateValue('DHL_PASS', str_replace(' ', '', Tools::getValue('dhl_pass'))) || !Configuration::updateValue('DHL_ACCOUNT_NUMBER', str_replace(' ', '', Tools::getValue('dhl_account_number'))) || !Configuration::updateValue('DHL_DROPOFF', Tools::getValue('dhl_dropoff')) || !Configuration::updateValue('DHL_UNIT', Tools::getValue('dhl_unit')) || !Configuration::updateValue('DHL_PACK', Tools::getValue('dhl_pack')) || !Configuration::updateValue('DHL_WIDTH', Tools::getValue('dhl_width')) || !Configuration::updateValue('DHL_HEIGHT', Tools::getValue('dhl_height')) || !Configuration::updateValue('DHL_DEPTH', Tools::getValue('dhl_depth')) || !Configuration::updateValue('DHL_WEIGHT', Tools::getValue('dhl_weight')) || !Configuration::updateValue('DHL_ORIGIN_ZIP', Tools::getValue('dhl_origin_zip')) || !Configuration::updateValue('DHL_ORIGIN_COUNTRY', Tools::getValue('dhl_origin_country')) || !Configuration::updateValue('DHL_ORIGIN_CITY', Tools::getValue('dhl_origin_city')) || !Configuration::updateValue('DHL_TYPE', Tools::getValue('dhl_type')) || !Configuration::updateValue('DHL_PACKAGES', Tools::getValue('dhl_packages')) || !Configuration::updateValue('DHL_PACKAGE_SIZE', Tools::getValue('dhl_package_size')) || !Configuration::updateValue('DHL_PACKAGES_PER_BOX', Tools::getValue('dhl_packages_per_box')) || !Configuration::updateValue('DHL_OVERRIDE_ADDRESS', Tools::getValue('dhl_override_address')) || !Configuration::updateValue('DHL_DEBUG_MODE', Tools::getValue('dhl_debug_mode')) || !Configuration::updateValue('DHL_ADDRESS_DISPLAY', serialize(array('country' => Tools::getValue('dhl_country_display'), 'state' => Tools::getValue('dhl_state_display'), 'city' => Tools::getValue('dhl_city_display'), 'zip' => Tools::getValue('dhl_zip_display')))) || !Configuration::updateValue('DHL_XML_LOG', Tools::getValue('dhl_xml_log')) || !Configuration::updateValue('DHL_CURRENCY_USED', Tools::getValue('dhl_currency_used')) || !Configuration::updateValue('DHL_DISCOUNT_RATE', Tools::getValue('dhl_discount_rate')) || !Configuration::updateValue('DHL_MODE', Tools::getValue('dhl_mode'))) {
                if ($this->getPSV() == 1.6) {
                    $this->_html .= $this->displayError($this->l('Cannot update settings'));
                } else {
                    $this->_html .= '<div class="alert error">' . $this->l('Cannot update settings') . '</div>';
                }
            } else {
                if ($this->getPSV() == 1.6) {
                    $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
                } else {
                    $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('Confirmation') . '" />' . $this->l('Settings updated') . '</div>';
                }
            }
        }
        if (Tools::getValue('ssr') == 'show') {
            $this->registerHook($this->getPSV() >= 1.5 ? 'displayProductButtons' : 'productActions');
            $this->registerHook('cartShippingPreview');
            Configuration::updateValue('DHL_SHIPPING_RATES_BUTTON', 'show');
        } elseif (Tools::getValue('ssr') == 'hide') {
            $this->unregisterHook($this->getPSV() >= 1.5 ? Hook::getIdByName('displayProductButtons') : Hook::get('productActions'));
            $this->unregisterHook($this->getPSV() >= 1.5 ? Hook::getIdByName('cartShippingPreview') : Hook::get('cartShippingPreview'));
            Configuration::updateValue('DHL_SHIPPING_RATES_BUTTON', 'hide');
        }
        if (Tools::isSubmit('addMethod')) {
            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier` (name, url, active, is_module, shipping_external, need_range, shipping_method, external_module_name) VALUES("' . (Tools::getValue('dhl_carrier_name') != "" ? Tools::getValue('dhl_carrier_name') : " ") . '", "http://www.dhl.com/content/g0/en/express/tracking.shtml?brand=DHL&AWB=@",  "1","1","1","1","1","dhl")';
            Db::getInstance()->Execute($query);
            $id_carrier = Db::getInstance()->Insert_ID();
            if ($this->getPSV() >= 1.5) {
                Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'carrier set id_reference = ' . $id_carrier . ' WHERE id_carrier = ' . $id_carrier);
            }
            if (in_array(_DB_PREFIX_ . "carrier_group", $existing_tables)) {
                $id_groups = Db::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'group GROUP BY id_group');
                foreach ($id_groups as $group) {
                    $query = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_group` (id_carrier, id_group) VALUES("' . $id_carrier . '", "' . $group['id_group'] . '")';
                    Db::getInstance()->Execute($query);
                }
            }
            if ($this->getPSV() >= 1.5) {
                /** $this->context->shop is not accurate */
                $id_shop_group = Shop::getContextShopGroupID(true);
                $id_shop = Shop::getContextShopID(true);
                /** if shop group is selected */
                if (!$id_shop && $id_shop_group) {
                    $shops = Shop::getShops(false, $id_shop_group);
                } elseif (!$id_shop && !$id_shop_group) {
                    $shops = Shop::getShops(false);
                } else {
                    $shops = array(0 => array('id_shop' => $id_shop));
                }
                if (is_array($shops) && count($shops)) {
                    foreach ($shops as $shop) {
                        if (in_array(_DB_PREFIX_ . "carrier_tax_rules_group_shop", $existing_tables)) {
                            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_tax_rules_group_shop` (id_carrier, id_tax_rules_group, id_shop) VALUES("' . $id_carrier . '", "0","' . $shop['id_shop'] . '")';
                            Db::getInstance()->Execute($query);
                        }
                        if (in_array(_DB_PREFIX_ . "carrier_shop", $existing_tables)) {
                            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_shop` (id_carrier, id_shop) VALUES("' . $id_carrier . '", "' . $shop['id_shop'] . '")';
                            Db::getInstance()->Execute($query);
                        }
                        /** insert carrier language for the store */
                        foreach ($languages as $language) {
                            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_lang` (id_carrier, id_shop, id_lang, delay) VALUES("' . (int) $id_carrier . '", "' . $shop['id_shop'] . '", "' . (int) $language['id_lang'] . '", "' . (Tools::getValue('dhl_transit_time') != "" ? Tools::getValue('dhl_transit_time') : " ") . '")';
                            Db::getInstance()->Execute($query);
                        }
                    }
                } else {
                    die('fatal error: could not create carrier, reload the page and try again');
                }
            } else {
                /** insert carrier language for the store */
                foreach ($languages as $language) {
                    $query = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_lang` (id_carrier, id_lang, delay) VALUES("' . (int) $id_carrier . '", "' . (int) $language['id_lang'] . '", "' . (Tools::getValue('dhl_transit_time') != "" ? Tools::getValue('dhl_transit_time') : " ") . '")';
                    Db::getInstance()->Execute($query);
                }
            }
            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'fe_dhl_method` (id_carrier, method, free_shipping, extra_shipping_type, extra_shipping_amount, insurance_minimum, insurance_type, insurance_amount, free_shipping_product, free_shipping_category, free_shipping_manufacturer, free_shipping_supplier) VALUES
				("' . $id_carrier . '","' . Tools::getValue('dhl_method') . '","' . intval(Tools::getValue('dhl_free_shipping')) . '",
				"' . intval(Tools::getValue('dhl_extra_charge')) . '","' . intval(Tools::getValue('dhl_extra_amount')) . '",
				"' . intval(Tools::getValue('dhl_minimum_insurance_amount')) . '","' . intval(Tools::getValue('dhl_insurance_charge')) . '",
				"' . intval(Tools::getValue('dhl_insurance_amount')) . '","","","","")';
            Db::getInstance()->Execute($query);
            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` (id_carrier, id_zone) VALUES("' . $id_carrier . '", "' . Tools::getValue('dhl_zone') . '")';
            Db::getInstance()->Execute($query);
            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'range_weight` (id_carrier, delimiter1, delimiter2) VALUES("' . $id_carrier . '", "0.00", "100000.00")';
            Db::getInstance()->Execute($query);
            $id_range_weight = Db::getInstance()->Insert_ID();
            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'delivery` (id_carrier, id_range_weight, id_zone, price) VALUES("' . $id_carrier . '", "' . $id_range_weight . '", "' . Tools::getValue('dhl_zone') . '","0")';
            Db::getInstance()->Execute($query);
            if ($this->getPSV() == 1.6) {
                $this->_html .= $this->displayConfirmation($this->l('Carrier created successfully'));
            } else {
                $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('Confirmation') . '" />' . $this->l('Carrier created successfully') . '</div>';
            }
        }
        if (Tools::isSubmit('updateShipping') || Tools::isSubmit('deleteCache') || Tools::isSubmit('updateSettings')) {
            $query = 'TRUNCATE `' . _DB_PREFIX_ . 'fe_dhl_rate_cache`';
            Db::getInstance()->Execute($query);
            $query = 'TRUNCATE `' . _DB_PREFIX_ . 'fe_dhl_hash_cache`';
            Db::getInstance()->Execute($query);
            $query = 'TRUNCATE `' . _DB_PREFIX_ . 'fe_dhl_package_rate_cache`';
            Db::getInstance()->Execute($query);
            $query = 'TRUNCATE `' . _DB_PREFIX_ . 'fe_dhl_invalid_dest`';
            Db::getInstance()->Execute($query);
            Configuration::updateValue('DHL_DOWN_TIME', '');
            //delete logs:
            $files = glob(dirname(__FILE__) . '/logs/*');
            // get all file names
            foreach ($files as $file) {
                // iterate files
                if (is_file($file) and !strstr($file, 'index.php')) {
                    unlink($file);
                }
                // delete file
            }
            if ($this->getPSV() == 1.6 && Tools::isSubmit('deleteCache')) {
                $this->_html .= $this->displayConfirmation($this->l('Shipping cache deleted successfully'));
            } elseif (Tools::isSubmit('deleteCache')) {
                $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('Confirmation') . '" />' . $this->l('Shipping cache deleted successfully') . '</div>';
            }
        }
        if (Tools::isSubmit('updateShipping')) {
            $i = 1;
            while (isset($_POST['id_' . $i]) && $_POST['id_' . $i]) {
                $query = 'UPDATE `' . _DB_PREFIX_ . 'fe_dhl_method` SET free_shipping = "' . $_POST['dhl_free_shipping_' . $i] . '",free_shipping_product = "' . $_POST['dhl_free_shipping_product_' . $i] . '",
						free_shipping_category = "' . $_POST['dhl_free_shipping_category_' . $i] . '",free_shipping_manufacturer = "' . $_POST['dhl_free_shipping_manufacturer_' . $i] . '",
						free_shipping_supplier = "' . $_POST['dhl_free_shipping_supplier_' . $i] . '",extra_shipping_type = "' . $_POST['dhl_extra_charge_' . $i] . '", extra_shipping_amount = "' . $_POST['dhl_extra_amount_' . $i] . '",
						insurance_minimum = "' . $_POST['dhl_minimum_insurance_amount_' . $i] . '", insurance_type = "' . $_POST['dhl_insurance_charge_' . $i] . '",
						insurance_amount = "' . $_POST['dhl_insurance_amount_' . $i] . '" WHERE id_carrier = "' . $_POST['id_' . $i] . '"';
                Db::getInstance()->Execute($query);
                $i++;
            }
            if ($this->getPSV() == 1.6) {
                $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
            } else {
                $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('Confirmation') . '" />' . $this->l('Settings updated') . '</div>';
            }
        }
        if (Tools::isSubmit('updateShipperInfo')) {
            Configuration::updateValue('DHL_SHIPPER_SHOP_NAME', Tools::getValue('shipper_shop_name'));
            Configuration::updateValue('DHL_SHIPPER_ATTENTION_NAME', Tools::getValue('shipper_attention_name'));
            Configuration::updateValue('DHL_SHIPPER_PHONE', Tools::getValue('shipper_phone'));
            Configuration::updateValue('DHL_SHIPPER_ADDR1', Tools::getValue('shipper_address1'));
            Configuration::updateValue('DHL_SHIPPER_ADDR2', Tools::getValue('shipper_address2'));
            Configuration::updateValue('DHL_SHIPPER_CITY', Tools::getValue('shipper_city'));
            Configuration::updateValue('DHL_SHIPPER_COUNTRY', Tools::getValue('shipper_country'));
            Configuration::updateValue('DHL_SHIPPER_STATE', Tools::getValue('shipper_state'));
            Configuration::updateValue('DHL_SHIPPER_POSTCODE', Tools::getValue('shipper_postcode'));
            Configuration::updateValue('DHL_ENABLE_LABELS', Tools::getValue('dhl_enable_labels'));
            Configuration::updateValue('DHL_LABEL_ORDER_STATUS', Tools::getValue('label_order_status'));
            if ($this->getPSV() == 1.6) {
                $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
            } else {
                $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('Confirmation') . '" />' . $this->l('Settings updated') . '</div>';
            }
        }
        $this->_refreshProperties();
    }
Exemplo n.º 17
0
    public function postProcessCallback()
    {
        $return = false;
        $installed_modules = array();
        foreach ($this->map as $key => $method) {
            $modules = Tools::getValue($key);
            if (strpos($modules, '|')) {
                $modules_list_save = $modules;
                $modules = explode('|', $modules);
            } else {
                $modules = empty($modules) ? false : array($modules);
            }
            $module_errors = array();
            if ($modules) {
                foreach ($modules as $name) {
                    $full_report = null;
                    if ($key == 'update') {
                        if (ConfigurationTest::test_dir('modules/' . $name, true, $full_report)) {
                            Tools::deleteDirectory('../modules/' . $name . '/');
                        } else {
                            $module = Module::getInstanceByName(urldecode($name));
                            $this->errors[] = $this->l(sprintf("Module %s can't be upgraded : ", $module->displayName)) . $full_report;
                            continue;
                        }
                    }
                    // If Addons module, download and unzip it before installing it
                    if (!file_exists('../modules/' . $name . '/' . $name . '.php')) {
                        $filesList = array(array('type' => 'addonsNative', 'file' => Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0), array('type' => 'addonsBought', 'file' => Module::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1));
                        foreach ($filesList as $f) {
                            if (file_exists(_PS_ROOT_DIR_ . $f['file'])) {
                                $file = $f['file'];
                                $content = Tools::file_get_contents(_PS_ROOT_DIR_ . $file);
                                $xml = @simplexml_load_string($content, null, LIBXML_NOCDATA);
                                foreach ($xml->module as $modaddons) {
                                    if ($name == $modaddons->name && isset($modaddons->id) && ($this->logged_on_addons || $f['loggedOnAddons'] == 0)) {
                                        if ($f['loggedOnAddons'] == 0) {
                                            if (file_put_contents('../modules/' . $modaddons->name . '.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id))))) {
                                                $this->extractArchive('../modules/' . $modaddons->name . '.zip', false);
                                            }
                                        }
                                        if ($f['loggedOnAddons'] == 1 && $this->logged_on_addons) {
                                            if (file_put_contents('../modules/' . $modaddons->name . '.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))))) {
                                                $this->extractArchive('../modules/' . $modaddons->name . '.zip', false);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // Check potential error
                    if (!($module = Module::getInstanceByName(urldecode($name)))) {
                        $this->errors[] = $this->l('Module not found');
                    } elseif ($key == 'install' && $this->tabAccess['add'] !== '1') {
                        $this->errors[] = Tools::displayError('You do not have permission to install this module.');
                    } elseif ($key == 'uninstall' && ($this->tabAccess['delete'] !== '1' || !$module->getPermission('configure'))) {
                        $this->errors[] = Tools::displayError('You do not have permission to delete this module.');
                    } elseif ($key == 'configure' && ($this->tabAccess['edit'] !== '1' || !$module->getPermission('configure') || !Module::isInstalled(urldecode($name)))) {
                        $this->errors[] = Tools::displayError('You do not have permission to configure this module.');
                    } elseif ($key == 'install' && Module::isInstalled($module->name)) {
                        $this->errors[] = Tools::displayError('This module is already installed:') . ' ' . $module->name;
                    } elseif ($key == 'uninstall' && !Module::isInstalled($module->name)) {
                        $this->errors[] = Tools::displayError('This module has already been uninstalled:') . ' ' . $module->name;
                    } else {
                        if ($key == 'update' && !Module::isInstalled($module->name)) {
                            $this->errors[] = Tools::displayError('This module need to be installed in order to be updated:') . ' ' . $module->name;
                        } else {
                            // If we install a module, force temporary global context for multishop
                            if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && $method != 'getContent') {
                                Context::getContext()->tmpOldShop = clone Context::getContext()->shop;
                                Context::getContext()->shop = new Shop();
                            }
                            //retrocompatibility
                            if (Tools::getValue('controller') != '') {
                                $_POST['tab'] = Tools::safeOutput(Tools::getValue('controller'));
                            }
                            $echo = '';
                            if ($key != 'update') {
                                // We check if method of module exists
                                if (!method_exists($module, $method)) {
                                    throw new PrestaShopException('Method of module can\'t be found');
                                }
                                // Get the return value of current method
                                $echo = $module->{$method}();
                            }
                            // If the method called is "configure" (getContent method), we show the html code of configure page
                            if ($key == 'configure' && Module::isInstalled($module->name)) {
                                if (isset($module->multishop_context)) {
                                    $this->multishop_context = $module->multishop_context;
                                }
                                $backlink = self::$currentIndex . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name;
                                $hooklink = 'index.php?tab=AdminModulesPositions&token=' . Tools::getAdminTokenLite('AdminModulesPositions') . '&show_modules=' . (int) $module->id;
                                $tradlink = 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&lang=';
                                $toolbar = '<table class="table" cellpadding="0" cellspacing="0" style="margin:auto;text-align:center"><tr>
									<th>' . $this->l('Module') . ' <span style="color: green;">' . $module->name . '</span></th>
									<th><a href="' . $backlink . '" style="padding:5px 10px">' . $this->l('Back') . '</a></th>
									<th><a href="' . $hooklink . '" style="padding:5px 10px">' . $this->l('Manage hooks') . '</a></th>
									<th style="padding:5px 10px">' . $this->l('Manage translations') . ' ';
                                foreach (Language::getLanguages(false) as $language) {
                                    $toolbar .= '<a href="' . $tradlink . $language['iso_code'] . '#' . $module->name . '" style="margin-left:5px"><img src="' . _THEME_LANG_DIR_ . $language['id_lang'] . '.jpg" alt="' . $language['iso_code'] . '" title="' . $language['iso_code'] . '" /></a>';
                                }
                                $toolbar .= '</th></tr>';
                                // Display checkbox in toolbar if multishop
                                if (Shop::isFeatureActive()) {
                                    $activateOnclick = 'onclick="location.href = \'' . $this->getCurrentUrl('enable') . '&enable=\'+(($(this).attr(\'checked\')) ? 1 : 0)"';
                                    $toolbar .= '<tr>
										<th colspan="4">
											<input type="checkbox" name="activateModule" value="1" ' . ($module->active ? 'checked="checked"' : '') . ' ' . $activateOnclick . ' /> ' . $this->l('Activate module for') . ' ';
                                    if (Shop::getContext() == Shop::CONTEXT_SHOP) {
                                        $toolbar .= 'shop <b>' . $this->context->shop->name . '</b>';
                                    } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
                                        $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
                                        $toolbar .= 'all shops of group shop <b>' . $shop_group->name . '</b>';
                                    } else {
                                        $toolbar .= 'all shops';
                                    }
                                    $toolbar .= '</th>
								</tr>';
                                }
                                $toolbar .= '</table>';
                                if (Shop::isFeatureActive() && isset(Context::getContext()->tmpOldShop)) {
                                    Context::getContext()->shop = clone Context::getContext()->tmpOldShop;
                                    unset(Context::getContext()->tmpOldShop);
                                }
                                // Display module configuration
                                $this->context->smarty->assign('module_content', $toolbar . '<div class="clear">&nbsp;</div>' . $echo . '<div class="clear">&nbsp;</div>' . $toolbar);
                            } elseif ($echo === true) {
                                $return = 13;
                                if ($method == 'install') {
                                    $return = 12;
                                    $installed_modules[] = $module->id;
                                }
                            } elseif ($echo === false) {
                                $module_errors[] = array('name' => $name, 'message' => $module->getErrors());
                            }
                            if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && isset(Context::getContext()->tmpOldShop)) {
                                Context::getContext()->shop = clone Context::getContext()->tmpOldShop;
                                unset(Context::getContext()->tmpOldShop);
                            }
                        }
                    }
                    if ($key != 'configure' && isset($_GET['bpay'])) {
                        Tools::redirectAdmin('index.php?tab=AdminPayment&token=' . Tools::getAdminToken('AdminPayment' . (int) Tab::getIdFromClassName('AdminPayment') . (int) $this->id_employee));
                    }
                }
            }
            if (count($module_errors)) {
                // If error during module installation, no redirection
                $html_error = $this->generateHtmlMessage($module_errors);
                $this->errors[] = sprintf(Tools::displayError('The following module(s) were not installed properly: %s'), $html_error);
                $this->context->smarty->assign('error_module', 'true');
            }
        }
        if ($return) {
            $params = count($installed_modules) ? '&installed_modules=' . implode('|', $installed_modules) : '';
            // If redirect parameter is present and module installed with success, we redirect on configuration module page
            if (Tools::getValue('redirect') == 'config' && Tools::getValue('module_name') != '' && $return == '12' && Module::isInstalled(pSQL(Tools::getValue('module_name')))) {
                Tools::redirectAdmin('index.php?controller=adminmodules&configure=' . Tools::getValue('module_name') . '&token=' . Tools::getValue('token') . '&module_name=' . Tools::getValue('module_name') . $params);
            }
            Tools::redirectAdmin(self::$currentIndex . '&conf=' . $return . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name . '&anchor=anchor' . ucfirst($module->name) . (isset($modules_list_save) ? '&modules_list=' . $modules_list_save : '') . $params);
        }
    }
Exemplo n.º 18
0
 public function getCarriers($id_zone = NULL, $cart = NULL, $is_cart = false, $product = NULL)
 {
     if ($this->getPSV() >= 1.5) {
         /** $this->context->shop is not accurate */
         $id_shop_group = Shop::getContextShopGroupID(true);
         $id_shop = Shop::getContextShopID(true);
         /** if shop group is selected */
         if (!$id_shop && $id_shop_group) {
             $shops = Shop::getShops(false, $id_shop_group, true);
         } elseif (!$id_shop && !$id_shop_group) {
             $shops = Shop::getShops(false, null, true);
         } else {
             $shops[$id_shop] = $id_shop;
         }
     }
     // for compatibility
     if ($this->name == 'localizedshipping') {
         $name = 'shp';
     } else {
         $name = $this->name;
     }
     $cart_carriers = $this->getProductCarriers($cart, $is_cart, $product);
     $query = '
         SELECT *
         FROM `' . _DB_PREFIX_ . 'carrier` c, `' . _DB_PREFIX_ . 'carrier_zone` cz,`' . _DB_PREFIX_ . 'fe_' . $name . '_method` ffm ' . ($this->getPSV() >= 1.5 ? ',`' . _DB_PREFIX_ . 'carrier_shop` cs' : '') . '
         WHERE c.active = 1 AND c.deleted = 0 AND c.id_carrier = ffm.id_carrier AND c.id_carrier = cz.id_carrier' . ($id_zone ? ' AND cz.id_zone = "' . (int) $id_zone . '"' : '') . (sizeof($cart_carriers) ? ' AND c.id_carrier IN (' . implode(',', $cart_carriers) . ')' : '') . ($this->getPSV() >= 1.5 ? ' AND c.id_carrier = cs.id_carrier AND cs.`id_shop` IN (' . implode(',', $shops) . ')' : '') . ' GROUP BY c.`id_carrier`';
     $result = Db::getInstance()->executeS($query);
     return $result;
 }
Exemplo n.º 19
0
            }
        } else {
            if (Shop::getShop($split[1]) && Context::getContext()->employee->hasAuthOnShop($split[1])) {
                $shop_id = $split[1];
                Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
            } else {
                $shop_id = Context::getContext()->employee->getDefaultShopID();
                Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
            }
        }
    }
}
// Check multishop context and set right context if need
if (Shop::getContext()) {
    if (Shop::getContext() == Shop::CONTEXT_SHOP && !Shop::CONTEXT_SHOP) {
        Shop::setContext(Shop::CONTEXT_GROUP, Shop::getContextShopGroupID());
    }
    if (Shop::getContext() == Shop::CONTEXT_GROUP && !Shop::CONTEXT_GROUP) {
        Shop::setContext(Shop::CONTEXT_ALL);
    }
}
// Replace existing shop if necessary
if (!$shop_id) {
    Context::getContext()->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
} elseif (Context::getContext()->shop->id != $shop_id) {
    Context::getContext()->shop = new Shop($shop_id);
}
require_once $module_path;
$grid = new $module();
$grid->setEmployee($id_employee);
$grid->setLang($id_lang);
Exemplo n.º 20
0
 /**
  * Check if configuration var is defined in given context
  *
  * @param string $key
  * @param int $id_lang
  * @param int $context
  */
 public static function hasContext($key, $id_lang, $context)
 {
     if (Shop::getContext() == Shop::CONTEXT_ALL) {
         $id_shop = $id_shop_group = null;
     } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
         $id_shop_group = Shop::getContextShopGroupID(true);
         $id_shop = null;
     } else {
         $id_shop_group = Shop::getContextShopGroupID(true);
         $id_shop = Shop::getContextShopID(true);
     }
     if ($context == Shop::CONTEXT_SHOP && Configuration::hasKey($key, $id_lang, null, $id_shop)) {
         return true;
     } elseif ($context == Shop::CONTEXT_GROUP && Configuration::hasKey($key, $id_lang, $id_shop_group)) {
         return true;
     } elseif ($context == Shop::CONTEXT_ALL && Configuration::hasKey($key, $id_lang)) {
         return true;
     }
     return false;
 }
Exemplo n.º 21
0
 public function initFormQuantities($obj)
 {
     if (!$this->default_form_language) {
         $this->getLanguages();
     }
     $data = $this->createTemplate($this->tpl_form);
     $data->assign('default_form_language', $this->default_form_language);
     if ($obj->id) {
         if ($this->product_exists_in_shop) {
             // Get all id_product_attribute
             $attributes = $obj->getAttributesResume($this->context->language->id);
             if (empty($attributes)) {
                 $attributes[] = array('id_product_attribute' => 0, 'attribute_designation' => '');
             }
             // Get available quantities
             $available_quantity = array();
             $product_designation = array();
             foreach ($attributes as $attribute) {
                 // Get available quantity for the current product attribute in the current shop
                 $available_quantity[$attribute['id_product_attribute']] = StockAvailable::getQuantityAvailableByProduct((int) $obj->id, $attribute['id_product_attribute']);
                 // Get all product designation
                 $product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id] . ' - ' . $attribute['attribute_designation'], ' - ');
             }
             $show_quantities = true;
             $shop_context = Shop::getContext();
             $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
             // if we are in all shops context, it's not possible to manage quantities at this level
             if (Shop::isFeatureActive() && $shop_context == Shop::CONTEXT_ALL) {
                 $show_quantities = false;
             } elseif (Shop::isFeatureActive() && $shop_context == Shop::CONTEXT_GROUP) {
                 // if quantities are not shared between shops of the group, it's not possible to manage them at group level
                 if (!$shop_group->share_stock) {
                     $show_quantities = false;
                 }
             } else {
                 // if quantities are shared between shops of the group, it's not possible to manage them for a given shop
                 if ($shop_group->share_stock) {
                     $show_quantities = false;
                 }
             }
             $data->assign('ps_stock_management', Configuration::get('PS_STOCK_MANAGEMENT'));
             $data->assign('has_attribute', $obj->hasAttributes());
             // Check if product has combination, to display the available date only for the product or for each combination
             if (Combination::isFeatureActive()) {
                 $data->assign('countAttributes', (int) Db::getInstance()->getValue('SELECT COUNT(id_product) FROM ' . _DB_PREFIX_ . 'product_attribute WHERE id_product = ' . (int) $obj->id));
             } else {
                 $data->assign('countAttributes', false);
             }
             // if advanced stock management is active, checks associations
             $advanced_stock_management_warning = false;
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $obj->advanced_stock_management) {
                 $p_attributes = Product::getProductAttributesIds($obj->id);
                 $warehouses = array();
                 if (!$p_attributes) {
                     $warehouses[] = Warehouse::getProductWarehouseList($obj->id, 0);
                 }
                 foreach ($p_attributes as $p_attribute) {
                     $ws = Warehouse::getProductWarehouseList($obj->id, $p_attribute['id_product_attribute']);
                     if ($ws) {
                         $warehouses[] = $ws;
                     }
                 }
                 $warehouses = Tools::arrayUnique($warehouses);
                 if (empty($warehouses)) {
                     $advanced_stock_management_warning = true;
                 }
             }
             if ($advanced_stock_management_warning) {
                 $this->displayWarning($this->l('If you wish to use the advanced stock management, you must:'));
                 $this->displayWarning('- ' . $this->l('associate your products with warehouses.'));
                 $this->displayWarning('- ' . $this->l('associate your warehouses with carriers.'));
                 $this->displayWarning('- ' . $this->l('associate your warehouses with the appropriate shops.'));
             }
             $pack_quantity = null;
             // if product is a pack
             if (Pack::isPack($obj->id)) {
                 $items = Pack::getItems((int) $obj->id, Configuration::get('PS_LANG_DEFAULT'));
                 // gets an array of quantities (quantity for the product / quantity in pack)
                 $pack_quantities = array();
                 foreach ($items as $item) {
                     if (!$item->isAvailableWhenOutOfStock((int) $item->out_of_stock)) {
                         $pack_id_product_attribute = Product::getDefaultAttribute($item->id, 1);
                         $pack_quantities[] = Product::getQuantity($item->id, $pack_id_product_attribute) / ($item->pack_quantity !== 0 ? $item->pack_quantity : 1);
                     }
                 }
                 // gets the minimum
                 if (count($pack_quantities)) {
                     $pack_quantity = $pack_quantities[0];
                     foreach ($pack_quantities as $value) {
                         if ($pack_quantity > $value) {
                             $pack_quantity = $value;
                         }
                     }
                 }
                 if (!Warehouse::getPackWarehouses((int) $obj->id)) {
                     $this->displayWarning($this->l('You must have a common warehouse between this pack and its product.'));
                 }
             }
             $data->assign(array('attributes' => $attributes, 'available_quantity' => $available_quantity, 'pack_quantity' => $pack_quantity, 'stock_management_active' => Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'product_designation' => $product_designation, 'product' => $obj, 'show_quantities' => $show_quantities, 'order_out_of_stock' => Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'token_preferences' => Tools::getAdminTokenLite('AdminPPreferences'), 'token' => $this->token, 'languages' => $this->_languages, 'id_lang' => $this->context->language->id));
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before managing quantities.'));
         }
     } else {
         $this->displayWarning($this->l('You must save this product before managing quantities.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
Exemplo n.º 22
0
 public function updateOptionPsCurrencyDefault($value)
 {
     if ($value == Configuration::get('PS_CURRENCY_DEFAULT')) {
         return;
     }
     Configuration::updateValue('PS_CURRENCY_DEFAULT', $value);
     /* Set conversion rate of default currency to 1 */
     ObjectModel::updateMultishopTable('Currency', array('conversion_rate' => 1), 'a.id_currency');
     $tmp_context = Shop::getContext();
     if ($tmp_context == Shop::CONTEXT_GROUP) {
         $tmp_shop = Shop::getContextShopGroupID();
     } else {
         $tmp_shop = (int) Shop::getContextShopID();
     }
     foreach (Shop::getContextListShopID() as $id_shop) {
         Shop::setContext(Shop::CONTEXT_SHOP, (int) $id_shop);
         Currency::refreshCurrencies();
     }
     Shop::setContext($tmp_context, $tmp_shop);
 }
Exemplo n.º 23
0
 public function initShopContext()
 {
     if (!$this->context->employee->isLoggedBack()) {
         return;
     }
     // Change shop context ?
     if (Shop::isFeatureActive() && Tools::getValue('setShopContext') !== false) {
         $this->context->cookie->shopContext = Tools::getValue('setShopContext');
         $url = parse_url($_SERVER['REQUEST_URI']);
         $query = isset($url['query']) ? $url['query'] : '';
         parse_str($query, $parse_query);
         unset($parse_query['setShopContext'], $parse_query['conf']);
         $this->redirect_after = $url['path'] . '?' . http_build_query($parse_query, '', '&');
     } elseif (!Shop::isFeatureActive()) {
         $this->context->cookie->shopContext = 's-' . Configuration::get('PS_SHOP_DEFAULT');
     } elseif (Shop::getTotalShops(false, null) < 2) {
         $this->context->cookie->shopContext = 's-' . $this->context->employee->getDefaultShopID();
     }
     $shop_id = '';
     Shop::setContext(Shop::CONTEXT_ALL);
     if ($this->context->cookie->shopContext) {
         $split = explode('-', $this->context->cookie->shopContext);
         if (count($split) == 2) {
             if ($split[0] == 'g') {
                 if ($this->context->employee->hasAuthOnShopGroup($split[1])) {
                     Shop::setContext(Shop::CONTEXT_GROUP, $split[1]);
                 } else {
                     $shop_id = $this->context->employee->getDefaultShopID();
                     Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
                 }
             } elseif (Shop::getShop($split[1]) && $this->context->employee->hasAuthOnShop($split[1])) {
                 $shop_id = $split[1];
                 Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
             } else {
                 $shop_id = $this->context->employee->getDefaultShopID();
                 Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
             }
         }
     }
     // Check multishop context and set right context if need
     if (!($this->multishop_context & Shop::getContext())) {
         if (Shop::getContext() == Shop::CONTEXT_SHOP && !($this->multishop_context & Shop::CONTEXT_SHOP)) {
             Shop::setContext(Shop::CONTEXT_GROUP, Shop::getContextShopGroupID());
         }
         if (Shop::getContext() == Shop::CONTEXT_GROUP && !($this->multishop_context & Shop::CONTEXT_GROUP)) {
             Shop::setContext(Shop::CONTEXT_ALL);
         }
     }
     // Replace existing shop if necessary
     if (!$shop_id) {
         $this->context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
     } elseif ($this->context->shop->id != $shop_id) {
         $this->context->shop = new Shop($shop_id);
     }
     if ($this->context->shop->id_theme != $this->context->theme->id) {
         $this->context->theme = new Theme($this->context->shop->id_theme);
     }
     // Replace current default country
     $this->context->country = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT'));
 }
Exemplo n.º 24
0
 public function getConfigFieldsValues()
 {
     $id_shop_group = Shop::getContextShopGroupID();
     $id_shop = Shop::getContextShopID();
     return array('HOMESLIDER_WIDTH' => Tools::getValue('HOMESLIDER_WIDTH', Configuration::get('HOMESLIDER_WIDTH', null, $id_shop_group, $id_shop)), 'HOMESLIDER_SPEED' => Tools::getValue('HOMESLIDER_SPEED', Configuration::get('HOMESLIDER_SPEED', null, $id_shop_group, $id_shop)), 'HOMESLIDER_PAUSE' => Tools::getValue('HOMESLIDER_PAUSE', Configuration::get('HOMESLIDER_PAUSE', null, $id_shop_group, $id_shop)), 'HOMESLIDER_LOOP' => Tools::getValue('HOMESLIDER_LOOP', Configuration::get('HOMESLIDER_LOOP', null, $id_shop_group, $id_shop)));
 }
Exemplo n.º 25
0
    /**
     * Render an area to determinate shop association
     *
     * @return string
     */
    public function renderAssoShop($disable_shared = false)
    {
        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;
            }
        }
        $tpl = $this->createTemplate('assoshop.tpl');
        $tree = Shop::getTree();
        $nb_shop = 0;
        foreach ($tree as &$value) {
            $value['disable_shops'] = isset($value[$disable_shared]) && $value[$disable_shared];
            $nb_shop += count($value['shops']);
        }
        $tpl->assign(array('input' => array('type' => 'shop', 'values' => $tree), 'fields_value' => array('shop' => $assos), 'form_id' => $this->id, 'table' => $this->table, 'nb_shop' => $nb_shop));
        return $tpl->fetch();
    }
Exemplo n.º 26
0
    /**
     * Removes all "NOSTOTAGGING_" config entries for the current context and given language.
     *
     * @param int|null $id_lang the ID of the language object to remove the config entries for.
     * @param null|int $id_shop_group the ID of the shop context.
     * @param null|int $id_shop the ID of the shop.
     * @return bool
     */
    public function deleteAllFromContext($id_lang = null, $id_shop_group = null, $id_shop = null)
    {
        if (_PS_VERSION_ >= '1.5') {
            if ($id_shop === null) {
                $id_shop = (int) Shop::getContextShopID(true);
            }
            if ($id_shop_group === null) {
                $id_shop_group = (int) Shop::getContextShopGroupID(true);
            }
            if ($id_shop) {
                $context_restriction = ' AND `id_shop` = ' . $id_shop;
            } elseif ($id_shop_group) {
                $context_restriction = ' AND `id_shop_group` = ' . $id_shop_group . ' AND (`id_shop` IS NULL OR `id_shop` = 0)';
            } else {
                $context_restriction = ' AND (`id_shop_group` IS NULL OR `id_shop_group` = 0) AND (`id_shop` IS NULL OR `id_shop` = 0)';
            }
        } else {
            $context_restriction = '';
        }
        $config_table = _DB_PREFIX_ . 'configuration';
        $config_lang_table = $config_table . '_lang';
        if (!empty($id_lang)) {
            Db::getInstance()->execute('
				DELETE `' . $config_lang_table . '` FROM `' . $config_lang_table . '`
				INNER JOIN `' . $config_table . '`
				ON `' . $config_lang_table . '`.`id_configuration` = `' . $config_table . '`.`id_configuration`
				WHERE `' . $config_table . '`.`name` LIKE "NOSTOTAGGING_%"
				AND `id_lang` = ' . (int) $id_lang . $context_restriction);
        }
        // We do not actually delete the main config entries, just set them to NULL, as there might me other language
        // specific entries tied to them. The main entries are not used anyways if there are languages defined.
        /* todo: this breaks PS 1.4, apparently you cannot update a value that is NULL in PS 1.4.
        		Db::getInstance()->execute('
        			UPDATE `'.$config_table.'`
        			SET `value` = NULL
        			WHERE `name` LIKE "NOSTOTAGGING_%"'
        			.$context_restriction
        		);*/
        // Reload the config.
        Configuration::loadConfiguration();
        return true;
    }
Exemplo n.º 27
0
    /**
     * This tricky method generates a SQL clause to check if ranged data are overloaded by multishop
     *
     * @since 1.5.0
     *
     * @param string $range_table Range table
     *
     * @return string SQL quoer to get the delivery range table in this Shop(Group)
     */
    public static function sqlDeliveryRangeShop($range_table, $alias = 'd')
    {
        if (Shop::getContext() == Shop::CONTEXT_ALL) {
            $where = 'AND d2.id_shop IS NULL AND d2.id_shop_group IS NULL';
        } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
            $where = 'AND ((d2.id_shop_group IS NULL OR d2.id_shop_group = ' . Shop::getContextShopGroupID() . ') AND d2.id_shop IS NULL)';
        } else {
            $where = 'AND (d2.id_shop = ' . Shop::getContextShopID() . ' OR (d2.id_shop_group = ' . Shop::getContextShopGroupID() . '
					AND d2.id_shop IS NULL) OR (d2.id_shop_group IS NULL AND d2.id_shop IS NULL))';
        }
        $sql = 'AND ' . $alias . '.id_delivery = (
					SELECT d2.id_delivery
					FROM ' . _DB_PREFIX_ . 'delivery d2
					WHERE d2.id_carrier = `' . bqSQL($alias) . '`.id_carrier
						AND d2.id_zone = `' . bqSQL($alias) . '`.id_zone
						AND d2.`id_' . bqSQL($range_table) . '` = `' . bqSQL($alias) . '`.`id_' . bqSQL($range_table) . '`
						' . $where . '
					ORDER BY d2.id_shop DESC, d2.id_shop_group DESC
					LIMIT 1
				)';
        return $sql;
    }
Exemplo n.º 28
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();
    }
Exemplo n.º 29
0
 /**
  * Add an sql restriction for shops fields
  *
  * @param int $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
  * @param string $alias
  */
 public static function addSqlRestriction($share = false, $alias = null)
 {
     if ($alias) {
         $alias .= '.';
     }
     $group = Shop::getGroupFromShop(Shop::getContextShopID(), false);
     if ($share == Shop::SHARE_CUSTOMER && Shop::getContext() == Shop::CONTEXT_SHOP && $group['share_customer']) {
         $restriction = ' AND ' . $alias . 'id_shop_group = ' . (int) Shop::getContextShopGroupID();
     } else {
         $restriction = ' AND ' . $alias . 'id_shop IN (' . implode(', ', Shop::getContextListShopID($share)) . ') ';
     }
     return $restriction;
 }
Exemplo n.º 30
0
 private function getContextShop()
 {
     $contextShop = NULL;
     if ($this->isVersionOneDotFive()) {
         $contextShop[] = Shop::getContext();
         if ($contextShop[0] == Shop::CONTEXT_SHOP) {
             array_push($contextShop, Shop::getContextShopID());
         } else {
             if ($contextShop[0] == Shop::CONTEXT_GROUP) {
                 array_push($contextShop, Shop::getContextShopGroupID());
             } else {
                 array_push($contextShop, NULL);
             }
         }
     }
     return $contextShop;
 }