/**
  * Return list of employees
  *
  * @return array|false Employees or false
  */
 public static function getEmployeesByProduct($id_product)
 {
     $sql = 'SELECT e.*, CONCAT(e.firstName, \' \', e.lastName) as fullName
         FROM `' . _DB_PREFIX_ . 'employee` e
         ' . Shop::addSqlAssociation('employee', 's') . '
         JOIN `' . _DB_PREFIX_ . 'employee_product` ep ON (ep.`id_employee` = e.`id_employee`)
         WHERE ep.`id_product`=' . $id_product . '
         AND e.id_profile IN (' . Configuration::get('APH_PROFILE_STORE_OWNER') . ', ' . Configuration::get('APH_PROFILE_STORE_EMPLOYEE') . ') 
         ORDER BY `lastname` ASC';
     $e = Db::getInstance()->executeS($sql);
     $employees = array();
     foreach ($e as &$employee) {
         $employees[$employee['id_employee']] = $employee;
         $employees[$employee['id_employee']]['text_color'] = '';
         $employees[$employee['id_employee']]['bg_color'] = '';
         $employees[$employee['id_employee']]['badge_style'] = '';
         if (!empty($employee['bo_color'])) {
             $employees[$employee['id_employee']]['text_color'] = Tools::getBrightness($employee['bo_color']) < 128 ? 'white' : '#383838';
             $employees[$employee['id_employee']]['bg_color'] = $employee['bo_color'];
             $employees[$employee['id_employee']]['badge_style'] = '.badge.employee_' . $employee['id_employee'] . '.active {
                     background-color: ' . $employees[$employee['id_employee']]['bg_color'] . ';
                     border-color: ' . $employees[$employee['id_employee']]['bg_color'] . ';
                     color: ' . $employees[$employee['id_employee']]['text_color'] . ';
                 }
                 .badge.employee_' . $employee['id_employee'] . '.notactive {
                     background-color: #fff;
                     border-color: ' . $employees[$employee['id_employee']]['bg_color'] . ';
                     color: ' . $employees[$employee['id_employee']]['bg_color'] . ';
                 }';
         }
     }
     return $employees;
 }
