public function initFormByStatus() { $this->fields_form = array('legend' => array('title' => $this->l('By order status'), 'image' => '../img/admin/pdf.gif'), 'input' => array(array('type' => 'checkboxStatuses', 'label' => $this->l('Statuses:'), 'name' => 'id_order_state', 'values' => array('query' => OrderState::getOrderStates($this->context->language->id), 'id' => 'id_order_state', 'name' => 'name'), 'desc' => $this->l('You can also export orders which have not been charged yet.') . ' (<img src="../img/admin/charged_ko.gif" alt="" />).')), 'submit' => array('title' => $this->l('Generate PDF file by status.'), 'class' => 'button', 'id' => 'submitPrint2')); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT COUNT(o.id_order) as nbOrders, ( SELECT oh.id_order_state FROM ' . _DB_PREFIX_ . 'order_history oh WHERE oh.id_order = oi.id_order ORDER BY oh.date_add DESC, oh.id_order_history DESC LIMIT 1 ) id_order_state FROM ' . _DB_PREFIX_ . 'order_invoice oi LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (oi.id_order = o.id_order) WHERE o.id_shop IN(' . implode(', ', Shop::getContextListShopID()) . ') GROUP BY id_order_state '); $status_stats = array(); foreach ($result as $row) { $status_stats[$row['id_order_state']] = $row['nbOrders']; } $this->tpl_form_vars = array('statusStats' => $status_stats, 'style' => ''); $this->table = 'invoice_status'; $this->show_toolbar = false; return parent::renderForm(); }
public static function getBlockContent($params, &$smarty) { //use in template as {getBelvgBlockContent id="block_identifier"} if (!Module::isEnabled('belvg_staticblocks')) { return FALSE; } if (isset($params['id'])) { $block_identifier = $params['id']; $sql = ' SELECT `id_belvg_staticblocks` FROM `' . _DB_PREFIX_ . 'belvg_staticblocks` WHERE `block_identifier` = "' . pSQL($block_identifier) . '" AND `status` = "1"'; if (Shop::isFeatureActive()) { $sql .= ' AND `id_belvg_staticblocks` IN ( SELECT sa.`id_belvg_staticblocks` FROM `' . _DB_PREFIX_ . 'belvg_staticblocks_shop` sa WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ') )'; } $block_id = (int) Db::getInstance()->getValue($sql); if ($block_id) { $id_lang = Context::getContext()->cookie->id_lang; $block = new self($block_id); if (isset($block->content[$id_lang])) { return $block->content[$id_lang]; } } } }
public function __construct() { $this->table = 'smart_blog_comment'; $this->className = 'Blogcomment'; $this->module = 'smartblog'; $this->context = Context::getContext(); $this->bootstrap = true; if (Shop::isFeatureActive()) { Shop::addTableAssociation($this->table, array('type' => 'shop')); } parent::__construct(); $this->fields_list = array('id_smart_blog_comment' => array('title' => $this->l('Id'), 'width' => 50, 'type' => 'text'), 'email' => array('title' => $this->l('Email'), 'width' => 50, 'type' => 'text', 'lang' => true), 'meta_title' => array('title' => $this->l('Post Title'), 'filter_key' => 'smp!meta_title', 'align' => 'center'), 'name' => array('title' => $this->l('Name'), 'width' => 150, 'type' => 'text'), 'content' => array('title' => $this->l('Comment'), 'width' => 200, 'type' => 'text', 'callback' => 'getCommentClean'), 'created' => array('title' => $this->l('Date'), 'width' => 60, 'type' => 'text', 'lang' => true), 'active' => array('title' => $this->l('Status'), 'width' => '70', 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?'))); $this->_join = ' LEFT JOIN ' . _DB_PREFIX_ . 'smart_blog_comment_shop sbs ON a.id_smart_blog_comment=sbs.id_smart_blog_comment && sbs.id_shop IN(' . implode(',', Shop::getContextListShopID()) . ')'; $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'smart_blog_post_lang smp ON a.id_post=smp.id_smart_blog_post and smp.id_lang = ' . (int) Context::getContext()->language->id; $this->_select = 'sbs.id_shop'; $this->_defaultOrderBy = 'a.id_smart_blog_comment'; $this->_defaultOrderWay = 'DESC'; $this->_select = 'smp.meta_title'; //$this->_defaultOrderBy = 'a.id_smart_blog_comment'; if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) { $this->_group = 'GROUP BY a.id_smart_blog_comment'; } parent::__construct(); }
public function __construct() { $this->table = 'smart_blog_post'; $this->className = 'SmartBlogPost'; $this->lang = true; $this->image_dir = '../modules/smartblog/images'; $this->context = Context::getContext(); $this->_defaultOrderBy = 'created'; $this->_defaultorderWay = 'DESC'; $this->bootstrap = true; if (Shop::isFeatureActive()) { Shop::addTableAssociation($this->table, array('type' => 'shop')); } parent::__construct(); $this->fields_list = array('id_smart_blog_post' => array('title' => $this->l('Id'), 'width' => 50, 'type' => 'text', 'orderby' => true, 'filter' => true, 'search' => true), 'viewed' => array('title' => $this->l('View'), 'width' => 50, 'type' => 'text', 'lang' => true, 'orderby' => true, 'filter' => false, 'search' => false), 'image' => array('title' => $this->l('Image'), 'image' => $this->image_dir, 'orderby' => false, 'search' => false, 'width' => 200, 'align' => 'center', 'orderby' => false, 'filter' => false, 'search' => false), 'meta_title' => array('title' => $this->l('Title'), 'width' => 440, 'type' => 'text', 'lang' => true, 'orderby' => true, 'filter' => true, 'search' => true), 'created' => array('title' => $this->l('Posted Date'), 'width' => 100, 'type' => 'date', 'lang' => true, 'orderby' => true, 'filter' => true, 'search' => true), 'active' => array('title' => $this->l('Status'), 'width' => '70', 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => true, 'filter' => true, 'search' => true)); $this->_join = 'LEFT JOIN ' . _DB_PREFIX_ . 'smart_blog_post_shop sbs ON a.id_smart_blog_post=sbs.id_smart_blog_post && sbs.id_shop IN(' . implode(',', Shop::getContextListShopID()) . ')'; $this->_select = 'sbs.id_shop'; $this->_defaultOrderBy = 'a.id_smart_blog_post'; $this->_defaultOrderWay = 'DESC'; // if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) // { // $this->_group = 'GROUP BY a.smart_blog_post'; // } parent::__construct(); }
/** * Return available contacts * * @param integer $id_lang Language ID * @param Context * @return array Contacts */ public static function getContacts($id_lang) { $shop_ids = Shop::getContextListShopID(); $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'contact` c ' . Shop::addSqlAssociation('contact', 'c', false) . ' LEFT JOIN `' . _DB_PREFIX_ . 'contact_lang` cl ON (c.`id_contact` = cl.`id_contact`) WHERE cl.`id_lang` = ' . (int) $id_lang . ' AND contact_shop.`id_shop` IN (' . implode(', ', array_map('intval', $shop_ids)) . ') ORDER BY `name` ASC'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); }
/** * Return available categories contacts * @return array Contacts */ public static function getCategoriesContacts() { $shop_ids = Shop::getContextListShopID(); return Db::getInstance()->executeS(' SELECT cl.* FROM ' . _DB_PREFIX_ . 'contact ct ' . Shop::addSqlAssociation('contact', 'ct', false) . ' LEFT JOIN ' . _DB_PREFIX_ . 'contact_lang cl ON (cl.id_contact = ct.id_contact AND cl.id_lang = ' . (int) Context::getContext()->language->id . ') WHERE ct.customer_service = 1 AND contact_shop.`id_shop` IN (' . implode(', ', array_map('intval', $shop_ids)) . ') GROUP BY ct.`id_contact` '); }
/** * getLastElementsIdsByType return all the element ids to show (order, customer registration, and customer message) * Get all the element ids * * @param string $type contains the field name of the Employee table * @param integer $id_last_element contains the id of the last seen element * @return array containing the notifications */ public static function getLastElementsIdsByType($type, $id_last_element) { switch ($type) { case 'order': $sql = ' SELECT SQL_CALC_FOUND_ROWS o.`id_order`, o.`id_customer`, o.`total_paid`, o.`id_currency`, c.`firstname`, c.`lastname` FROM `' . _DB_PREFIX_ . 'orders` as o LEFT JOIN `' . _DB_PREFIX_ . 'customer` as c ON (c.`id_customer` = o.`id_customer`) WHERE `id_order` > ' . (int) $id_last_element . Shop::addSqlRestriction(false, 'o') . ' ORDER BY `id_order` DESC LIMIT 5'; break; case 'customer_message': $sql = ' SELECT SQL_CALC_FOUND_ROWS c.`id_customer_message`, ct.`id_customer`, ct.`id_customer_thread`, ct.`email` FROM `' . _DB_PREFIX_ . 'customer_message` as c LEFT JOIN `' . _DB_PREFIX_ . 'customer_thread` as ct ON (c.`id_customer_thread` = ct.`id_customer_thread`) WHERE c.`id_customer_message` > ' . (int) $id_last_element . ' AND c.`id_employee` = 0 AND ct.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ') ORDER BY c.`id_customer_message` DESC LIMIT 5'; break; default: $sql = ' SELECT SQL_CALC_FOUND_ROWS t.`id_' . bqSQL($type) . '`, t.* FROM `' . _DB_PREFIX_ . bqSQL($type) . '` t WHERE t.`deleted` = 0 AND t.`id_' . bqSQL($type) . '` > ' . (int) $id_last_element . Shop::addSqlRestriction(false, 't') . ' ORDER BY t.`id_' . bqSQL($type) . '` DESC LIMIT 5'; break; } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, true, false); $total = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()', false); $json = array('total' => $total, 'results' => array()); foreach ($result as $value) { $customer_name = ''; if (isset($value['firstname']) && isset($value['lastname'])) { $customer_name = Tools::safeOutput($value['firstname'] . ' ' . $value['lastname']); } else { if (isset($value['email'])) { $customer_name = Tools::safeOutput($value['email']); } } $json['results'][] = array('id_order' => !empty($value['id_order']) ? (int) $value['id_order'] : 0, 'id_customer' => !empty($value['id_customer']) ? (int) $value['id_customer'] : 0, 'id_customer_message' => !empty($value['id_customer_message']) ? (int) $value['id_customer_message'] : 0, 'id_customer_thread' => !empty($value['id_customer_thread']) ? (int) $value['id_customer_thread'] : 0, 'total_paid' => !empty($value['total_paid']) ? Tools::displayPrice((double) $value['total_paid'], (int) $value['id_currency'], false) : 0, 'customer_name' => $customer_name); } return $json; }
/** * Inserts new menu item to the database * * @param bool $autoDate * @param bool $nullValues * * @return bool * @throws PrestaShopException */ public function add($autoDate = true, $nullValues = false) { $status = parent::add($autoDate, $nullValues); Hook::exec('actionCTTopMenuCompositionChanged'); if ($status) { $id_shop_list = Shop::getContextListShopID(); if (!empty($this->id_shop_list)) { $id_shop_list = $this->id_shop_list; } // @TODO Fix initial value foreach ($id_shop_list as $id_shop) { Db::getInstance()->update('ct_top_menu_item_shop', array('position' => self::getMaxPosition($id_shop) + 1), 'id_ct_top_menu_item = ' . (int) $this->id . ' AND id_shop = ' . (int) $id_shop); } } return $status; }
public function renderList() { // Display list Referrers: $this->addRowAction('view'); $this->addRowAction('edit'); $this->addRowAction('delete'); $this->_select = 'SUM(sa.cache_visitors) AS cache_visitors, SUM(sa.cache_visits) AS cache_visits, SUM(sa.cache_pages) AS cache_pages, SUM(sa.cache_registrations) AS cache_registrations, SUM(sa.cache_orders) AS cache_orders, SUM(sa.cache_sales) AS cache_sales, IF(sa.cache_orders > 0, ROUND(sa.cache_sales/sa.cache_orders, 2), 0) as cart, (sa.cache_visits*click_fee) as fee0, (sa.cache_orders*base_fee) as fee1, (sa.cache_sales*percent_fee/100) as fee2'; $this->_join = ' LEFT JOIN `' . _DB_PREFIX_ . 'referrer_shop` sa ON (sa.' . $this->identifier . ' = a.' . $this->identifier . ' AND sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . '))'; $this->_group = 'GROUP BY sa.id_referrer'; $this->tpl_list_vars = array('enable_calendar' => $this->enableCalendar(), 'calendar_form' => $this->displayCalendar(), 'settings_form' => $this->displaySettings()); return parent::renderList(); }
function upgrade_module_1_5_0($module) { /* Get existing values as default */ $default_width = (int) Configuration::get('HOMESLIDER_WIDTH'); $default_speed = (int) Configuration::get('HOMESLIDER_SPEED'); $default_pause = (int) Configuration::get('HOMESLIDER_PAUSE'); $default_loop = (int) Configuration::get('HOMESLIDER_LOOP'); $res = true; // Clean existing Configuration::deleteByName('HOMESLIDER_WIDTH'); Configuration::deleteByName('HOMESLIDER_SPEED'); Configuration::deleteByName('HOMESLIDER_PAUSE'); Configuration::deleteByName('HOMESLIDER_LOOP'); $shops = Shop::getContextListShopID(); $shop_groups_list = array(); /* Setup each shop */ foreach ($shops as $shop_id) { $shop_group_id = (int) Shop::getGroupFromShop($shop_id, true); if (!in_array($shop_group_id, $shop_groups_list)) { $shop_groups_list[] = $shop_group_id; } /* Sets up configuration */ $res = Configuration::updateValue('HOMESLIDER_WIDTH', $default_width, false, $shop_group_id, $shop_id); $res &= Configuration::updateValue('HOMESLIDER_SPEED', $default_speed, false, $shop_group_id, $shop_id); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', $default_pause, false, $shop_group_id, $shop_id); $res &= Configuration::updateValue('HOMESLIDER_LOOP', $default_loop, false, $shop_group_id, $shop_id); } /* Sets up Shop Group configuration */ if (count($shop_groups_list)) { foreach ($shop_groups_list as $shop_group_id) { $res = Configuration::updateValue('HOMESLIDER_WIDTH', $default_width, false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_SPEED', $default_speed, false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', $default_pause, false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_LOOP', $default_loop, false, $shop_group_id); } } /* Sets up Global configuration */ $res = Configuration::updateValue('HOMESLIDER_WIDTH', $default_width); $res &= Configuration::updateValue('HOMESLIDER_SPEED', $default_speed); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', $default_pause); $res &= Configuration::updateValue('HOMESLIDER_LOOP', $default_loop); return $res; }
public function initFormByStatus() { $this->fields_form = array('legend' => array('title' => $this->l('By order status'), 'icon' => 'icon-time'), 'input' => array(array('type' => 'checkboxStatuses', 'label' => $this->l('Statuses'), 'name' => 'id_order_state', 'values' => array('query' => OrderState::getOrderStates($this->context->language->id), 'id' => 'id_order_state', 'name' => 'name'), 'hint' => $this->l('You can also export orders which have not been charged yet.'))), 'submit' => array('title' => $this->l('Generate PDF file by status'), 'id' => 'submitPrint2', 'icon' => 'process-icon-download-alt')); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT COUNT( o.id_order ) AS nbOrders, o.current_state as id_order_state FROM `' . _DB_PREFIX_ . 'order_invoice` oi LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON oi.id_order = o.id_order WHERE o.id_shop IN(' . implode(', ', Shop::getContextListShopID()) . ') GROUP BY o.current_state '); $status_stats = array(); foreach ($result as $row) { $status_stats[$row['id_order_state']] = $row['nbOrders']; } $this->tpl_form_vars = array('statusStats' => $status_stats, 'style' => ''); $this->table = 'invoice_status'; $this->show_toolbar = false; return parent::renderForm(); }
public function __construct() { $this->bootstrap = true; $this->table = 'belvg_staticblocks'; $this->identifier = 'id_belvg_staticblocks'; $this->className = 'BelvgStaticBlocks'; $this->lang = TRUE; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->fields_list = array('id_belvg_staticblocks' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 30), 'title' => array('title' => $this->l('Block Title'), 'width' => 300), 'block_identifier' => array('title' => $this->l('Identifier'), 'width' => 300), 'status' => array('title' => $this->l('Status'), 'width' => 40, 'active' => 'update', 'align' => 'center', 'type' => 'bool', 'orderby' => FALSE), 'date_add' => array('title' => $this->l('Date Created'), 'width' => 150, 'type' => 'date', 'align' => 'right'), 'date_upd' => array('title' => $this->l('Last Modified'), 'width' => 150, 'type' => 'date', 'align' => 'right')); if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) { $this->_where .= ' AND a.' . $this->identifier . ' IN ( SELECT sa.' . $this->identifier . ' FROM `' . _DB_PREFIX_ . $this->table . '_shop` sa WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ') )'; } $this->identifiersDnd = array('id_belvg_staticblocks' => 'id_sslide_to_move'); parent::__construct(); }
public function __construct() { $this->table = 'smart_blog_comment'; $this->className = 'Blogcomment'; $this->module = 'smartblog'; $this->context = Context::getContext(); $this->bootstrap = true; if (Shop::isFeatureActive()) { Shop::addTableAssociation($this->table, array('type' => 'shop')); } parent::__construct(); $this->fields_list = array('id_smart_blog_comment' => array('title' => $this->l('Id'), 'width' => 100, 'type' => 'text'), 'name' => array('title' => $this->l('Name'), 'width' => 150, 'type' => 'text'), 'content' => array('title' => $this->l('Comment'), 'width' => 340, 'type' => 'text'), 'created' => array('title' => $this->l('Date'), 'width' => 60, 'type' => 'text', 'lang' => true), 'active' => array('title' => $this->l('Status'), 'width' => '70', 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)); $this->_join = 'LEFT JOIN ' . _DB_PREFIX_ . 'smart_blog_comment_shop sbs ON a.id_smart_blog_comment=sbs.id_smart_blog_comment && sbs.id_shop IN(' . implode(',', Shop::getContextListShopID()) . ')'; $this->_select = 'sbs.id_shop'; $this->_defaultOrderBy = 'a.id_smart_blog_comment'; $this->_defaultOrderWay = 'DESC'; if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) { $this->_group = 'GROUP BY a.id_smart_blog_comment'; } parent::__construct(); }
public function initContent() { parent::initContent(); $this->ajax = true; $region = Tools::getValue('set_region', -1); if ($region > -1) { $url = $this->getRegionURL($region); if ($url) { $this->context->cookie->__set('yandex_region', $region); } else { $this->context->cookie->__unset('yandex_region'); } die(json_encode($url)); } $sql = 'SELECT su.`id_shop_url` as id, su.`domain`, mu.`city_name`, s.`name` as shop_name FROM `' . _DB_PREFIX_ . 'shop_url` su INNER JOIN `' . _DB_PREFIX_ . 'shop` s ON s.`id_shop`=su.`id_shop` INNER JOIN `' . _DB_PREFIX_ . 'egmultishop_url` mu ON mu.`id_url`=su.`id_shop_url` WHERE su.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ') and su.`main`= 0 and su.`active` = 1 and not mu.`city_name` = \'\' and mu.`active` > 0 order by 3'; if (!($citys = Db::getInstance()->executeS($sql))) { return false; } if (Tools::getValue('json', false) !== false) { die(json_encode($citys)); } $host = "http://" . Tools::getHttpHost(); $current_page = str_replace($host, "", $_SERVER["HTTP_REFERER"]); $question = Tools::getValue('question'); $region = Tools::getValue('region'); $this->context->smarty->assign(array('citys' => $citys, 'host' => $host, 'question' => $question, 'region' => $region)); $this->smartyOutputContent($this->getTemplatePath('citys.tpl')); }
public static function addShopAssociation($table, $alias, $context = null) { if (is_null($context)) { $context = Context::getContext(); } $table_alias = $table . '_shop'; if (strpos($table, '.') !== false) { list($table_alias, $table) = explode('.', $table); } if (!array_key_exists($table, self::$blog_shop_tables)) { return; } $sql = ' INNER JOIN ' . _DB_PREFIX_ . $table . '_shop ' . $table_alias . ' ON (' . $table_alias . '.id_' . $table . ' = ' . $alias . '.id_' . $table; if (isset($context->shop->id)) { $sql .= ' AND ' . $table_alias . '.id_shop = ' . (int) $context->shop->id; } elseif (Shop::checkIdShopDefault($table)) { $sql .= ' AND ' . $table_alias . '.id_shop = ' . $alias . '.id_shop_default'; } else { $sql .= ' AND ' . $table_alias . '.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')'; } $sql .= ')'; return $sql; }
public function __construct() { $this->table = 'smart_blog_category'; $this->className = 'BlogCategory'; $this->module = 'smartblog'; $this->lang = true; $this->image_dir = '../modules/smartblog/images/category'; $this->bootstrap = true; $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash')); $this->tpl_list_vars['icon'] = 'icon-folder-close'; $this->tpl_list_vars['title'] = $this->l('Categories'); $this->fields_list = array('id_smart_blog_category' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'name' => array('title' => $this->l('Name'), 'width' => 'auto'), 'description' => array('title' => $this->l('Description'), 'maxlength' => 90, 'orderby' => false), 'position' => array('title' => $this->l('Position'), 'filter_key' => 'position', 'align' => 'center', 'class' => 'fixed-width-sm', 'position' => 'position'), 'active' => array('title' => $this->l('Displayed'), 'class' => 'fixed-width-sm', 'active' => 'status', 'align' => 'center', 'type' => 'bool', 'orderby' => false)); /* $id_smart_blog_category = (int)Tools::getValue('id_smart_blog_category', Tools::getValue('id_smart_blog_category', 1)); $this->smart_blog_category = new BlogCategory($id_smart_blog_category); $this->context = Context::getContext(); $this->_where = ' AND `id_parent` = '.(int)$this->smart_blog_category->id; */ $this->_select = 'position '; $this->_orderBy = 'position'; if (Shop::isFeatureActive()) { Shop::addTableAssociation($this->table, array('type' => 'shop')); } $this->_join = 'LEFT JOIN ' . _DB_PREFIX_ . 'smart_blog_category_shop sbs ON a.id_smart_blog_category=sbs.id_smart_blog_category && sbs.id_shop IN(' . implode(',', Shop::getContextListShopID()) . ')'; $this->_select = 'sbs.id_shop'; $this->_defaultOrderBy = 'a.id_smart_blog_category'; $this->_defaultOrderWay = 'DESC'; if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) { $this->_group = 'GROUP BY a.id_smart_blog_category'; } parent::__construct(); }
public function beforeUpdateOptions() { if (!Tools::getValue('PS_STOCK_MANAGEMENT', true)) { $_POST['PS_ORDER_OUT_OF_STOCK'] = 1; $_POST['PS_DISPLAY_QTIES'] = 0; } // if advanced stock management is disabled, updates concerned tables if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 1 && (int) Tools::getValue('PS_ADVANCED_STOCK_MANAGEMENT') == 0) { $id_shop_list = Shop::getContextListShopID(); $sql_shop = 'UPDATE `' . _DB_PREFIX_ . 'product_shop` SET `advanced_stock_management` = 0 WHERE `advanced_stock_management` = 1 AND (`id_shop` = ' . implode(' OR `id_shop` = ', $id_shop_list) . ')'; $sql_stock = 'UPDATE `' . _DB_PREFIX_ . 'stock_available` SET `depends_on_stock` = 0, `quantity` = 0 WHERE `depends_on_stock` = 1 AND (`id_shop` = ' . implode(' OR `id_shop` = ', $id_shop_list) . ')'; $sql = 'UPDATE `' . _DB_PREFIX_ . 'product` SET `advanced_stock_management` = 0 WHERE `advanced_stock_management` = 1 AND (`id_shop_default` = ' . implode(' OR `id_shop_default` = ', $id_shop_list) . ')'; Db::getInstance()->execute($sql_shop); Db::getInstance()->execute($sql_stock); Db::getInstance()->execute($sql); } if (Tools::getIsset('PS_CATALOG_MODE')) { Tools::clearSmartyCache(); Media::clearCache(); } }
public function renderList() { $shops = Shop::getContextListShopID(); $links = array(); foreach ($shops as $shop_id) { $links = array_merge($links, MenuTopLinks::gets((int) $this->context->language->id, null, (int) $shop_id)); } $fields_list = array('id_linksmenutop' => array('title' => $this->l('Link ID'), 'type' => 'text'), 'name' => array('title' => $this->l('Shop name'), 'type' => 'text'), 'label' => array('title' => $this->l('Label'), 'type' => 'text'), 'link' => array('title' => $this->l('Link'), 'type' => 'link'), 'new_window' => array('title' => $this->l('New window'), 'type' => 'bool', 'align' => 'center', 'active' => 'status')); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = true; $helper->identifier = 'id_linksmenutop'; $helper->table = 'linksmenutop'; $helper->actions = array('edit', 'delete'); $helper->show_toolbar = false; $helper->module = $this; $helper->title = $this->l('Link list'); $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name; return $helper->generateList($links, $fields_list); }
/** * Add an SQL JOIN in query between a table and its associated table in multishop * * @param string $table Table name (E.g. product, module, etc.) * @param string $alias Alias of table * @param bool $inner_join Use or not INNER JOIN * @param string $on * @return string */ public static function addSqlAssociation($table, $alias, $inner_join = true, $on = null, $force_not_default = false) { $table_alias = $table . '_shop'; if (strpos($table, '.') !== false) { list($table_alias, $table) = explode('.', $table); } $asso_table = Shop::getAssoTable($table); if ($asso_table === false || $asso_table['type'] != 'shop') { return; } $sql = ($inner_join ? ' INNER' : ' LEFT') . ' JOIN ' . _DB_PREFIX_ . $table . '_shop ' . $table_alias . ' ON (' . $table_alias . '.id_' . $table . ' = ' . $alias . '.id_' . $table; if ((int) self::$context_id_shop) { $sql .= ' AND ' . $table_alias . '.id_shop = ' . (int) self::$context_id_shop; } elseif (Shop::checkIdShopDefault($table) && !$force_not_default) { $sql .= ' AND ' . $table_alias . '.id_shop = ' . $alias . '.id_shop_default'; } else { $sql .= ' AND ' . $table_alias . '.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')'; } $sql .= ($on ? ' AND ' . $on : '') . ')'; return $sql; }
/** * Delete TaxRulesGroup from this Carrier * * @param array|null $shops Shops * * @return bool Whether the TaxRulesGroup has been successfully removed from this Carrier */ public function deleteTaxRulesGroup(array $shops = null) { if (!$shops) { $shops = Shop::getContextListShopID(); } $where = 'id_carrier = ' . (int) $this->id; if ($shops) { $where .= ' AND id_shop IN(' . implode(', ', array_map('intval', $shops)) . ')'; } return Db::getInstance()->delete('carrier_tax_rules_group_shop', $where); }
/** * Delete product cover * * @param integer $id_product Product ID * @return boolean result */ public static function deleteCover($id_product) { if (!Validate::isUnsignedId($id_product)) { die(Tools::displayError()); } if (file_exists(_PS_TMP_IMG_DIR_ . 'product_' . $id_product . '.jpg')) { unlink(_PS_TMP_IMG_DIR_ . 'product_' . $id_product . '.jpg'); } return Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'image` SET `cover` = 0 WHERE `id_product` = ' . (int) $id_product) && Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'image` i, `' . _DB_PREFIX_ . 'image_shop` image_shop SET image_shop.`cover` = 0 WHERE image_shop.id_shop IN (' . implode(',', array_map('intval', Shop::getContextListShopID())) . ') AND image_shop.id_image = i.id_image AND i.`id_product` = ' . (int) $id_product); }
private function _postProcess() { if ($this->_postValidation() == false) { return false; } $this->_errors = array(); if (Tools::isSubmit('submitBlockCMS')) { $this->context->controller->getLanguages(); $id_cms_category = (int) Tools::getvalue('id_category'); $display_store = (int) Tools::getValue('display_stores'); $location = (int) Tools::getvalue('block_location'); $position = BlockCMSModel::getMaxPosition($location); if (Tools::isSubmit('addBlockCMS')) { $id_cms_block = BlockCMSModel::insertCMSBlock($id_cms_category, $location, $position, $display_store); if ($id_cms_block !== false) { foreach ($this->context->controller->_languages as $language) { BlockCMSModel::insertCMSBlockLang($id_cms_block, $language['id_lang']); } $shops = Shop::getContextListShopID(); foreach ($shops as $shop) { BlockCMSModel::insertCMSBlockShop($id_cms_block, $shop); } } $this->_errors[] = $this->l('New block cannot be created!'); } elseif (Tools::isSubmit('editBlockCMS')) { $id_cms_block = Tools::getvalue('id_cms_block'); $old_block = BlockCMSModel::getBlockCMS($id_cms_block); BlockCMSModel::deleteCMSBlockPage($id_cms_block); if ($old_block[1]['location'] != (int) Tools::getvalue('block_location')) { BlockCMSModel::updatePositions($old_block[1]['position'], $old_block[1]['position'] + 1, $old_block[1]['location']); } BlockCMSModel::updateCMSBlock($id_cms_block, $id_cms_category, $position, $location, $display_store); foreach ($this->context->controller->_languages as $language) { $block_name = Tools::getValue('block_name_' . $language['id_lang']); BlockCMSModel::updateCMSBlockLang($id_cms_block, $block_name, $language['id_lang']); } } $cmsBoxes = Tools::getValue('cmsBox'); if ($cmsBoxes) { foreach ($cmsBoxes as $cmsBox) { $cms_properties = explode('_', $cmsBox); BlockCMSModel::insertCMSBlockPage($id_cms_block, $cms_properties[1], $cms_properties[0]); } } if (Tools::isSubmit('addBlockCMS')) { $redirect = 'addBlockCMSConfirmation'; } elseif (Tools::isSubmit('editBlockCMS')) { $redirect = 'editBlockCMSConfirmation'; } Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&' . $redirect); } elseif (Tools::isSubmit('deleteBlockCMS') && Tools::getValue('id_cms_block')) { $id_cms_block = Tools::getvalue('id_cms_block'); if ($id_cms_block) { BlockCMSModel::deleteCMSBlock((int) $id_cms_block); BlockCMSModel::deleteCMSBlockPage((int) $id_cms_block); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&deleteBlockCMSConfirmation'); } else { $this->_html .= $this->displayError($this->l('Error: you are trying to delete a non-existent block cms')); } } elseif (Tools::isSubmit('submitFooterCMS')) { $powered_by = Tools::getValue('cms_footer_powered_by_on') ? 1 : 0; $footer_boxes = Tools::getValue('footerBox') ? implode('|', Tools::getValue('footerBox')) : ''; $block_activation = Tools::getValue('cms_footer_on') == 1 ? 1 : 0; Configuration::updateValue('FOOTER_CMS', rtrim($footer_boxes, '|')); Configuration::updateValue('FOOTER_POWEREDBY', $powered_by); Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', $block_activation); $this->_html .= $this->displayConfirmation($this->l('Footer\'s information updated')); } elseif (Tools::isSubmit('addBlockCMSConfirmation')) { $this->_html .= $this->displayConfirmation($this->l('Block CMS added')); } elseif (Tools::isSubmit('editBlockCMSConfirmation')) { $this->_html .= $this->displayConfirmation($this->l('Block CMS edited')); } elseif (Tools::isSubmit('deleteBlockCMSConfirmation')) { $this->_html .= $this->displayConfirmation($this->l('Deletion successful')); } elseif (Tools::isSubmit('id_cms_block') && Tools::isSubmit('way') && Tools::isSubmit('position') && Tools::isSubmit('location')) { $this->changePosition(); } elseif (Tools::isSubmit('updatePositions')) { $this->updatePositionsDnd(); } if (count($this->_errors)) { foreach ($this->_errors as $err) { $this->_html .= '<div class="alert error">' . $err . '</div>'; } } }
public function getData() { $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $date_between = $this->getDate(); $id_lang = $this->getLang(); // If a shop is selected, get all children categories for the shop $categories = array(); if (Shop::getContext() != Shop::CONTEXT_ALL) { $sql = 'SELECT c.nleft, c.nright FROM ' . _DB_PREFIX_ . 'category c WHERE c.id_category IN ( SELECT s.id_category FROM ' . _DB_PREFIX_ . 'shop s WHERE s.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ') )'; if ($result = Db::getInstance()->executeS($sql)) { $ntree_restriction = array(); foreach ($result as $row) { $ntree_restriction[] = '(nleft >= ' . $row['nleft'] . ' AND nright <= ' . $row['nright'] . ')'; } if ($ntree_restriction) { $sql = 'SELECT id_category FROM ' . _DB_PREFIX_ . 'category WHERE ' . implode(' OR ', $ntree_restriction); if ($result = Db::getInstance()->executeS($sql)) { foreach ($result as $row) { $categories[] = $row['id_category']; } } } } } // Get best categories $this->query = ' SELECT SQL_CALC_FOUND_ROWS ca.`id_category`, CONCAT(parent.name, \' > \', calang.`name`) as name, IFNULL(SUM(t.`totalQuantitySold`), 0) AS totalQuantitySold, ROUND(IFNULL(SUM(t.`totalPriceSold`), 0), 2) AS totalPriceSold, ( SELECT IFNULL(SUM(pv.`counter`), 0) FROM `' . _DB_PREFIX_ . 'page` p LEFT JOIN `' . _DB_PREFIX_ . 'page_viewed` pv ON p.`id_page` = pv.`id_page` LEFT JOIN `' . _DB_PREFIX_ . 'date_range` dr ON pv.`id_date_range` = dr.`id_date_range` LEFT JOIN `' . _DB_PREFIX_ . 'product` pr ON CAST(p.`id_object` AS UNSIGNED INTEGER) = pr.`id_product` LEFT JOIN `' . _DB_PREFIX_ . 'category_product` capr2 ON capr2.`id_product` = pr.`id_product` WHERE capr.`id_category` = capr2.`id_category` AND p.`id_page_type` = 1 AND dr.`time_start` BETWEEN ' . $date_between . ' AND dr.`time_end` BETWEEN ' . $date_between . ' ) AS totalPageViewed FROM `' . _DB_PREFIX_ . 'category` ca LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` calang ON (ca.`id_category` = calang.`id_category` AND calang.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('calang') . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` parent ON (ca.`id_parent` = parent.`id_category` AND parent.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('parent') . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_product` capr ON ca.`id_category` = capr.`id_category` LEFT JOIN ( SELECT pr.`id_product`, t.`totalQuantitySold`, t.`totalPriceSold` FROM `' . _DB_PREFIX_ . 'product` pr LEFT JOIN ( SELECT pr.`id_product`, IFNULL(SUM(cp.`product_quantity`), 0) AS totalQuantitySold, IFNULL(SUM(cp.`product_price` * cp.`product_quantity`), 0) / o.conversion_rate AS totalPriceSold FROM `' . _DB_PREFIX_ . 'product` pr LEFT OUTER JOIN `' . _DB_PREFIX_ . 'order_detail` cp ON pr.`id_product` = cp.`product_id` LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON o.`id_order` = cp.`id_order` WHERE o.valid = 1 AND o.invoice_date BETWEEN ' . $date_between . ' GROUP BY pr.`id_product` ) t ON t.`id_product` = pr.`id_product` ) t ON t.`id_product` = capr.`id_product` ' . ($categories ? 'WHERE ca.id_category IN (' . implode(', ', $categories) . ')' : '') . ' GROUP BY ca.`id_category` HAVING ca.`id_category` != 1'; if (Validate::IsName($this->_sort)) { $this->query .= ' ORDER BY `' . $this->_sort . '`'; if (isset($this->_direction) && Validate::isSortDirection($this->_direction)) { $this->query .= ' ' . $this->_direction; } } if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) { $this->query .= ' LIMIT ' . $this->_start . ', ' . $this->_limit; } $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query); foreach ($values as &$value) { $value['totalPriceSold'] = Tools::displayPrice($value['totalPriceSold'], $currency); } $this->_values = $values; $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()'); }
protected function getListContent($id_lang = null) { if (is_null($id_lang)) { $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); } $sql = 'SELECT r.`id_info`, rl.`text`, s.`name` as shop_name FROM `' . _DB_PREFIX_ . 'info` r LEFT JOIN `' . _DB_PREFIX_ . 'info_lang` rl ON (r.`id_info` = rl.`id_info`) LEFT JOIN `' . _DB_PREFIX_ . 'shop` s ON (r.`id_shop` = s.`id_shop`) WHERE `id_lang` = ' . (int) $id_lang . ' AND ('; if ($shop_ids = Shop::getContextListShopID()) { foreach ($shop_ids as $id_shop) { $sql .= ' r.`id_shop` = ' . (int) $id_shop . ' OR '; } } $sql .= ' r.`id_shop` = 0 )'; $content = Db::getInstance()->executeS($sql); foreach ($content as $key => $value) { $content[$key]['text'] = substr(strip_tags($value['text']), 0, 200); } return $content; }
public function getLinks() { $result = array(); // Get id and url $sql = 'SELECT b.`id_blocklink`, b.`url`, b.`new_window` FROM `' . _DB_PREFIX_ . 'blocklink` b'; if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) { $sql .= ' JOIN `' . _DB_PREFIX_ . 'blocklink_shop` bs ON b.`id_blocklink` = bs.`id_blocklink` AND bs.`id_shop` IN (' . implode(', ', Shop::getContextListShopID()) . ') '; } $sql .= (int) Configuration::get('PS_BLOCKLINK_ORDERWAY') == 1 ? ' ORDER BY `id_blocklink` DESC' : ''; if (!($links = Db::getInstance()->executeS($sql))) { return false; } $i = 0; foreach ($links as $link) { $result[$i]['id'] = $link['id_blocklink']; $result[$i]['url'] = $link['url']; $result[$i]['newWindow'] = $link['new_window']; // Get multilingual text if (!($texts = Db::getInstance()->executeS(' SELECT `id_lang`, `text` FROM ' . _DB_PREFIX_ . 'blocklink_lang WHERE `id_blocklink`=' . (int) $link['id_blocklink']))) { return false; } foreach ($texts as $text) { $result[$i]['text_' . $text['id_lang']] = $text['text']; } $i++; } return $result; }
public function setTaxRulesGroup($id_tax_rules_group, $all_shops = false) { if (!Validate::isUnsignedId($id_tax_rules_group)) { die(Tools::displayError()); } if (!$all_shops) { $shops = Shop::getContextListShopID(); } else { $shops = Shop::getShops(true, null, true); } $this->deleteTaxRulesGroup($shops); $values = array(); foreach ($shops as $id_shop) { $values[] = array('id_carrier' => (int) $this->id, 'id_tax_rules_group' => (int) $id_tax_rules_group, 'id_shop' => (int) $id_shop); } Cache::clean('carrier_id_tax_rules_group_' . (int) $this->id . '_' . (int) Context::getContext()->shop->id); return Db::getInstance()->insert('carrier_tax_rules_group_shop', $values); }
public function addPosition($position, $id_shop = null) { $return = true; if (is_null($id_shop)) { if (Shop::getContext() != Shop::CONTEXT_SHOP) { foreach (Shop::getContextListShopID() as $id_shop) { $return &= Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'category_shop` (`id_category`, `id_shop`, `position`) VALUES (' . (int) $this->id . ', ' . (int) $id_shop . ', ' . (int) $position . ') ON DUPLICATE KEY UPDATE `position` = ' . (int) $position); } } else { $id = Context::getContext()->shop->id; $id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT'); $return &= Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'category_shop` (`id_category`, `id_shop`, `position`) VALUES (' . (int) $this->id . ', ' . (int) $id_shop . ', ' . (int) $position . ') ON DUPLICATE KEY UPDATE `position` = ' . (int) $position); } } else { $return &= Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'category_shop` (`id_category`, `id_shop`, `position`) VALUES (' . (int) $this->id . ', ' . (int) $id_shop . ', ' . (int) $position . ') ON DUPLICATE KEY UPDATE `position` = ' . (int) $position); } return $return; }
/** * Get the current objects' list form the database * * @param integer $id_lang Language used for display * @param string $order_by ORDER BY clause * @param string $_orderWay Order way (ASC, DESC) * @param integer $start Offset in LIMIT clause * @param integer $limit Row count in LIMIT clause */ public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) { Hook::exec('action' . $this->controller_name . 'ListingFieldsModifier', array('select' => &$this->_select, 'join' => &$this->_join, 'where' => &$this->_where, 'group_by' => &$this->_groupBy, 'order_by' => &$this->_orderBy, 'order_way' => &$this->_orderWay, 'fields' => &$this->fields_list)); if (!isset($this->list_id)) { $this->list_id = $this->table; } /* Manage default params values */ $use_limit = true; if ($limit === false) { $use_limit = false; } elseif (empty($limit)) { if (isset($this->context->cookie->{$this->list_id . '_pagination'}) && $this->context->cookie->{$this->list_id . '_pagination'}) { $limit = $this->context->cookie->{$this->list_id . '_pagination'}; } else { $limit = $this->_default_pagination; } } if (!Validate::isTableOrIdentifier($this->table)) { throw new PrestaShopException(sprintf('Table name %s is invalid:', $this->table)); } $prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this))); if (empty($order_by)) { if ($this->context->cookie->{$prefix . $this->list_id . 'Orderby'}) { $order_by = $this->context->cookie->{$prefix . $this->list_id . 'Orderby'}; } elseif ($this->_orderBy) { $order_by = $this->_orderBy; } else { $order_by = $this->_defaultOrderBy; } } if (empty($order_way)) { if ($this->context->cookie->{$prefix . $this->list_id . 'Orderway'}) { $order_way = $this->context->cookie->{$prefix . $this->list_id . 'Orderway'}; } elseif ($this->_orderWay) { $order_way = $this->_orderWay; } else { $order_way = $this->_defaultOrderWay; } } $limit = (int) Tools::getValue($this->list_id . '_pagination', $limit); if (in_array($limit, $this->_pagination) && $limit != $this->_default_pagination) { $this->context->cookie->{$this->list_id . '_pagination'} = $limit; } else { unset($this->context->cookie->{$this->list_id . '_pagination'}); } /* Check params validity */ if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way) || !is_numeric($start) || !is_numeric($limit) || !Validate::isUnsignedId($id_lang)) { throw new PrestaShopException('get list params is not valid'); } if (!isset($this->fields_list[$order_by]['order_key']) && isset($this->fields_list[$order_by]['filter_key'])) { $this->fields_list[$order_by]['order_key'] = $this->fields_list[$order_by]['filter_key']; } if (isset($this->fields_list[$order_by]) && isset($this->fields_list[$order_by]['order_key'])) { $order_by = $this->fields_list[$order_by]['order_key']; } /* Determine offset from current page */ $start = 0; if ((int) Tools::getValue('submitFilter' . $this->list_id)) { $start = ((int) Tools::getValue('submitFilter' . $this->list_id) - 1) * $limit; } elseif (empty($start) && isset($this->context->cookie->{$this->list_id . '_start'}) && Tools::isSubmit('export' . $this->table)) { $start = $this->context->cookie->{$this->list_id . '_start'}; } // Either save or reset the offset in the cookie if ($start) { $this->context->cookie->{$this->list_id . '_start'} = $start; } elseif (isset($this->context->cookie->{$this->list_id . '_start'})) { unset($this->context->cookie->{$this->list_id . '_start'}); } /* Cache */ $this->_lang = (int) $id_lang; $this->_orderBy = $order_by; if (preg_match('/[.!]/', $order_by)) { $order_by_split = preg_split('/[.!]/', $order_by); $order_by = bqSQL($order_by_split[0]) . '.`' . bqSQL($order_by_split[1]) . '`'; } elseif ($order_by) { $order_by = '`' . bqSQL($order_by) . '`'; } $this->_orderWay = Tools::strtoupper($order_way); /* SQL table : orders, but class name is Order */ $sql_table = $this->table == 'order' ? 'orders' : $this->table; // Add SQL shop restriction $select_shop = $join_shop = $where_shop = ''; if ($this->shopLinkType) { $select_shop = ', shop.name as shop_name '; $join_shop = ' LEFT JOIN ' . _DB_PREFIX_ . $this->shopLinkType . ' shop ON a.id_' . $this->shopLinkType . ' = shop.id_' . $this->shopLinkType; $where_shop = Shop::addSqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType); } if ($this->multishop_context && Shop::isTableAssociated($this->table) && !empty($this->className)) { if (Shop::getContext() != Shop::CONTEXT_ALL || !$this->context->employee->isSuperAdmin()) { $test_join = !preg_match('#`?' . preg_quote(_DB_PREFIX_ . $this->table . '_shop') . '`? *sa#', $this->_join); if (Shop::isFeatureActive() && $test_join && Shop::isTableAssociated($this->table)) { $this->_where .= ' AND a.' . $this->identifier . ' IN ( SELECT sa.' . $this->identifier . ' FROM `' . _DB_PREFIX_ . $this->table . '_shop` sa WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ') )'; } } } /* Query in order to get results with all fields */ $lang_join = ''; if ($this->lang) { $lang_join = 'LEFT JOIN `' . _DB_PREFIX_ . $this->table . '_lang` b ON (b.`' . $this->identifier . '` = a.`' . $this->identifier . '` AND b.`id_lang` = ' . (int) $id_lang; if ($id_lang_shop) { if (!Shop::isFeatureActive()) { $lang_join .= ' AND b.`id_shop` = 1'; } elseif (Shop::getContext() == Shop::CONTEXT_SHOP) { $lang_join .= ' AND b.`id_shop` = ' . (int) $id_lang_shop; } else { $lang_join .= ' AND b.`id_shop` = a.id_shop_default'; } } $lang_join .= ')'; } $having_clause = ''; if (isset($this->_filterHaving) || isset($this->_having)) { $having_clause = ' HAVING '; if (isset($this->_filterHaving)) { $having_clause .= ltrim($this->_filterHaving, ' AND '); } if (isset($this->_having)) { $having_clause .= $this->_having . ' '; } } do { $this->_listsql = ' SELECT SQL_CALC_FOUND_ROWS ' . ($this->_tmpTableFilter ? ' * FROM (SELECT ' : ''); if ($this->explicitSelect) { foreach ($this->fields_list as $key => $array_value) { // Add it only if it is not already in $this->_select if (isset($this->_select) && preg_match('/[\\s]`?' . preg_quote($key, '/') . '`?\\s*,/', $this->_select)) { continue; } if (isset($array_value['filter_key'])) { $this->_listsql .= str_replace('!', '.', $array_value['filter_key']) . ' as ' . $key . ','; } elseif ($key == 'id_' . $this->table) { $this->_listsql .= 'a.`' . bqSQL($key) . '`,'; } elseif ($key != 'image' && !preg_match('/' . preg_quote($key, '/') . '/i', $this->_select)) { $this->_listsql .= '`' . bqSQL($key) . '`,'; } } $this->_listsql = rtrim($this->_listsql, ','); } else { $this->_listsql .= ($this->lang ? 'b.*,' : '') . ' a.*'; } $this->_listsql .= ' ' . (isset($this->_select) ? ', ' . rtrim($this->_select, ', ') : '') . $select_shop . ' FROM `' . _DB_PREFIX_ . $sql_table . '` a ' . $lang_join . ' ' . (isset($this->_join) ? $this->_join . ' ' : '') . ' ' . $join_shop . ' WHERE 1 ' . (isset($this->_where) ? $this->_where . ' ' : '') . ($this->deleted ? 'AND a.`deleted` = 0 ' : '') . (isset($this->_filter) ? $this->_filter : '') . $where_shop . ' ' . (isset($this->_group) ? $this->_group . ' ' : '') . ' ' . $having_clause . ' ORDER BY ' . (str_replace('`', '', $order_by) == $this->identifier ? 'a.' : '') . $order_by . ' ' . pSQL($order_way) . ($this->_tmpTableFilter ? ') tmpTable WHERE 1' . $this->_tmpTableFilter : '') . ($use_limit === true ? ' LIMIT ' . (int) $start . ',' . (int) $limit : ''); $this->_list = Db::getInstance()->executeS($this->_listsql, true, false); if ($this->_list === false) { $this->_list_error = Db::getInstance()->getMsgError(); break; } $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `' . _DB_PREFIX_ . $this->table . '`', false); if ($use_limit === true) { $start = (int) $start - (int) $limit; if ($start < 0) { break; } } else { break; } } while (empty($this->_list)); Hook::exec('action' . $this->controller_name . 'ListingResultsModifier', array('list' => &$this->_list, 'list_total' => &$this->_listTotal)); }
public function renderForm() { // Init toolbar $this->initToolbarTitle(); // toolbar (save, cancel, new, ..) $this->initToolbar(); $id_module = (int) Tools::getValue('id_module'); $id_hook = (int) Tools::getValue('id_hook'); if (Tools::isSubmit('editGraft')) { // Check auth for this page if (!$id_module || !$id_hook) { Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token); } $sql = 'SELECT id_module FROM ' . _DB_PREFIX_ . 'hook_module WHERE id_module = ' . $id_module . ' AND id_hook = ' . $id_hook . ' AND id_shop IN(' . implode(', ', Shop::getContextListShopID()) . ')'; if (!Db::getInstance()->getValue($sql)) { Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token); } $sl_module = Module::getInstanceById($id_module); $excepts_list = $sl_module->getExceptions($id_hook, true); $excepts_diff = false; $excepts = ''; if ($excepts_list) { $first = current($excepts_list); foreach ($excepts_list as $k => $v) { if (array_diff($v, $first) || array_diff($first, $v)) { $excepts_diff = true; } } if (!$excepts_diff) { $excepts = implode(', ', $first); } } } else { $excepts_diff = false; $excepts_list = Tools::getValue('exceptions', array(array())); } $modules = Module::getModulesInstalled(0); $instances = array(); foreach ($modules as $module) { if ($tmp_instance = Module::getInstanceById($module['id_module'])) { $instances[$tmp_instance->displayName] = $tmp_instance; } } ksort($instances); $modules = $instances; $hooks = Hook::getHooks(0); $exception_list_diff = array(); foreach ($excepts_list as $shop_id => $file_list) { $exception_list_diff[] = $this->displayModuleExceptionList($file_list, $shop_id); } $tpl = $this->createTemplate('form.tpl'); $tpl->assign(array('url_submit' => self::$currentIndex . '&token=' . $this->token, 'edit_graft' => Tools::isSubmit('editGraft'), 'id_module' => (int) Tools::getValue('id_module'), 'id_hook' => (int) Tools::getValue('id_hook'), 'show_modules' => Tools::getValue('show_modules'), 'hooks' => $hooks, 'exception_list' => $this->displayModuleExceptionList(array_shift($excepts_list), 0), 'exception_list_diff' => $exception_list_diff, 'except_diff' => isset($excepts_diff) ? $excepts_diff : null, 'display_key' => $this->display_key, 'modules' => $modules, 'show_toolbar' => true, 'toolbar_btn' => $this->toolbar_btn, 'toolbar_scroll' => $this->toolbar_scroll, 'title' => $this->toolbar_title, 'table' => 'hook_module')); return $tpl->fetch(); }
public function ajaxProcessaddProductImage() { self::$currentIndex = 'index.php?tab=AdminProducts'; $product = new Product((int) Tools::getValue('id_product')); $legends = Tools::getValue('legend'); if (!is_array($legends)) { $legends = (array) $legends; } if (!Validate::isLoadedObject($product)) { $files = array(); $files[0]['error'] = Tools::displayError('Cannot add image because product creation failed.'); } $image_uploader = new HelperImageUploader('file'); $image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg'))->setMaxSize($this->max_image_size); $files = $image_uploader->process(); foreach ($files as &$file) { $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; foreach ($legends as $key => $legend) { if (!empty($legend)) { $image->legend[(int) $key] = $legend; } } if (!Image::getCover($image->id_product)) { $image->cover = 1; } else { $image->cover = 0; } if (($validate = $image->validateFieldsLang(false, true)) !== true) { $file['error'] = Tools::displayError($validate); } if (isset($file['error']) && (!is_numeric($file['error']) || $file['error'] != 0)) { continue; } if (!$image->add()) { $file['error'] = Tools::displayError('Error while creating additional image'); } else { if (!($new_path = $image->getPathForCreation())) { $file['error'] = Tools::displayError('An error occurred during new folder creation'); continue; } $error = 0; if (!ImageManager::resize($file['save_path'], $new_path . '.' . $image->image_format, null, null, 'jpg', false, $error)) { switch ($error) { case ImageManager::ERROR_FILE_NOT_EXIST: $file['error'] = Tools::displayError('An error occurred while copying image, the file does not exist anymore.'); break; case ImageManager::ERROR_FILE_WIDTH: $file['error'] = Tools::displayError('An error occurred while copying image, the file width is 0px.'); break; case ImageManager::ERROR_MEMORY_LIMIT: $file['error'] = Tools::displayError('An error occurred while copying image, check your memory limit.'); break; default: $file['error'] = Tools::displayError('An error occurred while copying image.'); break; } continue; } else { $imagesTypes = ImageType::getImagesTypes('products'); foreach ($imagesTypes as $imageType) { if (!ImageManager::resize($file['save_path'], $new_path . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) { $file['error'] = Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']); continue; } } } unlink($file['save_path']); //Necesary to prevent hacking unset($file['save_path']); Hook::exec('actionWatermark', array('id_image' => $image->id, 'id_product' => $product->id)); if (!$image->update()) { $file['error'] = Tools::displayError('Error while updating status'); continue; } // Associate image to shop from context $shops = Shop::getContextListShopID(); $image->associateTo($shops); $json_shops = array(); foreach ($shops as $id_shop) { $json_shops[$id_shop] = true; } $file['status'] = 'ok'; $file['id'] = $image->id; $file['position'] = $image->position; $file['cover'] = $image->cover; $file['legend'] = $image->legend; $file['path'] = $image->getExistingImgPath(); $file['shops'] = $json_shops; @unlink(_PS_TMP_IMG_DIR_ . 'product_' . (int) $product->id . '.jpg'); @unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product->id . '_' . $this->context->shop->id . '.jpg'); } } die(Tools::jsonEncode(array($image_uploader->getName() => $files))); }