public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true, $use_push = false, $id_shop = null)
    {
        $output = parent::exec($hook_name, $hook_args, $id_module, $array_return, $check_exceptions, $use_push, $id_shop);
        $live_edit = Tools::isSubmit('live_edit') ? true : false;
        if (!($module_list = Hook::getHookModuleExecList($hook_name))) {
            return '';
        }
        $ip = Configuration::get('witm_config');
        $ip_array = explode(',', $ip);
        $before_output = '';
        $after_output = '';
        if (in_array(Tools::getRemoteAddr(), $ip_array) || in_array('*', $ip_array)) {
            if (Configuration::get('witm_h_m') == 1) {
                $before_output .= '
					<div class="div_infos_hook">
					<span class="infos_hook"><span onclick="display_infos_hook(\'' . $hook_name . '\')"><i class="icon-expand-alt icon-large"></i> H-M</span>
						<span class="hook_module" id="hook_module_' . $hook_name . '"><br/>
					HOOK: ' . $hook_name . '<div class="see_modules"><span onclick="display_module(\'' . $hook_name . '\')"><i class="icon-expand-alt icon-large"></i> Modules</span><span id="d_m_' . $hook_name . '" class="display_modules">';
            } else {
                $before_output .= '
					<div class="div_infos_hook">
					<span class="infos_hook">H-M
						<span class="hook_module"><br/>
					HOOK: ' . $hook_name . '<div class="see_modules"><span onclick="display_module(\'' . $hook_name . '\')"><i class="icon-expand-alt icon-large"></i> Modules</span><span id="d_m_' . $hook_name . '" class="display_modules">';
            }
            $css_js = (int) Configuration::get('witm_css_js');
            $img = '<img src="' . Context::getContext()->shop->physical_uri . '/modules/whatisthismodule/img/open_new_tab.png"/>';
            foreach ($module_list as $module) {
                $css = '';
                $js = '';
                if ($css_js == 1) {
                    foreach (Context::getContext()->controller->css_files as $key => $value) {
                        if (strstr($key, '/' . $module['module'] . '/')) {
                            $css .= '<br/> <a class="file_css" href="' . $key . '" target="_blank">CSS : ' . $key . ' ' . $img . '</a>';
                        }
                    }
                    foreach (Context::getContext()->controller->js_files as $key => $value) {
                        if (strstr($value, '/' . $module['module'] . '/')) {
                            $js .= '<br/> <a class="file_js" href="' . $value . '" target="_blank">JS : ' . $value . ' ' . $img . '</a>';
                        }
                    }
                }
                $before_output .= '<br/>- ' . $module['module'] . ($css != '' && $js != '' ? ' : ' : '') . $css . $js;
            }
            $before_output .= '</span></div></span></span>';
            $after_output .= '</div>';
        }
        if ($array_return) {
            return $output;
        } else {
            return ($live_edit ? '<script type="text/javascript">hooks_list.push(\'' . $hook_name . '\');</script>
				<div id="' . $hook_name . '" class="dndHook" style="min-height:50px">' : '') . $before_output . $output . $after_output . ($live_edit ? '</div>' : '');
        }
    }
Example #2
0
 public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true, $use_push = false, $id_shop = null)
 {
     $module_list = Hook::getHookModuleExecList($hook_name);
     if (is_array($module_list)) {
         $module_list_ids = array();
         foreach ($module_list as $module) {
             $module_list_ids[] = $module['id_module'];
         }
         self::$executedModules = array_merge(self::$executedModules, $module_list_ids);
     }
     $memoryUsage = memory_get_usage();
     $t0 = microtime(true);
     $result = parent::exec($hook_name, $hook_args, $id_module, $array_return, $check_exceptions, $use_push, $id_shop);
     self::$hookTime[$hook_name] = microtime(true) - $t0;
     self::$hookMemoryUsage[$hook_name] = memory_get_usage() - $memoryUsage;
     return $result;
 }
Example #3
0
    public function copyShopData($old_id, $tables_import = false, $deleted = false)
    {
        // If we duplicate some specific data, automatically duplicate other data linked to the first
        // E.g. if carriers are duplicated for the shop, duplicate carriers langs too
        if (!$old_id) {
            $old_id = Configuration::get('PS_SHOP_DEFAULT');
        }
        if (isset($tables_import['carrier'])) {
            $tables_import['carrier_tax_rules_group_shop'] = true;
            $tables_import['carrier_lang'] = true;
        }
        $tables_import['category_lang'] = true;
        if (isset($tables_import['product'])) {
            $tables_import['product_lang'] = true;
        }
        if (isset($tables_import['module'])) {
            $tables_import['module_currency'] = true;
            $tables_import['module_country'] = true;
            $tables_import['module_group'] = true;
        }
        if (isset($tables_import['hook_module'])) {
            $tables_import['hook_module_exceptions'] = true;
        }
        if (isset($tables_import['attribute_group'])) {
            $tables_import['attribute'] = true;
        }
        // Browse and duplicate data
        foreach (Shop::getAssoTables() as $table_name => $row) {
            if ($tables_import && !isset($tables_import[$table_name])) {
                continue;
            }
            // Special case for stock_available if current shop is in a share stock group
            if ($table_name == 'stock_available') {
                $group = new ShopGroup($this->id_shop_group);
                if ($group->share_stock && $group->haveShops()) {
                    continue;
                }
            }
            $id = 'id_' . $row['type'];
            if ($row['type'] == 'fk_shop') {
                $id = 'id_shop';
            } else {
                $table_name .= '_' . $row['type'];
            }
            if (!$deleted) {
                $res = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . $table_name . '` WHERE `' . $id . '` = ' . (int) $old_id);
                if ($res) {
                    unset($res[$id]);
                    if (isset($row['primary'])) {
                        unset($res[$row['primary']]);
                    }
                    $categories = Tools::getValue('categoryBox');
                    if ($table_name == 'product_shop' && count($categories) == 1) {
                        unset($res['id_category_default']);
                        $keys = implode('`, `', array_keys($res));
                        $sql = 'INSERT IGNORE INTO `' . _DB_PREFIX_ . $table_name . '` (`' . $keys . '`, `id_category_default`, ' . $id . ')
								(SELECT `' . $keys . '`, ' . (int) $categories[0] . ', ' . (int) $this->id . ' FROM ' . _DB_PREFIX_ . $table_name . '
								WHERE `' . $id . '` = ' . (int) $old_id . ')';
                    } else {
                        $keys = implode('`, `', array_keys($res));
                        $sql = 'INSERT IGNORE INTO `' . _DB_PREFIX_ . $table_name . '` (`' . $keys . '`, ' . $id . ')
								(SELECT `' . $keys . '`, ' . (int) $this->id . ' FROM ' . _DB_PREFIX_ . $table_name . '
								WHERE `' . $id . '` = ' . (int) $old_id . ')';
                    }
                    Db::getInstance()->execute($sql);
                }
            }
        }
        // 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) {
                if (!$tables_import || isset($tables_import['Module' . ucfirst($m['module'])])) {
                    Hook::exec('actionShopDataDuplication', array('old_id_shop' => (int) $old_id, 'new_id_shop' => (int) $this->id), $m['id_module']);
                }
            }
        }
    }