Esempio n. 2
0
 public static function getSubCategories($id_lang, $active = true, $id_category = 2, $p = 0, $n = 6)
 {
     $sql_groups_where = '';
     $sql_groups_join = '';
     if (Group::isFeatureActive()) {
         $sql_groups_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`)';
         $groups = FrontController::getCurrentCustomerGroups();
         $sql_groups_where = 'AND cg.`id_group` ' . (count($groups) ? 'IN (' . pSQL(implode(',', $groups)) . ')' : '=' . (int) Group::getCurrent()->id);
     }
     $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
     SELECT c.*, cl.id_lang, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description
     FROM `' . _DB_PREFIX_ . 'category` c
     ' . Shop::addSqlAssociation('category', 'c') . '
     LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` 
 		AND `id_lang` = ' . (int) $id_lang . ' ' . Shop::addSqlRestrictionOnLang('cl') . ')
     ' . $sql_groups_join . '
     WHERE `id_parent` = ' . (int) $id_category . '
     ' . ($active ? 'AND `active` = 1' : '') . '
     ' . $sql_groups_where . '
     GROUP BY c.`id_category`
     ORDER BY `level_depth` ASC, category_shop.`position` ASC
     LIMIT ' . (int) $p . ', ' . (int) $n);
     foreach ($result as &$row) {
         $row['id_image'] = Tools::file_exists_cache(_PS_CAT_IMG_DIR_ . $row['id_category'] . '.jpg') ? (int) $row['id_category'] : Language::getIsoById($id_lang) . '-default';
         $row['legend'] = 'no picture';
     }
     return $result;
 }
 /**
  * Gets the name of a given product, in the given lang
  * HAI : override method to record product name with sort
  * 
  * @since 1.5.0
  * @param int $id_product
  * @param int $id_product_attribute Optional
  * @param int $id_lang Optional
  * @return string
  */
 public static function getProductName($id_product, $id_product_attribute = null, $id_lang = null)
 {
     // use the lang in the context if $id_lang is not defined
     if (!$id_lang) {
         $id_lang = (int) Context::getContext()->language->id;
     }
     // creates the query object
     $query = new DbQuery();
     // selects different names, if it is a combination
     if ($id_product_attribute) {
         $query->select('IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(DISTINCT agl.`name`, \' - \', al.name ORDER BY agl.`name`, \' - \', al.name ASC SEPARATOR \', \')),pl.name) as name');
     } else {
         $query->select('DISTINCT pl.name as name');
     }
     // adds joins & where clauses for combinations
     if ($id_product_attribute) {
         $query->from('product_attribute', 'pa');
         $query->join(Shop::addSqlAssociation('product_attribute', 'pa'));
         $query->innerJoin('product_lang', 'pl', 'pl.id_product = pa.id_product AND pl.id_lang = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl'));
         $query->leftJoin('product_attribute_combination', 'pac', 'pac.id_product_attribute = pa.id_product_attribute');
         $query->leftJoin('attribute', 'atr', 'atr.id_attribute = pac.id_attribute');
         $query->leftJoin('attribute_lang', 'al', 'al.id_attribute = atr.id_attribute AND al.id_lang = ' . (int) $id_lang);
         $query->leftJoin('attribute_group_lang', 'agl', 'agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = ' . (int) $id_lang);
         $query->where('pa.id_product = ' . (int) $id_product . ' AND pa.id_product_attribute = ' . (int) $id_product_attribute);
     } else {
         $query->from('product_lang', 'pl');
         $query->where('pl.id_product = ' . (int) $id_product);
         $query->where('pl.id_lang = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl'));
     }
     return Db::getInstance()->getValue($query);
 }
    public function renderList()
    {
        $this->addRowAction('details');
        $this->toolbar_btn = array();
        // disables link
        $this->list_no_link = true;
        // query
        $this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations, SUM(s.usable_quantity+s.usable_quantity_remainder) as stock';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pa.id_product = a.id_product)
						' . Shop::addSqlAssociation('product_attribute', 'pa', false) . '
						INNER JOIN `' . _DB_PREFIX_ . 'stock` s ON (s.id_product = a.id_product)';
        $this->_group = 'GROUP BY a.id_product';
        self::$currentIndex .= '&coverage_period=' . (int) $this->getCurrentCoveragePeriod() . '&warn_days=' . (int) $this->getCurrentWarning();
        if ($this->getCurrentCoverageWarehouse() != -1) {
            $this->_where .= ' AND s.id_warehouse = ' . (int) $this->getCurrentCoverageWarehouse();
            self::$currentIndex .= '&id_warehouse=' . (int) $this->getCurrentCoverageWarehouse();
        }
        // Hack for multi shop ..
        $this->_where .= ' AND b.id_shop = 1';
        $this->tpl_list_vars['stock_cover_periods'] = $this->stock_cover_periods;
        $this->tpl_list_vars['stock_cover_cur_period'] = $this->getCurrentCoveragePeriod();
        $this->tpl_list_vars['stock_cover_warehouses'] = $this->stock_cover_warehouses;
        $this->tpl_list_vars['stock_cover_cur_warehouse'] = $this->getCurrentCoverageWarehouse();
        $this->tpl_list_vars['stock_cover_warn_days'] = $this->getCurrentWarning();
        $this->ajax_params = array('period' => $this->getCurrentCoveragePeriod(), 'id_warehouse' => $this->getCurrentCoverageWarehouse(), 'warn_days' => $this->getCurrentWarning());
        $this->displayInformation($this->l('Considering the coverage period chosen and the quantity of products/combinations that you sold.'));
        $this->displayInformation($this->l('this interface gives you an idea of when a product will run out of stock.'));
        return $this->adminControllerRenderList();
    }
    public function __construct()
    {
        $this->bootstrap = true;
        $this->table = 'alias';
        $this->className = 'Alias';
        $this->lang = false;
        parent::__construct();
        // Alias fields
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        if (!Tools::getValue('realedit')) {
            $this->deleted = false;
        }
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
        $this->fields_list = array('alias' => array('title' => $this->l('Aliases')), 'search' => array('title' => $this->l('Search')), 'active' => array('title' => $this->l('Status'), 'class' => 'fixed-width-sm', 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
        // Search options
        $current_file_name = array_reverse(explode('/', $_SERVER['SCRIPT_NAME']));
        $cron_url = Tools::getHttpHost(true, true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_) . '/searchcron.php?full=1&token=' . substr(_COOKIE_KEY_, 34, 8);
        list($total, $indexed) = Db::getInstance()->getRow('SELECT COUNT(*) as "0", SUM(product_shop.indexed) as "1" FROM ' . _DB_PREFIX_ . 'product p ' . Shop::addSqlAssociation('product', 'p') . ' WHERE product_shop.`visibility` IN ("both", "search") AND product_shop.`active` = 1');
        $this->fields_options = array('indexation' => array('title' => $this->l('Indexing'), 'icon' => 'icon-cogs', 'info' => '<p>' . $this->l('The "indexed" products have been analyzed by PrestaShop and will appear in the results of a Front Office search.') . '<br />
						' . $this->l('Indexed products') . ' <strong>' . (int) $indexed . ' / ' . (int) $total . '</strong>.
						</p>
						<p>' . $this->l('Building the product index may take a few minutes.') . $this->l('If your server stops before the process ends, you can resume the indexing by clicking "Add missing products."') . '</p>
						<a href="searchcron.php?token=' . substr(_COOKIE_KEY_, 34, 8) . '&amp;redirect=1" class="btn-link"><i class="icon-external-link-sign"></i> ' . $this->l('Add missing products to the index.') . '</a><br />
						<a href="searchcron.php?full=1&amp;token=' . substr(_COOKIE_KEY_, 34, 8) . '&amp;redirect=1" class="btn-link"><i class="icon-external-link-sign"></i> ' . $this->l('Re-build the entire index.') . '</a><br /><br />
						' . $this->l('You can set a cron job that will rebuild your index using the following URL:') . ' <a href="' . Tools::safeOutput($cron_url) . '"><i class="icon-external-link-sign"></i> ' . Tools::safeOutput($cron_url) . '</a>', 'fields' => array('PS_SEARCH_INDEXATION' => array('title' => $this->l('Indexing'), 'validation' => 'isBool', 'type' => 'bool', 'cast' => 'intval', 'desc' => $this->l('Enable the automatic indexing of products. If you enable this feature, the products will be indexed in the search automatically when they are saved. If the feature is disabled, you will have to index products manually by using the links provided in the field set.'))), 'submit' => array('title' => $this->l('Save'))), 'search' => array('title' => $this->l('Search'), 'icon' => 'icon-search', 'fields' => array('PS_SEARCH_AJAX' => array('title' => $this->l('Ajax search'), 'validation' => 'isBool', 'type' => 'bool', 'cast' => 'intval', 'hint' => array($this->l('Enable ajax search for your visitors.'), $this->l('With ajax search, the first 10 products matching the user query will appear in real time below the input field.'))), 'PS_INSTANT_SEARCH' => array('title' => $this->l('Instant search'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'hint' => array($this->l('Enable instant search for your visitors?'), $this->l('With instant search, the results will appear immediately as the user writes a query.'))), 'PS_SEARCH_MINWORDLEN' => array('title' => $this->l('Minimum word length (in characters)'), 'hint' => $this->l('Only words this size or larger will be indexed.'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_BLACKLIST' => array('title' => $this->l('Blacklisted words'), 'validation' => 'isGenericName', 'hint' => $this->l('Please enter the index words separated by a "|".'), 'type' => 'textLang')), 'submit' => array('title' => $this->l('Save'))), 'relevance' => array('title' => $this->l('Weight'), 'icon' => 'icon-cogs', 'info' => $this->l('The "weight" represents its importance and relevance for the ranking of the products when completing a new search.') . '<br />
						' . $this->l('A word with a weight of eight will have four times more value than a word with a weight of two.') . '<br /><br />
						' . $this->l('We advise you to set a greater weight for words which appear in the name or reference of a product. This will allow the search results to be as precise and relevant as possible.') . '<br /><br />
						' . $this->l('Setting a weight to 0 will exclude that field from search index. Re-build of the entire index is required when changing to or from 0'), 'fields' => array('PS_SEARCH_WEIGHT_PNAME' => array('title' => $this->l('Product name weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_REF' => array('title' => $this->l('Reference weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_SHORTDESC' => array('title' => $this->l('Short description weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_DESC' => array('title' => $this->l('Description weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_CNAME' => array('title' => $this->l('Category weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_MNAME' => array('title' => $this->l('Manufacturer weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_TAG' => array('title' => $this->l('Tags weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_ATTRIBUTE' => array('title' => $this->l('Attributes weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_FEATURE' => array('title' => $this->l('Features weight'), 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval')), 'submit' => array('title' => $this->l('Save'))));
    }