Example #4
0
    public function addNewModulesTasks()
    {
        $id_shop = (int) Context::getContext()->shop->id;
        $id_shop_group = (int) Context::getContext()->shop->id_shop_group;
        $crons = Hook::getHookModuleExecList('actionCronJob');
        if ($crons == false) {
            return false;
        }
        foreach ($crons as $cron) {
            $module = Module::getInstanceById((int) $cron['id_module']);
            if ($module == false) {
                Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . $this->name . ' WHERE `id_cronjob` = \'' . (int) $cron['id_cronjob'] . '\'');
                break;
            }
            $id_module = (int) $cron['id_module'];
            $id_cronjob = (int) Db::getInstance()->getValue('SELECT `id_cronjob` FROM `' . _DB_PREFIX_ . $this->name . '`
				WHERE `id_module` = \'' . $id_module . '\' AND `id_shop` = \'' . $id_shop . '\' AND `id_shop_group` = \'' . $id_shop_group . '\'');
            if ((bool) $id_cronjob == false) {
                $this->registerModuleHook($id_module);
            }
        }
    }
 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();
 }
Example #6
0
    public function __construct()
    {
        $this->bootstrap = true;
        $this->table = 'product';
        $this->className = 'Product';
        $this->lang = true;
        $this->explicitSelect = true;
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?')));
        if (!Tools::getValue('id_product')) {
            $this->multishop_context_group = false;
        }
        parent::__construct();
        $this->imageType = 'jpg';
        $this->_defaultOrderBy = 'position';
        $this->max_file_size = (int) (Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
        $this->max_image_size = (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
        $this->allow_export = true;
        // @since 1.5 : translations for tabs
        $this->available_tabs_lang = array('Informations' => $this->l('Information'), 'Pack' => $this->l('Pack'), 'VirtualProduct' => $this->l('Virtual Product'), 'Prices' => $this->l('Prices'), 'Seo' => $this->l('SEO'), 'Images' => $this->l('Images'), 'Associations' => $this->l('Associations'), 'Shipping' => $this->l('Shipping'), 'Combinations' => $this->l('Combinations'), 'Features' => $this->l('Features'), 'Customization' => $this->l('Customization'), 'Attachments' => $this->l('Attachments'), 'Quantities' => $this->l('Quantities'), 'Suppliers' => $this->l('Suppliers'), 'Warehouses' => $this->l('Warehouses'));
        $this->available_tabs = array('Quantities' => 6, 'Warehouses' => 14);
        if ($this->context->shop->getContext() != Shop::CONTEXT_GROUP) {
            $this->available_tabs = array_merge($this->available_tabs, array('Informations' => 0, 'Pack' => 7, 'VirtualProduct' => 8, 'Prices' => 1, 'Seo' => 2, 'Associations' => 3, 'Images' => 9, 'Shipping' => 4, 'Combinations' => 5, 'Features' => 10, 'Customization' => 11, 'Attachments' => 12, 'Suppliers' => 13));
        }
        // Sort the tabs that need to be preloaded by their priority number
        asort($this->available_tabs, SORT_NUMERIC);
        /* Adding tab if modules are hooked */
        $modules_list = Hook::getHookModuleExecList('displayAdminProductsExtra');
        if (is_array($modules_list) && count($modules_list) > 0) {
            foreach ($modules_list as $m) {
                $this->available_tabs['Module' . ucfirst($m['module'])] = 23;
                $this->available_tabs_lang['Module' . ucfirst($m['module'])] = Module::getModuleName($m['module']);
            }
        }
        if (Tools::getValue('reset_filter_category')) {
            $this->context->cookie->id_category_products_filter = false;
        }
        if (Shop::isFeatureActive() && $this->context->cookie->id_category_products_filter) {
            $category = new Category((int) $this->context->cookie->id_category_products_filter);
            if (!$category->inShop()) {
                $this->context->cookie->id_category_products_filter = false;
                Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts'));
            }
        }
        /* Join categories table */
        if ($id_category = (int) Tools::getValue('productFilter_cl!name')) {
            $this->_category = new Category((int) $id_category);
            $_POST['productFilter_cl!name'] = $this->_category->name[$this->context->language->id];
        } else {
            if ($id_category = (int) Tools::getValue('id_category')) {
                $this->id_current_category = $id_category;
                $this->context->cookie->id_category_products_filter = $id_category;
            } elseif ($id_category = $this->context->cookie->id_category_products_filter) {
                $this->id_current_category = $id_category;
            }
            if ($this->id_current_category) {
                $this->_category = new Category((int) $this->id_current_category);
            } else {
                $this->_category = new Category();
            }
        }
        $join_category = false;
        if (Validate::isLoadedObject($this->_category) && empty($this->_filter)) {
            $join_category = true;
        }
        $this->_join .= '
		LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = a.`id_product`)
		LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
		' . StockAvailable::addSqlShopRestriction(null, null, 'sav') . ') ';
        $alias = 'sa';
        $alias_image = 'image_shop';
        $id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ? (int) $this->context->shop->id : 'a.id_shop_default';
        $this->_join .= ' JOIN `' . _DB_PREFIX_ . 'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = ' . $id_shop . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = ' . $id_shop . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'shop` shop ON (shop.id_shop = ' . $id_shop . ') 
				LEFT JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = ' . $id_shop . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'product_download` pd ON (pd.`id_product` = a.`id_product`)';
        $this->_select .= 'shop.name as shopname, a.id_shop_default, ';
        $this->_select .= 'MAX(' . $alias_image . '.id_image) id_image, cl.name `name_category`, ' . $alias . '.`price`, 0 AS price_final, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` as sav_quantity, ' . $alias . '.`active`, IF(sav.`quantity`<=0, 1, 0) badge_danger';
        if ($join_category) {
            $this->_join .= ' INNER JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = ' . (int) $this->_category->id . ') ';
            $this->_select .= ' , cp.`position`, ';
        }
        $this->_group = 'GROUP BY ' . $alias . '.id_product';
        $this->fields_list = array();
        $this->fields_list['id_product'] = array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs', 'type' => 'int');
        $this->fields_list['image'] = array('title' => $this->l('Image'), 'align' => 'center', 'image' => 'p', 'orderby' => false, 'filter' => false, 'search' => false);
        $this->fields_list['name'] = array('title' => $this->l('Name'), 'filter_key' => 'b!name');
        $this->fields_list['reference'] = array('title' => $this->l('Reference'), 'align' => 'left');
        if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
            $this->fields_list['shopname'] = array('title' => $this->l('Default shop'), 'filter_key' => 'shop!name');
        } else {
            $this->fields_list['name_category'] = array('title' => $this->l('Category'), 'filter_key' => 'cl!name');
        }
        $this->fields_list['price'] = array('title' => $this->l('Base price'), 'type' => 'price', 'align' => 'text-right', 'filter_key' => 'a!price');
        $this->fields_list['price_final'] = array('title' => $this->l('Final price'), 'type' => 'price', 'align' => 'text-right', 'havingFilter' => true, 'orderby' => false, 'search' => false);
        if (Configuration::get('PS_STOCK_MANAGEMENT')) {
            $this->fields_list['sav_quantity'] = array('title' => $this->l('Quantity'), 'type' => 'int', 'align' => 'text-right', 'filter_key' => 'sav!quantity', 'orderby' => true, 'badge_danger' => true);
        }
        $this->fields_list['active'] = array('title' => $this->l('Status'), 'active' => 'status', 'filter_key' => $alias . '!active', 'align' => 'text-center', 'type' => 'bool', 'class' => 'fixed-width-sm', 'orderby' => false);
        if ($join_category && (int) $this->id_current_category) {
            $this->fields_list['position'] = array('title' => $this->l('Position'), 'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position');
        }
    }
Example #7
0
    /**
     * Execute modules for specified hook
     *
     * @param string $hook_name Hook Name
     * @param array $hook_args Parameters for the functions
     * @param int $id_module Execute hook for this module only
     * @param bool $array_return If specified, module output will be set by name in an array
     * @param bool $check_exceptions Check permission exceptions
     * @param bool $use_push Force change to be refreshed on Dashboard widgets
     * @param int $id_shop If specified, hook will be execute the shop with this ID
     *
     * @throws PrestaShopException
     *
     * @return string/array modules output
     */
    public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true, $use_push = false, $id_shop = null)
    {
        if (defined('PS_INSTALLATION_IN_PROGRESS')) {
            return;
        }
        static $disable_non_native_modules = null;
        if ($disable_non_native_modules === null) {
            $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
        }
        // Check arguments validity
        if ($id_module && !is_numeric($id_module) || !Validate::isHookName($hook_name)) {
            throw new PrestaShopException('Invalid id_module or hook_name');
        }
        // If no modules associated to hook_name or recompatible hook name, we stop the function
        if (!($module_list = Hook::getHookModuleExecList($hook_name))) {
            return '';
        }
        // Check if hook exists
        if (!($id_hook = Hook::getIdByName($hook_name))) {
            return false;
        }
        // Store list of executed hooks on this page
        Hook::$executed_hooks[$id_hook] = $hook_name;
        $live_edit = false;
        $context = Context::getContext();
        if (!isset($hook_args['cookie']) || !$hook_args['cookie']) {
            $hook_args['cookie'] = $context->cookie;
        }
        if (!isset($hook_args['cart']) || !$hook_args['cart']) {
            $hook_args['cart'] = $context->cart;
        }
        $retro_hook_name = Hook::getRetroHookName($hook_name);
        // Look on modules list
        $altern = 0;
        $output = '';
        if ($disable_non_native_modules && !isset(Hook::$native_module)) {
            Hook::$native_module = Module::getNativeModuleList();
        }
        $different_shop = false;
        if ($id_shop !== null && Validate::isUnsignedId($id_shop) && $id_shop != $context->shop->getContextShopID()) {
            $old_context = $context->shop->getContext();
            $old_shop = clone $context->shop;
            $shop = new Shop((int) $id_shop);
            if (Validate::isLoadedObject($shop)) {
                $context->shop = $shop;
                $context->shop->setContext(Shop::CONTEXT_SHOP, $shop->id);
                $different_shop = true;
            }
        }
        foreach ($module_list as $array) {
            // Check errors
            if ($id_module && $id_module != $array['id_module']) {
                continue;
            }
            if ((bool) $disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($array['module'], Hook::$native_module)) {
                continue;
            }
            // Check permissions
            if ($check_exceptions) {
                $exceptions = Module::getExceptionsStatic($array['id_module'], $array['id_hook']);
                $controller = Dispatcher::getInstance()->getController();
                $controller_obj = Context::getContext()->controller;
                //check if current controller is a module controller
                if (isset($controller_obj->module) && Validate::isLoadedObject($controller_obj->module)) {
                    $controller = 'module-' . $controller_obj->module->name . '-' . $controller;
                }
                if (in_array($controller, $exceptions)) {
                    continue;
                }
                //Backward compatibility of controller names
                $matching_name = array('authentication' => 'auth', 'productscomparison' => 'compare');
                if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) {
                    continue;
                }
                if (Validate::isLoadedObject($context->employee) && !Module::getPermissionStatic($array['id_module'], 'view', $context->employee)) {
                    continue;
                }
            }
            if (!($moduleInstance = Module::getInstanceByName($array['module']))) {
                continue;
            }
            if ($use_push && !$moduleInstance->allow_push) {
                continue;
            }
            // Check which / if method is callable
            $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
            $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
            if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) {
                $hook_args['altern'] = ++$altern;
                if ($use_push && isset($moduleInstance->push_filename) && file_exists($moduleInstance->push_filename)) {
                    Tools::waitUntilFileIsModified($moduleInstance->push_filename, $moduleInstance->push_time_limit);
                }
                // Call hook method
                if ($hook_callable) {
                    $display = Hook::coreCallHook($moduleInstance, 'hook' . $hook_name, $hook_args);
                } elseif ($hook_retro_callable) {
                    $display = Hook::coreCallHook($moduleInstance, 'hook' . $retro_hook_name, $hook_args);
                }
                // Live edit
                if (!$array_return && $array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions' . (int) Tab::getIdFromClassName('AdminModulesPositions') . (int) Tools::getValue('id_employee'))) {
                    $live_edit = true;
                    $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']);
                } elseif ($array_return) {
                    $output[$moduleInstance->name] = $display;
                } else {
                    $output .= $display;
                }
            }
        }
        if ($different_shop) {
            $context->shop = $old_shop;
            $context->shop->setContext($old_context, $shop->id);
        }
        if ($array_return) {
            return $output;
        } else {
            return ($live_edit ? '<script type="text/javascript">hooks_list.push(\'' . $hook_name . '\');</script>
				<div id="' . $hook_name . '" class="dndHook" style="min-height:50px">' : '') . $output . ($live_edit ? '</div>' : '');
        }
        // Return html string
    }
 public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true)
 {
     require_once dirname(__FILE__) . '../../../modules/designerpreview/defines.inc.php';
     static $disable_non_native_modules = null;
     if ($disable_non_native_modules === null) {
         $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
     }
     // Check arguments validity
     if ($id_module && !is_numeric($id_module) || !Validate::isHookName($hook_name)) {
         throw new PrestaShopException('Invalid id_module or hook_name');
     }
     // If no modules associated to hook_name or recompatible hook name, we stop the function
     if (!($module_list = Hook::getHookModuleExecList($hook_name))) {
         return '';
     }
     // Check if hook exists
     if (!($id_hook = Hook::getIdByName($hook_name))) {
         return false;
     }
     // Store list of executed hooks on this page
     Hook::$executed_hooks[$id_hook] = $hook_name;
     $live_edit = false;
     $context = Context::getContext();
     if (!isset($hook_args['cookie']) || !$hook_args['cookie']) {
         $hook_args['cookie'] = $context->cookie;
     }
     if (!isset($hook_args['cart']) || !$hook_args['cart']) {
         $hook_args['cart'] = $context->cart;
     }
     $retro_hook_name = Hook::getRetroHookName($hook_name);
     // Look on modules list
     $altern = 0;
     $output = '';
     if ($disable_non_native_modules && !isset(Hook::$native_module)) {
         Hook::$native_module = Module::getNativeModuleList();
     }
     $callableHooks = array('displayLeftColumn', 'displayRightColumn', 'displayFooter', 'displayTop', 'displayHome', 'displayNavigationBar');
     $isDesignerHook = isset($hook_args) && isset($hook_args['designer_hook']);
     // Billion Themler layoutPosition only
     $source_hook_name = $hook_name;
     if (isset($hook_args) && isset($hook_args['blockId'])) {
         // both Prestashop hooks and Designer layoutPosition
         $blockId = $hook_args['blockId'];
         $context->smarty->assign('blockId', $blockId);
         file_put_contents(getThemeDir() . '/includes/' . $hook_name . '.tpl', "{assign var=blockId value={$blockId} scope='parent'}");
         // for blocklayered-ajax
     }
     $count = getModulesCount($hook_name, $module_list);
     foreach ($module_list as $index => $array) {
         // Check errors
         if ($id_module && $id_module != $array['id_module']) {
             continue;
         }
         if ((bool) $disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($array['module'], self::$native_module)) {
             continue;
         }
         if (!($moduleInstance = Module::getInstanceByName($array['module']))) {
             continue;
         }
         // Check permissions
         if ($check_exceptions) {
             $exceptions = $moduleInstance->getExceptions($array['id_hook']);
             $controller = Dispatcher::getInstance()->getController();
             if (in_array($controller, $exceptions)) {
                 continue;
             }
             //retro compat of controller names
             $matching_name = array('authentication' => 'auth', 'compare' => 'products-comparison');
             if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) {
                 continue;
             }
             if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) {
                 continue;
             }
         }
         $hook_callable = false;
         $hook_retro_callable = false;
         // Check whether Billion Themler hook is
         if ($isDesignerHook) {
             foreach ($callableHooks as $name) {
                 $hook_name = $name;
                 $retro_hook_name = Hook::getRetroHookName($hook_name);
                 $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
                 $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
                 // modules in layoutPosition Billion Themler hook can be called from $callableHooks (displayLeftColumn etc.)
                 // so we save callable hook name as $hook_name variable and write its output to layoutPosition hook
                 if ($hook_callable || $hook_retro_callable) {
                     break;
                 }
                 // goes to Module::preCall line
             }
         } else {
             // Check which / if method is callable as usual
             $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
             $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
         }
         if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) {
             $hook_args['altern'] = ++$altern;
             // Call hook method
             if ($hook_callable) {
                 $display = $moduleInstance->{'hook' . $hook_name}($hook_args);
             } else {
                 if ($hook_retro_callable) {
                     $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args);
                 }
             }
             // Billion Themler edit - $array['live_edit'] defines if module can be moved
             // displayTop and displayFooter hooks can be moved too in Billion Themler but it has live_edit = 0 in DB.hook table
             if (!$array_return && Tools::getValue('theme_name') && ($array['live_edit'] || $hook_name == 'displayTop' || $hook_name == 'displayFooter' || $hook_name == 'displayNavigationBar')) {
                 $display = wrapThemlerEdit($display, $moduleInstance, $array['id_hook']);
             }
             $display = addBootstrapColumn($display, $moduleInstance, $hook_name, $count, $index);
             // Live edit
             if (!$array_return && $array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions' . (int) Tab::getIdFromClassName('AdminModulesPositions') . (int) Tools::getValue('id_employee'))) {
                 // We should used in Live Edit mode native PrestaShop hooks only not Billion Themler ones
                 // That's why we remember $source_hook_name and check it
                 if ($isDesignerHook && !in_array($source_hook_name, $callableHooks)) {
                     $output .= $display;
                 } else {
                     $live_edit = true;
                     $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']);
                 }
             } else {
                 if ($array_return) {
                     $output[$moduleInstance->name] = $display;
                 } else {
                     $output .= $display;
                 }
             }
         }
     }
     if ($array_return) {
         return $output;
     } else {
         return ($live_edit ? '<script type="text/javascript">hooks_list.push(\'' . $hook_name . '\'); </script>
             <div id="' . $hook_name . '" class="dndHook" style="min-height:50px">' : '') . $output . ($live_edit ? '</div>' : '');
         // Return html string
     }
 }