Esempio n. 6
0
    /**
     * Lists of items
     * @param int $iIdLang
     * @param bool $active
     * @return array
     */
    public static function getProductsCollection($iIdLang = null, $bActive = true)
    {
        if (!Validate::isBool($bActive)) {
            die(Tools::displayError());
        }
        if (is_null($iIdLang)) {
            $iIdLang = (int) Context::getContext()->language->id;
        }
        $sSQL = '
			SELECT r.`id_product`
			FROM `' . _DB_PREFIX_ . 'now_mea_home` r
			' . Shop::addSqlAssociation('now_mea_home', 'r') . '
			LEFT JOIN `' . _DB_PREFIX_ . 'now_product_type_product` pt ON (pt.`id_product` = r.`id_product`)
			WHERE 1 ' . ($bActive ? ' AND r.`active` = 1 ' : '') . '
			AND pt.`id_now_product_type_product` IS NULL
			ORDER BY RAND() LIMIT 0 , ' . Configuration::get('NOW_MEA_HOME_NB_PRODUCT');
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sSQL);
        $aProducts = array();
        foreach ($result as $row) {
            $oProduct = new Product($row['id_product'], false, $iIdLang);
            $oProduct->loadStockData();
            $aProducts[] = $oProduct;
        }
        return $aProducts;
    }