Example #9
0
 public function _getPrestoChangeoShippingModulesForOrder($carrier)
 {
     $PrestoChangeoShippingModules = array();
     /** LIST OF SHIPPING MODULE WITH LABEL PRINTING */
     $PCShippingModulesWithLabelPrinting = array('fedex' => 'fedex', 'dhl' => 'dhl', 'ups' => 'ups', 'usps' => 'usps', 'canadapost' => 'canadapost');
     /** GET ALL THE ENABLED MODULES IN adminOrder HOOK */
     if ($this->getPSV() == 1.6) {
         $modules = Hook::getHookModuleExecList('adminOrder');
     } elseif ($this->getPSV() == 1.5) {
         $modules = Hook::getHookModuleExecList('displayAdminOrder');
     } else {
         $modules = array();
         foreach ($PCShippingModulesWithLabelPrinting as $module) {
             $module = Module::getInstanceByName($module);
             if (isset($module->active) && $module->active) {
                 $modules[]['module'] = $module->name;
             }
         }
     }
     if (is_array($modules) && count($modules)) {
         foreach ($modules as $module) {
             /** VERIFY IF MODULE IS A SHIPPING MODULE WITH LABEL PRINTING */
             if (in_array($module['module'], $PCShippingModulesWithLabelPrinting)) {
                 if ($carrier->external_module_name == $module['module']) {
                     $PrestoChangeoShippingModules[] = $module['module'];
                 } elseif (Configuration::get(strtoupper($module['module']) . '_ENABLE_LABELS') == 'all') {
                     $PrestoChangeoShippingModules[] = $module['module'];
                 }
             }
         }
     }
     return $PrestoChangeoShippingModules;
 }
Example #10
0
    /**
     * Execute modules for specified hook
     *
     * @param string $hook_name Hook Name
     * @param array $hook_args Parameters for the functions
     * @param int $id_module Execute hook for this module only
     * @return string modules output
     */
    public static function exec($hook_name, $hook_args = array(), $id_module = null)
    {
        // Check arguments validity
        if ($id_module && !is_numeric($id_module) || !Validate::isHookName($hook_name)) {
            throw new PrestaShopException('Invalid id_module or hook_name');
        }
        // If no modules associated to hook_name or recompatible hook name, we stop the function
        if (!($module_list = Hook::getHookModuleExecList($hook_name))) {
            return '';
        }
        // Check if hook exists
        if (!($id_hook = Hook::getIdByName($hook_name))) {
            return false;
        }
        // Store list of executed hooks on this page
        Hook::$executed_hooks[$id_hook] = $hook_name;
        $live_edit = false;
        $context = Context::getContext();
        if (!isset($hook_args['cookie']) || !$hook_args['cookie']) {
            $hook_args['cookie'] = $context->cookie;
        }
        if (!isset($hook_args['cart']) || !$hook_args['cart']) {
            $hook_args['cart'] = $context->cart;
        }
        $retro_hook_name = Hook::getRetroHookName($hook_name);
        // Look on modules list
        $altern = 0;
        $output = '';
        foreach ($module_list as $array) {
            // Check errors
            if ($id_module && $id_module != $array['id_module']) {
                continue;
            }
            if (!($moduleInstance = Module::getInstanceByName($array['module']))) {
                continue;
            }
            // Check permissions
            $exceptions = $moduleInstance->getExceptions($array['id_hook']);
            if (in_array(Dispatcher::getInstance()->getController(), $exceptions)) {
                continue;
            }
            if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) {
                continue;
            }
            // Check which / if method is callable
            $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
            $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
            if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) {
                $hook_args['altern'] = ++$altern;
                // Call hook method
                if ($hook_callable) {
                    $display = $moduleInstance->{'hook' . $hook_name}($hook_args);
                } else {
                    if ($hook_retro_callable) {
                        $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args);
                    }
                }
                // Live edit
                if ($array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions' . (int) Tab::getIdFromClassName('AdminModulesPositions') . (int) Tools::getValue('id_employee'))) {
                    $live_edit = true;
                    $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']);
                } else {
                    $output .= $display;
                }
            }
        }
        // Return html string
        return ($live_edit ? '<script type="text/javascript">hooks_list.push(\'' . $hook_name . '\'); </script>
				<div id="' . $hook_name . '" class="dndHook" style="min-height:50px">' : '') . $output . ($live_edit ? '</div>' : '');
    }