Esempio n. 7
0
    public static function getFrontFeaturesStatic($id_lang, $id_product)
    {
        if (!Feature::isFeatureActive()) {
            return array();
        }
        if (!array_key_exists($id_product . '-' . $id_lang, self::$_frontFeaturesCache)) {
            self::$_frontFeaturesCache[$id_product . '-' . $id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
				SELECT name, value, pf.id_feature
				FROM ' . _DB_PREFIX_ . 'feature_product pf
				LEFT JOIN ' . _DB_PREFIX_ . 'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = ' . (int) $id_lang . ')
				LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = ' . (int) $id_lang . ')
				LEFT JOIN ' . _DB_PREFIX_ . 'feature f ON (f.id_feature = pf.id_feature AND fl.id_lang = ' . (int) $id_lang . ')
				' . Shop::addSqlAssociation('feature', 'f') . '
				WHERE pf.id_product = ' . (int) $id_product . '
				ORDER BY f.position ASC');
        }
        $features = self::$_frontFeaturesCache[$id_product . '-' . $id_lang];
        foreach ($features as &$feature) {
            if ($feature['id_feature'] == 9 && Context::getContext()->language->id != 1) {
                $feature['value'] = Tools::rus2translit($feature['value']);
            }
        }
        return $features;
        //return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
    }
    public function __construct()
    {
        $this->table = 'alias';
        $this->className = 'Alias';
        $this->lang = false;
        parent::__construct();
        // Alias fields
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        if (!Tools::getValue('realedit')) {
            $this->deleted = false;
        }
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
        $this->fields_list = array('alias' => array('title' => $this->l('Aliases'), 'width' => 'auto'), 'search' => array('title' => $this->l('Search'), 'width' => 100), 'active' => array('title' => $this->l('Status'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
        // Search options
        $current_file_name = array_reverse(explode('/', $_SERVER['SCRIPT_NAME']));
        $cron_url = Tools::getHttpHost(true, true) . __PS_BASE_URI__ . substr($_SERVER['SCRIPT_NAME'], strlen(__PS_BASE_URI__), -strlen($current_file_name['0'])) . 'searchcron.php?full=1&token=' . substr(_COOKIE_KEY_, 34, 8);
        list($total, $indexed) = Db::getInstance()->getRow('SELECT COUNT(*) as "0", SUM(product_shop.indexed) as "1" FROM ' . _DB_PREFIX_ . 'product p ' . Shop::addSqlAssociation('product', 'p'));
        $this->fields_options = array('indexation' => array('title' => $this->l('Indexation'), 'icon' => 'search', 'info' => $this->l('The "indexed" products have been analyzed by PrestaShop and will appear in the results of the Front Office search.') . '<br />
						' . $this->l('Indexed products:') . ' <b>' . (int) $indexed . ' / ' . (int) $total . '</b>.
						</p>
						<p>' . $this->l('Building the product index can take a few minutes or more.') . $this->l('If your server stops the process before it ends, you can resume the indexation by clicking "Add missing products."') . '</p>
						-&gt; <a href="searchcron.php?token=' . substr(_COOKIE_KEY_, 34, 8) . '&redirect=1" class="bold">' . $this->l('Add missing products to index.') . '</a><br />
						-&gt; <a href="searchcron.php?full=1&token=' . substr(_COOKIE_KEY_, 34, 8) . '&redirect=1" class="bold">' . $this->l('Re-build entire index.') . '</a><br /><br />
						' . $this->l('You can set a cron job that will rebuild your index using the following URL:') . ' <a href="' . $cron_url . '">' . $cron_url . '</a>', 'fields' => array('PS_SEARCH_INDEXATION' => array('title' => $this->l('Indexation'), 'validation' => 'isBool', 'type' => 'bool', 'cast' => 'intval', 'desc' => $this->l('Enable automatic indexation of the products. If you enable this feature, the products will be indexed in the search automatically when they are saved, but if the feature is disabled, you will have to index the products manually by using the links provided in this fieldset.')))), 'search' => array('title' => $this->l('Search'), 'icon' => 'search', 'fields' => array('PS_SEARCH_AJAX' => array('title' => $this->l('Ajax search'), 'validation' => 'isBool', 'type' => 'bool', 'cast' => 'intval', 'desc' => $this->l('Enable ajax search for your visitors.') . '<br />' . $this->l('With ajax search, the first 10 products matching the user query will appear in real time below the input field.')), 'PS_INSTANT_SEARCH' => array('title' => $this->l('Instant search'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'desc' => $this->l('Enable instant search for your visitors.') . '<br />' . $this->l('With instant search, the results will appear immediately as the user writes a query.')), 'PS_SEARCH_MINWORDLEN' => array('title' => $this->l('Minimum word length (in characters)'), 'desc' => $this->l('Only words this size or larger will be indexed.'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_BLACKLIST' => array('title' => $this->l('Blacklisted words'), 'size' => 35, 'validation' => 'isGenericName', 'desc' => $this->l('Please enter the words separated by a "|".'), 'type' => 'textLang')), 'submit' => array()), 'relevance' => array('title' => $this->l('Weight'), 'icon' => 'weight', 'info' => $this->l('The "weight" represents its importance and relevance for the ranking of the products when try a new search.') . '<br />
						' . $this->l('A word with a weight of 8 will have 4 times more value than a word with a weight of 2.') . '<br /><br />
						' . $this->l('That\'s why we advise to set a greater weight for words which appear in the name or reference of a product than the ones in the description. Thus, the search results will be as precise and relevant as possible.'), 'fields' => array('PS_SEARCH_WEIGHT_PNAME' => array('title' => $this->l('Product name weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_REF' => array('title' => $this->l('Reference weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_SHORTDESC' => array('title' => $this->l('Short description weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_DESC' => array('title' => $this->l('Description weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_CNAME' => array('title' => $this->l('Category weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_MNAME' => array('title' => $this->l('Manufacturer weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_TAG' => array('title' => $this->l('Tags weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_ATTRIBUTE' => array('title' => $this->l('Attributes weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'), 'PS_SEARCH_WEIGHT_FEATURE' => array('title' => $this->l('Features weight'), 'size' => 4, 'validation' => 'isUnsignedInt', 'type' => 'text', 'cast' => 'intval'))));
    }
    public static function getTaxRulesGroups($only_active = true)
    {
        return Db::getInstance()->executeS('
			SELECT DISTINCT g.id_tax_rules_group, g.name, g.active
			FROM `' . _DB_PREFIX_ . 'tax_rules_group` g' . Shop::addSqlAssociation('tax_rules_group', 'g') . ($only_active ? ' WHERE g.`active` = 1' : '') . '
			ORDER BY name ASC');
    }
Esempio n. 10
0
    public function renderContent($setting)
    {
        $t = array('product_id' => 0, 'image_height' => '320', 'image_width' => 300);
        $setting = array_merge($t, $setting);
        $id_lang = (int) $this->lang_id;
        $id_product = $setting['product_id'];
        $sql = 'SELECT p.*, product_shop.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
						pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
						p.`ean13`, p.`upc`, MAX(image_shop.`id_image`) id_image, il.`legend`,
						DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(),
						INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . '
							DAY)) > 0 AS new
					FROM `' . _DB_PREFIX_ . 'product` p
					LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
						p.`id_product` = pl.`id_product`
						AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
					)
					' . Shop::addSqlAssociation('product', 'p') . '
					LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
					LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
					' . Product::sqlStock('p', 0) . '
					WHERE p.id_product = ' . (int) $id_product . '
					GROUP BY product_shop.id_product';
        $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
        if (!$row) {
            return false;
        }
        if (isset($row['id_product_attribute']) && $row['id_product_attribute']) {
            $row['id_product_attribute'] = $row['id_product_attribute'];
        }
        $p = Product::getProductProperties($id_lang, $row);
        $setting['product'] = $p;
        $output = array('type' => 'product', 'data' => $setting);
        return $output;
    }
 /**
  * AdminController::renderList() override
  * @see AdminController::renderList()
  */
 public function renderList()
 {
     // sets actions
     $this->addRowAction('details');
     $this->addRowAction('addstock');
     $this->addRowAction('removestock');
     if (count(Warehouse::getWarehouses()) > 1) {
         $this->addRowAction('transferstock');
     }
     // no link on list rows
     $this->list_no_link = true;
     // inits toolbar
     $this->toolbar_btn = array();
     // overrides query
     $this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations';
     $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pa.id_product = a.id_product)' . Shop::addSqlAssociation('product_attribute', 'pa', false);
     $this->_where = 'AND a.is_virtual = 0';
     $this->_group = 'GROUP BY a.id_product';
     // displays informations
     $this->displayInformation($this->l('This interface allows you to manage product stock and their variations.') . '<br />');
     $this->displayInformation($this->l('Through this interface, you can increase and decrease product stock for an given warehouse.'));
     $this->displayInformation($this->l('Furthermore, you can move product quantities between warehouses, or within one warehouse.') . '<br />');
     $this->displayInformation($this->l('If you want to increase quantities of multiple products at once, you can use the "Supply orders" page under the "Stock" menu.') . '<br />');
     $this->displayInformation($this->l('Finally, you need to provide the quantity that you\'ll be adding: "Usable for sale" means that this quantity will be available in your shop(s), otherwise it will be considered reserved (i.e. for other purposes).'));
     return parent::renderList();
 }
Esempio n. 12
0
 public static function getStores()
 {
     $stores = Db::getInstance()->executeS('
         SELECT s.id_store AS `id`, s.*
         FROM ' . _DB_PREFIX_ . 'store s
         ' . Shop::addSqlAssociation('store', 's') . '
         WHERE s.active = 1');
     return $stores;
 }
    /**
     * Permet de tester si un produit est typer ou pas
     * @param $iIdProduct
     * @param int $iIdNowProductType
     * @return bool
     */
    public static function isProductTyped($iIdProduct, $iIdNowProductType = null)
    {
        $sSQL = '
			SELECT 1
			FROM `' . _DB_PREFIX_ . 'now_product_type_product` pt
			' . Shop::addSqlAssociation('now_product_type_product', 'pt') . '
			WHERE pt.`id_product` = ' . (int) $iIdProduct . (!is_null($iIdNowProductType) ? ' AND pt.`id_now_product_type` = ' . (int) $iIdNowProductType : '');
        return (bool) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sSQL);
    }
Esempio n. 14
0
    /**
     * Get all features for a given language
     *
     * @param int $id_lang Language id
     * @return array Multiple arrays with feature's data
     */
    public static function getFeatures($id_lang, $with_shop = true)
    {
        return Db::getInstance()->executeS('
		SELECT DISTINCT f.id_feature, f.*, fl.*
		FROM `' . _DB_PREFIX_ . 'feature` f
		' . ($with_shop ? Shop::addSqlAssociation('feature', 'f') : '') . '
		LEFT JOIN `' . _DB_PREFIX_ . 'feature_lang` fl ON (f.`id_feature` = fl.`id_feature` AND fl.`id_lang` = ' . (int) $id_lang . ')
		ORDER BY f.`position` ASC');
    }
Esempio n. 15
0
    public function hookRightColumn($params)
    {
        $this->smarty->assign('store_img', Configuration::get('BLOCKSTORE_IMG'));
        $sql = 'SELECT COUNT(*)
				FROM ' . _DB_PREFIX_ . 'store s' . Shop::addSqlAssociation('store', 's');
        $total = Db::getInstance()->getValue($sql);
        if ($total > 0) {
            return $this->display(__FILE__, 'blockstore.tpl');
        }
    }
Esempio n. 16
0
    /**
     * Get the user's journey
     *
     * @param integer $id_category Category ID
     * @param string $path Path end
     * @param boolean $linkOntheLastItem Put or not a link on the current category
     * @param string [optionnal] $categoryType defined what type of categories is used (products or cms)
     */
    public static function getPath($id_category, $path = '', $link_on_the_item = false, $category_type = 'products', Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        $id_category = (int) $id_category;
        if ($id_category == 1) {
            return '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span class="navigation_end">' . $path . '</span></div>';
        }
        $pipe = Configuration::get('PS_NAVIGATION_PIPE');
        if (empty($pipe)) {
            $pipe = '>';
        }
        $full_path = '';
        if ($category_type === 'products') {
            $interval = Category::getInterval($id_category);
            $id_root_category = $context->shop->getCategory();
            $interval_root = Category::getInterval($id_root_category);
            if ($interval) {
                $sql = 'SELECT c.id_category, cl.name, cl.link_rewrite
						FROM ' . _DB_PREFIX_ . 'category c
						LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category' . Shop::addSqlRestrictionOnLang('cl') . ')
						' . Shop::addSqlAssociation('category', 'c') . '
						WHERE c.nleft <= ' . $interval['nleft'] . '
							AND c.nright >= ' . $interval['nright'] . '
							AND c.nleft >= ' . $interval_root['nleft'] . '
							AND c.nright <= ' . $interval_root['nright'] . '
							AND cl.id_lang = ' . (int) $context->language->id . '
							AND c.active = 1
							AND c.level_depth > ' . (int) $interval_root['level_depth'] . '
						ORDER BY c.level_depth ASC';
                $categories = Db::getInstance()->executeS($sql);
                $n = 1;
                $n_categories = count($categories);
                foreach ($categories as $category) {
                    $full_path .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">' . ($n < $n_categories || $link_on_the_item ? '<a href="' . Tools::safeOutput($context->link->getCategoryLink((int) $category['id_category'], $category['link_rewrite'])) . '" title="' . htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8') . '" itemprop="url">' : '') . '<span itemprop="title">' . htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8') . '</span>' . ($n < $n_categories || $link_on_the_item ? '</a>' : '') . '</div>' . ($n++ != $n_categories || !empty($path) ? '<span class="navigation-pipe">' . $pipe . '</span>' : '');
                }
                return $full_path . $path;
            }
        } else {
            if ($category_type === 'CMS') {
                $category = new CMSCategory($id_category, $context->language->id);
                if (!Validate::isLoadedObject($category)) {
                    die(Tools::displayError());
                }
                $category_link = $context->link->getCMSCategoryLink($category);
                if ($path != $category->name) {
                    $full_path .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . Tools::safeOutput($category_link) . '" itemprop="url"><span itemprop="title">' . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . '</span></a><span class="navigation-pipe">' . $pipe . '</span>' . $path;
                } else {
                    $full_path = ($link_on_the_item ? '<a href="' . Tools::safeOutput($category_link) . '" itemprop="url">' : '') . '<span itemprop="title">' . htmlentities($path, ENT_NOQUOTES, 'UTF-8') . '</span>' . ($link_on_the_item ? '</a>' : '');
                }
                return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, $category_type);
            }
        }
    }
    /**
     * Permet de récupérer le code_iso d'une langue à partir d'un nom de dossier
     * @param string $sFolderName
     * @return array
     */
    public static function getIsoCodeByFolderName($sFolderName)
    {
        $sSQL = '
			SELECT l.`iso_code`
			FROM `' . _DB_PREFIX_ . 'now_language_link` ll
			' . Shop::addSqlAssociation('now_language_link', 'll') . '
			INNER JOIN `' . _DB_PREFIX_ . 'lang` l ON (l.`id_lang` = ll.`id_lang`)
			WHERE ll.`folder_name` = "' . Tools::link_rewrite($sFolderName) . '"';
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sSQL);
        return $result;
    }
Esempio n. 18
0
    public function hookRightColumn($params)
    {
        $productsViewed = isset($params['cookie']->viewed) && !empty($params['cookie']->viewed) ? array_slice(array_reverse(explode(',', $params['cookie']->viewed)), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array();
        if (count($productsViewed)) {
            $defaultCover = Language::getIsoById($params['cookie']->id_lang) . '-default';
            $productIds = implode(',', array_map('intval', $productsViewed));
            $productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT MAX(image_shop.id_image) id_image, p.id_product, p.price, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite
			FROM ' . _DB_PREFIX_ . 'product p
			' . Shop::addSqlAssociation('product', 'p') . '
			LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (pl.id_product = p.id_product' . Shop::addSqlRestrictionOnLang('pl') . ')
			LEFT JOIN ' . _DB_PREFIX_ . 'image i ON (i.id_product = p.id_product)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
			LEFT JOIN ' . _DB_PREFIX_ . 'image_lang il ON (il.id_image = image_shop.id_image)
			LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = product_shop.id_category_default' . Shop::addSqlRestrictionOnLang('cl') . ')
			WHERE p.id_product IN (' . $productIds . ')
			AND pl.id_lang = ' . (int) $params['cookie']->id_lang . '
			AND cl.id_lang = ' . (int) $params['cookie']->id_lang . '
			GROUP BY product_shop.id_product');
            $productsImagesArray = array();
            foreach ($productsImages as $pi) {
                $productsImagesArray[$pi['id_product']] = $pi;
            }
            $productsViewedObj = array();
            foreach ($productsViewed as $productViewed) {
                $obj = (object) 'Product';
                if (!isset($productsImagesArray[$productViewed]) || !($obj->active = $productsImagesArray[$productViewed]['active'])) {
                    continue;
                } else {
                    $obj->id = (int) $productsImagesArray[$productViewed]['id_product'];
                    $obj->price = $productsImagesArray[$productViewed]['price'];
                    $obj->id_image = (int) $productsImagesArray[$productViewed]['id_image'];
                    $obj->cover = (int) $productsImagesArray[$productViewed]['id_product'] . '-' . (int) $productsImagesArray[$productViewed]['id_image'];
                    $obj->legend = $productsImagesArray[$productViewed]['legend'];
                    $obj->name = $productsImagesArray[$productViewed]['name'];
                    $obj->description_short = $productsImagesArray[$productViewed]['description_short'];
                    $obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite'];
                    $obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite'];
                    // $obj is not a real product so it cannot be used as argument for getProductLink()
                    $obj->product_link = $this->context->link->getProductLink($obj->id, $obj->link_rewrite, $obj->category_rewrite);
                    if (!isset($obj->cover) || !$productsImagesArray[$productViewed]['id_image']) {
                        $obj->cover = $defaultCover;
                        $obj->legend = '';
                    }
                    $productsViewedObj[] = $obj;
                }
            }
            if (!count($productsViewedObj)) {
                return;
            }
            $this->smarty->assign(array('productsViewedObj' => $productsViewedObj, 'mediumSize' => Image::getSize('medium')));
            return $this->display(__FILE__, 'blockviewed.tpl');
        }
        return;
    }
Esempio n. 19
0
    /**
     * Get all features for a given language
     *
     * @param integer $id_lang Language id
     * @return array Multiple arrays with feature's data
     * @static
     */
    public static function getFeatures($id_lang)
    {
        return Db::getInstance()->executeS('
			SELECT *
			FROM `' . _DB_PREFIX_ . 'feature` f
			' . Shop::addSqlAssociation('feature', 'f') . '
			LEFT JOIN `' . _DB_PREFIX_ . 'feature_lang` fl
				ON (f.`id_feature` = fl.`id_feature` AND fl.`id_lang` = ' . (int) $id_lang . ')
			ORDER BY f.`position` ASC
		');
    }
Esempio n. 20
0
    /**
     * 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);
    }
    public static function getProducts($product_ids, $p = 1, $n, $active = true, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        $id_lang = $context->language->id;
        $front = true;
        if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
            $front = false;
        }
        if ($p < 1) {
            $p = 1;
        }
        $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) AS quantity' . (Combination::isFeatureActive() ? ', IFNULL(product_attribute_shop.id_product_attribute, 0) AS id_product_attribute,
					product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity' : '') . ', 
						pl.`description`, pl.`description_short`, pl.`available_now`,
					pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, 
					pl.`meta_title`, pl.`name`, image_shop.`id_image` id_image,
					il.`legend` as legend, m.`name` AS manufacturer_name, cl.`name` AS category_default,
					DATEDIFF(product_shop.`date_add`, DATE_SUB("' . date('Y-m-d') . ' 00:00:00",
					INTERVAL ' . (int) Configuration::get('PS_NB_DAYS_NEW_PRODUCT') . ' DAY)) > 0 AS new, product_shop.price AS orderprice
				FROM `' . _DB_PREFIX_ . 'category_product` cp
				LEFT JOIN `' . _DB_PREFIX_ . 'product` p
					ON p.`id_product` = cp.`id_product`
				' . Shop::addSqlAssociation('product', 'p') . (Combination::isFeatureActive() ? ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_shop` product_attribute_shop
				ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 
					AND product_attribute_shop.id_shop=' . (int) $context->shop->id . ')' : '') . '
				' . Product::sqlStock('p', 0) . '
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl
					ON (product_shop.`id_category_default` = cl.`id_category`
					AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl
					ON (p.`id_product` = pl.`id_product`
					AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop
					ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $context->shop->id . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il
					ON (image_shop.`id_image` = il.`id_image`
					AND il.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m
					ON m.`id_manufacturer` = p.`id_manufacturer`
				WHERE product_shop.`id_shop` = ' . (int) $context->shop->id . ($active ? ' AND product_shop.`active` = 1' : '') . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ($product_ids ? ' AND p.id_product IN (0, ' . pSQL(implode(',', $product_ids)) . ')' : '') . ' GROUP BY cp.id_product';
        if ($n) {
            $sql .= ' LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n;
        }
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, true, false);
        if (!$result) {
            return array();
        }
        /* Modify SQL result */
        return Product::getProductsProperties($id_lang, $result);
    }
    public function __construct()
    {
        $this->table = 'currency';
        $this->className = 'Currency';
        $this->lang = false;
        $this->fields_list = array('id_currency' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Currency')), 'iso_code' => array('title' => $this->l('ISO code'), 'align' => 'center', 'width' => 80), 'iso_code_num' => array('title' => $this->l('ISO code number'), 'align' => 'center', 'width' => 120), 'sign' => array('title' => $this->l('Symbol'), 'width' => 20, 'align' => 'center', 'orderby' => false, 'search' => false), 'conversion_rate' => array('title' => $this->l('Conversion rate'), 'type' => 'float', 'align' => 'center', 'width' => 130, 'search' => false), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')), 'enableSelection' => array('text' => $this->l('Enable selection')), 'disableSelection' => array('text' => $this->l('Disable selection')));
        $this->fields_options = array('change' => array('title' => $this->l('Currency rates'), 'image' => '../img/admin/exchangesrate.gif', 'description' => $this->l('Use PrestaShop\'s webservice to update your currency exchange rates. Please use caution, rates are provided as-is.'), 'submit' => array('title' => $this->l('Update currency rates'), 'class' => 'button', 'name' => 'SubmitExchangesRates')), 'cron' => array('title' => $this->l('Automatically update currency rates'), 'image' => '../img/admin/tab-tools.gif', 'info' => $this->l('Use PrestaShop\'s webservice to update your currency exchange rates. Please use caution, rates are provided as-is. Place this URL in crontab or access it manually daily') . ':<br />
					<b>' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_) . '/cron_currency_rates.php?secure_key=' . md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME')) . '</b></p>'));
        parent::__construct();
        $this->_select .= 'currency_shop.conversion_rate conversion_rate';
        $this->_join .= Shop::addSqlAssociation('currency', 'a');
    }
Esempio n. 23
0
    private function getProducts($id_lang)
    {
        $sql = 'SELECT p.`id_product`, p.reference, pl.`name`, IFNULL(stock.quantity, 0) as quantity
				FROM `' . _DB_PREFIX_ . 'product` p
				' . Product::sqlStock('p', 0) . '
				LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON p.`id_product` = pl.`id_product`' . Shop::addSqlRestrictionOnLang('pl') . '
				' . Shop::addSqlAssociation('product', 'p') . '
				' . (Tools::getValue('id_category') ? 'LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON p.`id_product` = cp.`id_product`' : '') . '
				WHERE pl.`id_lang` = ' . (int) $id_lang . '
					' . (Tools::getValue('id_category') ? 'AND cp.id_category = ' . (int) Tools::getValue('id_category') : '') . '
				ORDER BY pl.`name`';
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
    }
Esempio n. 24
0
    public static function getGroups($id_lang, $id_shop = false)
    {
        $shop_criteria = '';
        if ($id_shop) {
            $shop_criteria = Shop::addSqlAssociation('group', 'g');
        }
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT DISTINCT g.`id_group`, g.`reduction`, g.`price_display_method`, gl.`name`
		FROM `' . _DB_PREFIX_ . 'group` g
		LEFT JOIN `' . _DB_PREFIX_ . 'group_lang` AS gl ON (g.`id_group` = gl.`id_group` AND gl.`id_lang` = ' . (int) $id_lang . ')
		' . $shop_criteria . '
		ORDER BY g.`id_group` ASC');
    }
 public function __construct()
 {
     $this->bootstrap = true;
     $this->table = 'currency';
     $this->className = 'Currency';
     $this->lang = false;
     $this->cldr = Tools::getCldr(Context::getContext());
     parent::__construct();
     $this->fields_list = array('name' => array('title' => $this->l('Currency'), 'orderby' => false, 'search' => false), 'sign' => array('title' => $this->l('Symbol'), 'width' => 20, 'align' => 'center', 'orderby' => false, 'search' => false, 'class' => 'fixed-width-xs'), 'iso_code' => array('title' => $this->l('ISO code'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'conversion_rate' => array('title' => $this->l('Exchange rate'), 'type' => 'float', 'align' => 'center', 'width' => 130, 'search' => false, 'filter_key' => 'currency_shop!conversion_rate'), 'active' => array('title' => $this->trans('Enabled', array(), 'Admin.Global'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'class' => 'fixed-width-sm'));
     $this->_select .= 'currency_shop.conversion_rate conversion_rate';
     $this->_join .= Shop::addSqlAssociation('currency', 'a');
     $this->_group .= 'GROUP BY a.id_currency';
 }
Esempio n. 26
0
    public function hookRightColumn($params)
    {
        if (!$this->isCached('blockstore.tpl', $this->getCacheId())) {
            $id_lang = $this->context->cart->id_lang;
            $this->smarty->assign(array('store_img' => Configuration::get('BLOCKSTORE_IMG'), 'store_text' => Configuration::get('BLOCKSTORE_TEXT', $id_lang)));
            $sql = 'SELECT COUNT(*)
					FROM ' . _DB_PREFIX_ . 'store s' . Shop::addSqlAssociation('store', 's');
            $total = Db::getInstance()->getValue($sql);
            if ($total <= 0) {
                return;
            }
        }
        return $this->display(__FILE__, 'blockstore.tpl', $this->getCacheId());
    }
Esempio n. 27
0
    /**
     * 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`
		');
    }
Esempio n. 28
0
    public function getData()
    {
        $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
        $date_between = $this->getDate();
        $array_date_between = explode(' AND ', $date_between);
        $this->query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name,
				ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold,
				IFNULL(stock.quantity, 0) as quantity,
				IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold,
				ROUND(IFNULL(IFNULL(SUM(od.product_quantity), 0) / (1 + LEAST(TO_DAYS(' . $array_date_between[1] . '), TO_DAYS(NOW())) - GREATEST(TO_DAYS(' . $array_date_between[0] . '), TO_DAYS(product_shop.date_add))), 0), 2) as averageQuantitySold,
				ROUND(IFNULL(SUM((od.product_price * od.product_quantity) / o.conversion_rate), 0), 2) AS totalPriceSold,
				(
					SELECT IFNULL(SUM(pv.counter), 0)
					FROM ' . _DB_PREFIX_ . 'page pa
					LEFT JOIN ' . _DB_PREFIX_ . 'page_viewed pv ON pa.id_page = pv.id_page
					LEFT JOIN ' . _DB_PREFIX_ . 'date_range dr ON pv.id_date_range = dr.id_date_range
					WHERE pa.id_object = p.id_product AND pa.id_page_type = ' . (int) Page::getPageTypeByName('product') . '
					AND dr.time_start BETWEEN ' . $date_between . '
					AND dr.time_end BETWEEN ' . $date_between . '
				) AS totalPageViewed,
				product_shop.active
				FROM ' . _DB_PREFIX_ . 'product p
				' . Shop::addSqlAssociation('product', 'p') . '
				LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = ' . (int) $this->getLang() . ' ' . Shop::addSqlRestrictionOnLang('pl') . ')
				LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON od.product_id = p.id_product
				LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON od.id_order = o.id_order
				' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
				' . Product::sqlStock('p', 0) . '
				WHERE o.valid = 1
				AND o.invoice_date BETWEEN ' . $date_between . '
				GROUP BY od.product_id';
        if (Validate::IsName($this->_sort)) {
            $this->query .= ' ORDER BY `' . bqSQL($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 ' . (int) $this->_start . ', ' . (int) $this->_limit;
        }
        $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query);
        foreach ($values as &$value) {
            $value['avgPriceSold'] = Tools::displayPrice($value['avgPriceSold'], $currency);
            $value['totalPriceSold'] = Tools::displayPrice($value['totalPriceSold'], $currency);
        }
        unset($value);
        $this->_values = $values;
        $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
    }
Esempio n. 29
0
    public static function listCms($id_lang = null, $id_block = false, $active = true)
    {
        if (empty($id_lang)) {
            $id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
        }
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT c.id_cms, l.meta_title
		FROM  ' . _DB_PREFIX_ . 'cms c
		JOIN ' . _DB_PREFIX_ . 'cms_lang l ON (c.id_cms = l.id_cms)
		' . Shop::addSqlAssociation('cms', 'c') . '
		' . ($id_block ? 'JOIN ' . _DB_PREFIX_ . 'block_cms b ON (c.id_cms = b.id_cms)' : '') . '
		WHERE l.id_lang = ' . (int) $id_lang . ($id_block ? ' AND b.id_block = ' . (int) $id_block : '') . ($active ? ' AND c.`active` = 1 ' : '') . '
		GROUP BY c.id_cms
		ORDER BY c.`position`');
    }
Esempio n. 30
0
    public function __construct()
    {
        $this->bootstrap = true;
        $this->table = 'currency';
        $this->className = 'Currency';
        $this->lang = false;
        $this->fields_list = array('id_currency' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'name' => array('title' => $this->l('Currency')), 'iso_code' => array('title' => $this->l('ISO code'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'iso_code_num' => array('title' => $this->l('ISO code number'), 'align' => 'center', 'class' => 'fixed-width-xs'), 'sign' => array('title' => $this->l('Symbol'), 'width' => 20, 'align' => 'center', 'orderby' => false, 'search' => false, 'class' => 'fixed-width-xs'), 'conversion_rate' => array('title' => $this->l('Exchange rate'), 'type' => 'float', 'align' => 'center', 'width' => 130, 'search' => false, 'filter_key' => 'currency_shop!conversion_rate'), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'class' => 'fixed-width-sm'));
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
        $this->fields_options = array('change' => array('title' => $this->l('Currency rates'), 'image' => '../img/admin/exchangesrate.gif', 'description' => $this->l('Use PrestaShop\'s webservice to update your currency\'s exchange rates. However, please use caution: rates are provided as-is.'), 'submit' => array('title' => $this->l('Update currency rates'), 'name' => 'SubmitExchangesRates')), 'cron' => array('title' => $this->l('Automatically update currency rates'), 'image' => '../img/admin/tab-tools.gif', 'info' => '<div class="alert alert-block"><p>' . $this->l('Use PrestaShop\'s webservice to update your currency exchange rates. However, please use caution: rates are provided as-is.') . '<br/>' . $this->l('You can place the following URL in your crontab file, or you can click it yourself regularly:') . '</p>
					<p><strong><a href="' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_) . '/cron_currency_rates.php?secure_key=' . md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME')) . '" onclick="return !window.open($(this).attr(\'href\'));">' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_) . '/cron_currency_rates.php?secure_key=' . md5(_COOKIE_KEY_ . Configuration::get('PS_SHOP_NAME')) . '</a></strong></p></div>'));
        parent::__construct();
        $this->_select .= 'currency_shop.conversion_rate conversion_rate';
        $this->_join .= Shop::addSqlAssociation('currency', 'a');
        $this->_group .= 'GROUP BY a.id_currency';
    }