Example #11
0
 public static function execModuleHook($hook_name, $hook_args = array(), $module_name, $use_push = false, $id_shop = null)
 {
     static $disable_non_native_modules = null;
     if ($disable_non_native_modules === null) {
         $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
     }
     // Check arguments validity
     if (!Validate::isModuleName($module_name) || !Validate::isHookName($hook_name)) {
         throw new PrestaShopException('Invalid module name or hook name');
     }
     // If no modules associated to hook_name or recompatible hook name, we stop the function
     if (!Hook::getHookModuleExecList($hook_name)) {
         return '';
     }
     // Check if hook exists
     if (!($id_hook = Hook::getIdByName($hook_name))) {
         return false;
     }
     // Store list of executed hooks on this page
     Hook::$executed_hooks[$id_hook] = $hook_name;
     //		$live_edit = false;
     $context = Context::getContext();
     if (!isset($hook_args['cookie']) || !$hook_args['cookie']) {
         $hook_args['cookie'] = $context->cookie;
     }
     if (!isset($hook_args['cart']) || !$hook_args['cart']) {
         $hook_args['cart'] = $context->cart;
     }
     $retro_hook_name = Hook::getRetroHookName($hook_name);
     // Look on modules list
     $altern = 0;
     $output = '';
     if ($disable_non_native_modules && !isset(Hook::$native_module)) {
         Hook::$native_module = Module::getNativeModuleList();
     }
     $different_shop = false;
     if ($id_shop !== null && Validate::isUnsignedId($id_shop) && $id_shop != $context->shop->getContextShopID()) {
         //			$old_context_shop_id = $context->shop->getContextShopID();
         $old_context = $context->shop->getContext();
         $old_shop = clone $context->shop;
         $shop = new Shop((int) $id_shop);
         if (Validate::isLoadedObject($shop)) {
             $context->shop = $shop;
             $context->shop->setContext(Shop::CONTEXT_SHOP, $shop->id);
             $different_shop = true;
         }
     }
     // Check errors
     if ((bool) $disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($module_name, self::$native_module)) {
         return;
     }
     if (!($moduleInstance = Module::getInstanceByName($module_name))) {
         return;
     }
     if ($use_push && !$moduleInstance->allow_push) {
         continue;
     }
     // Check which / if method is callable
     $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
     $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
     if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) {
         $hook_args['altern'] = ++$altern;
         if ($use_push && isset($moduleInstance->push_filename) && file_exists($moduleInstance->push_filename)) {
             Tools::waitUntilFileIsModified($moduleInstance->push_filename, $moduleInstance->push_time_limit);
         }
         // Call hook method
         if ($hook_callable) {
             $display = $moduleInstance->{'hook' . $hook_name}($hook_args);
         } elseif ($hook_retro_callable) {
             $display = $moduleInstance->{'hook' . $retro_hook_name}($hook_args);
         }
         $output .= $display;
     }
     if ($different_shop) {
         $context->shop = $old_shop;
         $context->shop->setContext($old_context, $shop->id);
     }
     return $output;
     // Return html string
 }
Example #12
0
function smartyHook($params, &$smarty)
{
    $id_module = null;
    $hook_params = $params;
    $hook_params['smarty'] = $smarty;
    if (!empty($params['mod'])) {
        $module = Module::getInstanceByName($params['mod']);
        unset($hook_params['mod']);
        if ($module && $module->id) {
            $id_module = $module->id;
        } else {
            unset($hook_params['h']);
            return '';
        }
    }
    if (!empty($params['excl'])) {
        $result = '';
        $modules = Hook::getHookModuleExecList($hook_params['h']);
        $moduleexcl = explode(',', $params['excl']);
        foreach ($modules as $module) {
            if (!in_array($module['module'], $moduleexcl)) {
                $result .= Hook::exec($params['h'], $hook_params, $module['id_module']);
            }
        }
        unset($hook_params['h']);
        unset($hook_params['excl']);
        return $result;
    }
    unset($hook_params['h']);
    return Hook::exec($params['h'], $hook_params, $id_module);
}
    /**
     * @param string $content
     */
    public static function parseHookOutput($themeDir, $hook_name, $hook_list)
    {
        $context = Context::getContext();
        $output = '';
        if (!Validate::isHookName($hook_name) || !($module_list = Hook::getHookModuleExecList($hook_name))) {
            return null;
        }
        $id_hook = Hook::getIdByName($hook_name);
        $dataRequirePosAttr = implode(';', $hook_list);
        foreach ($module_list as $array) {
            if (!($moduleInstance = Module::getInstanceByName($array['module']))) {
                continue;
            }
            $exceptions = $moduleInstance->getExceptions($array['id_hook']);
            if (in_array(Dispatcher::getInstance()->getController(), $exceptions)) {
                continue;
            }
            if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) {
                continue;
            }
            $name = $moduleInstance->name;
            if (Module::preCall($name)) {
                $blockDataAttr = 'hook_' . $id_hook . '_module_' . $moduleInstance->id . '_moduleName_' . $name;
                if ($name === 'blocklayered') {
                    $output .= <<<EOT

{if \$page_name eq 'category'}
{literal}
\t<script type="text/javascript">
\t\t//<![CDATA[
\t\t\$(document).ready(function()
\t\t{
\t\t\t\$('#selectPrductSort').unbind('change').bind('change', function()
\t\t\t{
\t\t\t\treloadContent();
\t\t\t})
\t\t});
\t\t//]]>
\t</script>
{/literal}
{/if}
EOT;
                } elseif (file_exists($themeDir . "/modules/{$name}/{$name}.tpl")) {
                    $output .= <<<EOT

{assign var=blockDataAttr value='{$blockDataAttr}'}
{assign var=blockDataRequirePosAttr value='{$dataRequirePosAttr}'}

{include file="{\$tpl_dir}./modules/{$name}/{$name}.tpl" blockId=\$blockId blockDataAttr=\$blockDataAttr blockDataRequirePosAttr=\$blockDataRequirePosAttr}
EOT;
                } elseif (file_exists(_PS_MODULE_DIR_ . "{$name}/{$name}.tpl")) {
                    $output .= <<<EOT

{include file="{\$modules_dir}./{$name}/{$name}.tpl"}
EOT;
                }
            }
        }
        return $output;
    }
    public function __construct()
    {
        $this->table = 'product';
        $this->className = 'Product';
        $this->lang = true;
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
        if (!Tools::getValue('id_product')) {
            $this->multishop_context_group = false;
        }
        parent::__construct();
        $this->imageType = 'jpg';
        $this->_defaultOrderBy = 'position';
        $this->max_file_size = (int) (Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
        $this->max_image_size = (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
        $this->fields_list = array();
        $this->fields_list['id_product'] = array('title' => $this->l('ID'), 'align' => 'center', 'width' => 20);
        $this->fields_list['image'] = array('title' => $this->l('Photo'), 'align' => 'center', 'image' => 'p', 'width' => 70, 'orderby' => false, 'filter' => false, 'search' => false);
        $this->fields_list['name'] = array('title' => $this->l('Name'), 'filter_key' => 'b!name');
        $this->fields_list['reference'] = array('title' => $this->l('Reference'), 'align' => 'left', 'width' => 80);
        if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
            $this->fields_list['shopname'] = array('title' => $this->l('Default Shop'), 'width' => 230, 'filter_key' => 'shop!name');
        } else {
            $this->fields_list['name_category'] = array('title' => $this->l('Category'), 'width' => 230, 'filter_key' => 'cl!name');
        }
        $this->fields_list['price'] = array('title' => $this->l('Base price'), 'width' => 90, 'type' => 'price', 'align' => 'right', 'filter_key' => 'a!price');
        $this->fields_list['price_final'] = array('title' => $this->l('Final price'), 'width' => 90, 'type' => 'price', 'align' => 'right', 'havingFilter' => true, 'orderby' => false);
        $this->fields_list['sav_quantity'] = array('title' => $this->l('Quantity'), 'width' => 90, 'align' => 'right', 'filter_key' => 'sav!quantity', 'orderby' => true, 'hint' => $this->l('This is the quantity available in the current shop/group'));
        $this->fields_list['active'] = array('title' => $this->l('Displayed'), 'width' => 70, 'active' => 'status', 'filter_key' => 'sa!active', 'align' => 'center', 'type' => 'bool', 'orderby' => false);
        if ((int) Tools::getValue('id_category')) {
            $this->fields_list['position'] = array('title' => $this->l('Position'), 'width' => 70, 'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position');
        }
        // @since 1.5 : translations for tabs
        $this->available_tabs_lang = array('Informations' => $this->l('Information'), 'Pack' => $this->l('Pack'), 'VirtualProduct' => $this->l('Virtual Product'), 'Prices' => $this->l('Prices'), 'Seo' => $this->l('SEO'), 'Images' => $this->l('Images'), 'Associations' => $this->l('Associations'), 'Shipping' => $this->l('Shipping'), 'Combinations' => $this->l('Combinations'), 'Features' => $this->l('Features'), 'Customization' => $this->l('Customization'), 'Attachments' => $this->l('Attachments'), 'Quantities' => $this->l('Quantities'), 'Suppliers' => $this->l('Suppliers'), 'Warehouses' => $this->l('Warehouses'));
        $this->available_tabs = array('Quantities' => 6, 'Warehouses' => 14);
        if ($this->context->shop->getContext() != Shop::CONTEXT_GROUP) {
            $this->available_tabs = array_merge($this->available_tabs, array('Informations' => 0, 'Pack' => 7, 'VirtualProduct' => 8, 'Prices' => 1, 'Seo' => 2, 'Associations' => 3, 'Images' => 9, 'Shipping' => 4, 'Combinations' => 5, 'Features' => 10, 'Customization' => 11, 'Attachments' => 12, 'Suppliers' => 13));
        }
        // Sort the tabs that need to be preloaded by their priority number
        asort($this->available_tabs, SORT_NUMERIC);
        /* Adding tab if modules are hooked */
        $modules_list = Hook::getHookModuleExecList('displayAdminProductsExtra');
        if (is_array($modules_list) && count($modules_list) > 0) {
            foreach ($modules_list as $m) {
                $this->available_tabs['Module' . ucfirst($m['module'])] = 23;
                $this->available_tabs_lang['Module' . ucfirst($m['module'])] = Module::getModuleName($m['module']);
            }
        }
        /* Join categories table */
        if ($id_category = (int) Tools::getValue('productFilter_cl!name')) {
            $this->_category = new Category((int) $id_category);
            $_POST['productFilter_cl!name'] = $this->_category->name[$this->context->language->id];
        } elseif ($id_category = Tools::getvalue('id_category')) {
            $this->_category = new Category((int) $id_category);
        } else {
            $this->_category = new Category();
        }
        $join_category = false;
        if (Validate::isLoadedObject($this->_category) && empty($this->_filter)) {
            $join_category = true;
        }
        if (Shop::isFeatureActive()) {
            $alias = 'sa';
            if (Shop::getContext() == Shop::CONTEXT_SHOP) {
                $this->_join .= ' JOIN `' . _DB_PREFIX_ . 'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = ' . (int) $this->context->shop->id . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = ' . (int) $this->context->shop->id . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'shop` shop ON (shop.id_shop = ' . (int) $this->context->shop->id . ') ';
            } else {
                $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = a.id_shop_default)
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default)
				LEFT JOIN `' . _DB_PREFIX_ . 'shop` shop ON (shop.id_shop = a.id_shop_default) ';
            }
            $this->_select .= 'shop.name as shopname, ';
        } else {
            $alias = 'a';
            $this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = 1)';
        }
        $this->_join .= '
		LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1)
		' . ($join_category ? 'INNER JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = ' . (int) $this->_category->id . ')' : '') . '
		LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (' . $alias . '.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = ' . (int) $this->context->country->id . ' AND tr.`id_state` = 0)
		LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)
		LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
		' . StockAvailable::addSqlShopRestriction(null, null, 'sav') . ') ';
        $this->_select .= 'cl.name `name_category` ' . ($join_category ? ', cp.`position`' : '') . ', i.`id_image`, ' . $alias . '.`price`, (' . $alias . '.`price` * ((100 + (t.`rate`))/100)) AS price_final, sav.`quantity` as sav_quantity, ' . $alias . '.`active`';
    }
Example #15
0
 /**
  * Execute modules for specified hook
  *
  * @param string $hook_name Hook Name
  * @param array $hook_args Parameters for the functions
  * @param int $id_module Execute hook for this module only
  * @param bool $array_return If specified, module output will be set by name in an array
  * @param bool $check_exceptions Check permission exceptions
  * @param bool $use_push Force change to be refreshed on Dashboard widgets
  * @param int $id_shop If specified, hook will be execute the shop with this ID
  *
  * @throws PrestaShopException
  *
  * @return string/array modules output
  */
 public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true, $use_push = false, $id_shop = null)
 {
     if (defined('PS_INSTALLATION_IN_PROGRESS')) {
         return;
     }
     static $disable_non_native_modules = null;
     if ($disable_non_native_modules === null) {
         $disable_non_native_modules = (bool) Configuration::get('PS_DISABLE_NON_NATIVE_MODULE');
     }
     // Check arguments validity
     if ($id_module && !is_numeric($id_module) || !Validate::isHookName($hook_name)) {
         throw new PrestaShopException('Invalid id_module or hook_name');
     }
     // If no modules associated to hook_name or recompatible hook name, we stop the function
     if (!($module_list = Hook::getHookModuleExecList($hook_name))) {
         return '';
     }
     // Check if hook exists
     if (!($id_hook = Hook::getIdByName($hook_name))) {
         return false;
     }
     if (array_key_exists($hook_name, self::$deprecated_hooks)) {
         $deprecVersion = isset(self::$deprecated_hooks[$hook_name]['from']) ? self::$deprecated_hooks[$hook_name]['from'] : _PS_VERSION_;
         Tools::displayAsDeprecated('The hook ' . $hook_name . ' is deprecated in PrestaShop v.' . $deprecVersion);
     }
     // Store list of executed hooks on this page
     Hook::$executed_hooks[$id_hook] = $hook_name;
     $context = Context::getContext();
     if (!isset($hook_args['cookie']) || !$hook_args['cookie']) {
         $hook_args['cookie'] = $context->cookie;
     }
     if (!isset($hook_args['cart']) || !$hook_args['cart']) {
         $hook_args['cart'] = $context->cart;
     }
     $retro_hook_name = Hook::getRetroHookName($hook_name);
     // Look on modules list
     $altern = 0;
     if ($array_return) {
         $output = array();
     } else {
         $output = '';
     }
     if ($disable_non_native_modules && !isset(Hook::$native_module)) {
         Hook::$native_module = Module::getNativeModuleList();
     }
     $different_shop = false;
     if ($id_shop !== null && Validate::isUnsignedId($id_shop) && $id_shop != $context->shop->getContextShopID()) {
         $old_context = $context->shop->getContext();
         $old_shop = clone $context->shop;
         $shop = new Shop((int) $id_shop);
         if (Validate::isLoadedObject($shop)) {
             $context->shop = $shop;
             $context->shop->setContext(Shop::CONTEXT_SHOP, $shop->id);
             $different_shop = true;
         }
     }
     foreach ($module_list as $array) {
         // Check errors
         if ($id_module && $id_module != $array['id_module']) {
             continue;
         }
         if ((bool) $disable_non_native_modules && Hook::$native_module && count(Hook::$native_module) && !in_array($array['module'], Hook::$native_module)) {
             continue;
         }
         // Check permissions
         if ($check_exceptions) {
             $exceptions = Module::getExceptionsStatic($array['id_module'], $array['id_hook']);
             $controller = Dispatcher::getInstance()->getController();
             $controller_obj = Context::getContext()->controller;
             //check if current controller is a module controller
             if (isset($controller_obj->module) && Validate::isLoadedObject($controller_obj->module)) {
                 $controller = 'module-' . $controller_obj->module->name . '-' . $controller;
             }
             if (in_array($controller, $exceptions)) {
                 continue;
             }
             //Backward compatibility of controller names
             $matching_name = array('authentication' => 'auth');
             if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) {
                 continue;
             }
             if (Validate::isLoadedObject($context->employee) && !Module::getPermissionStatic($array['id_module'], 'view', $context->employee)) {
                 continue;
             }
         }
         if (!($moduleInstance = Module::getInstanceByName($array['module']))) {
             continue;
         }
         if ($use_push && !$moduleInstance->allow_push) {
             continue;
         }
         // Check which / if method is callable
         $hook_callable = is_callable(array($moduleInstance, 'hook' . $hook_name));
         $hook_retro_callable = is_callable(array($moduleInstance, 'hook' . $retro_hook_name));
         if ($hook_callable || $hook_retro_callable) {
             $hook_args['altern'] = ++$altern;
             if ($use_push && isset($moduleInstance->push_filename) && file_exists($moduleInstance->push_filename)) {
                 Tools::waitUntilFileIsModified($moduleInstance->push_filename, $moduleInstance->push_time_limit);
             }
             // Call hook method
             if ($hook_callable) {
                 $display = Hook::coreCallHook($moduleInstance, 'hook' . $hook_name, $hook_args);
             } elseif ($hook_retro_callable) {
                 $display = Hook::coreCallHook($moduleInstance, 'hook' . $retro_hook_name, $hook_args);
             }
             if ($array_return) {
                 $output[$moduleInstance->name] = $display;
             } else {
                 $output .= $display;
             }
         } elseif (Hook::isDisplayHookName($hook_name)) {
             if ($moduleInstance instanceof WidgetInterface) {
                 $display = Hook::coreRenderWidget($moduleInstance, $hook_name, $hook_args);
                 if ($array_return) {
                     $output[$moduleInstance->name] = $display;
                 } else {
                     $output .= $display;
                 }
             }
         }
     }
     if ($different_shop) {
         $context->shop = $old_shop;
         $context->shop->setContext($old_context, $shop->id);
     }
     return $output;
 }