/**
     * Get product accessories
     *
     * @param integer $id_lang Language id
     * @return array Product accessories
     */
    public static function getItems($iIdProduct, $id_lang, $active = true, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`,
					pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`,
					MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` as manufacturer_name, cl.`name` AS category_default,
					DATEDIFF(
						p.`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_ . 'now_ideas_or_tips`
				LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = `id_product_2`
				' . Shop::addSqlAssociation('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') . '
				)
				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_ . '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 . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (p.`id_manufacturer`= m.`id_manufacturer`)
				' . Product::sqlStock('p', 0) . '
				WHERE `id_product_1` = ' . (int) $iIdProduct . ($active ? ' AND product_shop.`active` = 1 AND product_shop.`visibility` != \'none\'' : '') . '
				GROUP BY product_shop.id_product';
        if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))) {
            return false;
        }
        foreach ($result as &$row) {
            $row['id_product_attribute'] = Product::getDefaultAttribute((int) $row['id_product']);
        }
        return Product::getProductsProperties($id_lang, $result);
    }
    public function getContent()
    {
        $html = '
		<h2>' . $this->l('Payment logo.') . '</h2>
		';
        if (Tools::isSubmit('submitConfiguration')) {
            if (Validate::isUnsignedInt(Tools::getValue('id_cms'))) {
                Configuration::updateValue('PS_PAYMENT_LOGO_CMS_ID', (int) Tools::getValue('id_cms'));
                $this->_clearCache('blockpaymentlogo.tpl');
                $html .= $this->displayConfirmation($this->l('The settings have been updated.'));
            }
        }
        $cmss = CMS::listCms($this->context->language->id);
        if (!count($cmss)) {
            $html .= $this->displayError($this->l('No CMS page is available.'));
        } else {
            $html .= '
			<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post">
				<fieldset>
					<legend><img src="' . $this->_path . '/logo.gif" alt="" /> ' . $this->l('Configure') . '</legend>
					<label>' . $this->l('Page CMS for link') . ':</label>
					<div class="margin-form">
						<select name="id_cms"><option value="0">(' . $this->l('Select a page') . ')</option>';
            foreach ($cmss as $cms) {
                $html .= '<option value="' . $cms['id_cms'] . '"' . (Configuration::get('PS_PAYMENT_LOGO_CMS_ID') == $cms['id_cms'] ? ' selected="selected"' : '') . '>' . $cms['meta_title'] . '</option>';
            }
            $html .= '</select>
					</div>
					<p class="center"><input class="button" type="submit" name="submitConfiguration" value="' . $this->l('Save settings') . '" /></p>
				</fieldset>
			</form>
			';
        }
        return $html;
    }
 public static function cleanRelatedForPost($id_simpleblog_post)
 {
     if (!Validate::isUnsignedInt($id_simpleblog_post)) {
         die(Tools::displayError());
     }
     return Db::getInstance()->delete('simpleblog_related_post', 'id_simpleblog_post = ' . (int) $id_simpleblog_post);
 }
Example #4
0
 private function _update_value($key, $value)
 {
     $interface = PS_CLI_Interface::getInterface();
     $validValue = true;
     switch ($key) {
         case 'PS_ONE_PHONE_AT_LEAST':
         case 'PS_REGISTRATION_PROCESS_TYPE':
         case 'PS_CART_FOLLOWING':
         case 'PS_CUSTOMER_CREATION_EMAIL':
         case 'PS_B2B_ENABLE':
             $validValue = Validate::isBool($value);
             break;
         case 'PS_PASSWD_TIME_FRONT':
             $validValue = Validate::isUnsignedInt($value);
             break;
         default:
             $interface->error("The configuration key {$key} is not handled by this plugin !");
             break;
     }
     if (!$validValue) {
         $interface->error("Invalid value '{$value}' for configuration key '{$key}'");
     }
     if (PS_CLI_Utils::update_configuration_value($key, $value)) {
         $interface->success("Successfully updated configuration key '{$key}'");
     } else {
         $interface->error("Could not update configuration key '{$key}'");
     }
 }
Example #5
0
 function getContent()
 {
     $output = '';
     if (Tools::isSubmit('submitBlockSuppliers')) {
         $text_list = (int) Tools::getValue('SUPPLIER_DISPLAY_TEXT');
         $text_nb = (int) Tools::getValue('SUPPLIER_DISPLAY_TEXT_NB');
         $form_list = (int) Tools::getValue('SUPPLIER_DISPLAY_FORM');
         if ($text_list and !Validate::isUnsignedInt($text_nb)) {
             $errors[] = $this->l('Invalid number of elements.');
         } elseif (!$text_list and !$form_list) {
             $errors[] = $this->l('Please activate at least one type of list.');
         } else {
             Configuration::updateValue('SUPPLIER_DISPLAY_TEXT', $text_list);
             Configuration::updateValue('SUPPLIER_DISPLAY_TEXT_NB', $text_nb);
             Configuration::updateValue('SUPPLIER_DISPLAY_FORM', $form_list);
             $this->_clearCache('blocksupplier.tpl');
         }
         if (isset($errors) and sizeof($errors)) {
             $output .= $this->displayError(implode('<br />', $errors));
         } else {
             $output .= $this->displayConfirmation($this->l('Settings updated.'));
         }
     }
     return $output . $this->renderForm();
 }
Example #6
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;
    }
Example #7
0
    public static function getBestSales($id_lang, $page_number = 0, $nb_products = 10, $order_by = null, $order_way = null)
    {
        if ($page_number < 0) {
            $page_number = 0;
        }
        if ($nb_products < 1) {
            $nb_products = 10;
        }
        $final_order_by = $order_by;
        if (empty($order_by) || $order_by == 'position' || ($order_by = 'price')) {
            $order_by = 'sales';
        }
        if (empty($order_way) || $order_by == 'sales') {
            $order_way = 'DESC';
        }
        $groups = FrontController::getCurrentCustomerGroups();
        $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
        $interval = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20;
        $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
					pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
					pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
					m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer,
					MAX(image_shop.`id_image`) id_image, il.`legend`,
					ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`,
					DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
					INTERVAL ' . $interval . ' DAY)) > 0 AS new
				FROM `' . _DB_PREFIX_ . 'product_sale` ps
				LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON ps.`id_product` = p.`id_product`
				' . Shop::addSqlAssociation('product', 'p', false) . '
				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` 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 . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
				LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`)
					AND tr.`id_country` = ' . (int) Context::getContext()->country->id . '
					AND tr.`id_state` = 0
				LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)
				' . Product::sqlStock('p') . '
				WHERE product_shop.`active` = 1
					AND p.`visibility` != \'none\'
					AND p.`id_product` IN (
						SELECT cp.`id_product`
						FROM `' . _DB_PREFIX_ . 'category_group` cg
						LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
						WHERE cg.`id_group` ' . $sql_groups . '
					)
				GROUP BY product_shop.id_product
				ORDER BY `' . pSQL($order_by) . '` ' . pSQL($order_way) . '
				LIMIT ' . (int) ($page_number * $nb_products) . ', ' . (int) $nb_products;
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
        if ($final_order_by == 'price') {
            Tools::orderbyPrice($result, $order_way);
        }
        if (!$result) {
            return false;
        }
        return Product::getProductsProperties($id_lang, $result);
    }
    public function getContent()
    {
        global $cookie;
        $html = '
		<h2>' . $this->l('Payment logo') . '</h2>
		';
        if (Tools::isSubmit('submitConfiguration')) {
            if (Validate::isUnsignedInt(Tools::getValue('id_cms'))) {
                Configuration::updateValue('PS_PAYMENT_LOGO_CMS_ID', intval(Tools::getValue('id_cms')));
                $html .= $this->displayConfirmation($this->l('Settings are updated'));
            }
        }
        $cmss = CMS::listCms(intval($cookie->id_lang));
        if (!sizeof($cmss)) {
            $html .= $this->displayError($this->l('No CMS page is available'));
        } else {
            $html .= '
			<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
				<fieldset>
					<legend><img src="' . $this->_path . '/logo.gif" alt="" /> ' . $this->l('Configure') . '</legend>
					<label>' . $this->l('Page CMS for link') . ':</label>
					<div class="margin-form">
						<select name="id_cms">';
            foreach ($cmss as $cms) {
                $html .= '<option value="' . $cms['id_cms'] . '"' . (Configuration::get('PS_PAYMENT_LOGO_CMS_ID') == $cms['id_cms'] ? ' selected="selected"' : '') . '>' . $cms['meta_title'] . '</option>';
            }
            $html .= '</select>
					</div>
					<p class="center"><input class="button" type="submit" name="submitConfiguration" value="' . $this->l('Save settings') . '" /></p>
				</fieldset>
			</form>
			';
        }
        return $html;
    }
 public function hasProductDownload($cart)
 {
     foreach ($cart->getProducts() as $product) {
         $pd = ProductDownload::getIdFromIdProduct((int) $product['id_product']);
         if ($pd and Validate::isUnsignedInt($pd)) {
             return true;
         }
     }
     return false;
 }
Example #10
0
 public static function getMailAlerts($id_customer, $id_lang, Shop $shop = null)
 {
     if (!Validate::isUnsignedId($id_customer) || !Validate::isUnsignedId($id_lang)) {
         die(Tools::displayError());
     }
     if (!$shop) {
         $shop = Context::getContext()->shop;
     }
     $customer = new Customer($id_customer);
     $products = MailAlert::getProducts($customer, $id_lang);
     $products_number = count($products);
     if (empty($products) === true || !$products_number) {
         return array();
     }
     for ($i = 0; $i < $products_number; ++$i) {
         $obj = new Product((int) $products[$i]['id_product'], false, (int) $id_lang);
         if (!Validate::isLoadedObject($obj)) {
             continue;
         }
         if (isset($products[$i]['id_product_attribute']) && Validate::isUnsignedInt($products[$i]['id_product_attribute'])) {
             $attributes = self::getProductAttributeCombination($products[$i]['id_product_attribute'], $id_lang);
             $products[$i]['attributes_small'] = '';
             if ($attributes) {
                 foreach ($attributes as $k => $row) {
                     $products[$i]['attributes_small'] .= $row['attribute_name'] . ', ';
                 }
             }
             $products[$i]['attributes_small'] = rtrim($products[$i]['attributes_small'], ', ');
             $products[$i]['id_shop'] = $shop->id;
             /* Get cover */
             $attrgrps = $obj->getAttributesGroups((int) $id_lang);
             foreach ($attrgrps as $attrgrp) {
                 if ($attrgrp['id_product_attribute'] == (int) $products[$i]['id_product_attribute'] && ($images = Product::_getAttributeImageAssociations((int) $attrgrp['id_product_attribute']))) {
                     $products[$i]['cover'] = $obj->id . '-' . array_pop($images);
                     break;
                 }
             }
         }
         if (!isset($products[$i]['cover']) || !$products[$i]['cover']) {
             $images = $obj->getImages((int) $id_lang);
             foreach ($images as $k => $image) {
                 if ($image['cover']) {
                     $products[$i]['cover'] = $obj->id . '-' . $image['id_image'];
                     break;
                 }
             }
         }
         if (!isset($products[$i]['cover'])) {
             $products[$i]['cover'] = Language::getIsoById($id_lang) . '-default';
         }
         $products[$i]['link'] = $obj->getLink();
         $products[$i]['link_rewrite'] = $obj->link_rewrite;
     }
     return $products;
 }
Example #11
0
 public static function getSlugById($id_simpleblog_post_type)
 {
     if (!Validate::isUnsignedInt($id_simpleblog_post_type)) {
         return Tools::displayError('getSlugByID - invalid ID');
     }
     $sql = new DbQuery();
     $sql->select('slug');
     $sql->from('simpleblog_post_type', 'sbpt');
     $sql->where('id_simpleblog_post_type = ' . (int) $id_simpleblog_post_type);
     return Db::getInstance()->getValue($sql);
 }
Example #12
0
 public static function getAllById($id_simpleblog_post)
 {
     if (!Validate::isUnsignedInt($id_simpleblog_post)) {
         return Tools::displayError('getAllById - invalid ID');
     }
     $sql = new DbQuery();
     $sql->select('*');
     $sql->from('simpleblog_post_image', 'sbpi');
     $sql->where('id_simpleblog_post = ' . (int) $id_simpleblog_post);
     $sql->orderBy('position ASC');
     return Db::getInstance()->executeS($sql);
 }
Example #13
0
    public static function getBestSales($id_lang, $pageNumber = 0, $nbProducts = 10, $orderBy = null, $orderWay = null)
    {
        if ($pageNumber < 0) {
            $pageNumber = 0;
        }
        if ($nbProducts < 1) {
            $nbProducts = 10;
        }
        if (empty($orderBy) || $orderBy == 'position') {
            $orderBy = 'sales';
        }
        if (empty($orderWay)) {
            $orderWay = 'DESC';
        }
        $groups = FrontController::getCurrentCustomerGroups();
        $sqlGroups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT p.*,
			pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, m.`name` manufacturer_name, p.`id_manufacturer` as id_manufacturer,
			i.`id_image`, il.`legend`,
			ps.`quantity` sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`,
			DATEDIFF(p.`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 new
		FROM `' . _DB_PREFIX_ . 'product_sale` ps
		LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON ps.`id_product` = p.`id_product`
		LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . ')
		LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`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`)
		LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
		                                           AND tr.`id_country` = ' . (int) Country::getDefaultCountryId() . '
	                                           	   AND tr.`id_state` = 0)
	    LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)
		WHERE p.`active` = 1
		AND p.`id_product` IN (
			SELECT cp.`id_product`
			FROM `' . _DB_PREFIX_ . 'category_group` cg
			LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
			WHERE cg.`id_group` ' . $sqlGroups . '
		)
		ORDER BY ' . (isset($orderByPrefix) ? $orderByPrefix . '.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . '
		LIMIT ' . (int) ($pageNumber * $nbProducts) . ', ' . (int) $nbProducts);
        if ($orderBy == 'price') {
            Tools::orderbyPrice($result, $orderWay);
        }
        if (!$result) {
            return false;
        }
        return Product::getProductsProperties($id_lang, $result);
    }
Example #14
0
 private function addMissingProductFields(array $rawProduct)
 {
     $id_shop = (int) $this->searchContext->getIdShop();
     $id_lang = (int) $this->searchContext->getIdLang();
     $id_product = (int) $rawProduct['id_product'];
     $prefix = _DB_PREFIX_;
     $nb_days_new_product = (int) Configuration::get('PS_NB_DAYS_NEW_PRODUCT');
     if (!Validate::isUnsignedInt($nb_days_new_product)) {
         $nb_days_new_product = 20;
     }
     $now = date('Y-m-d') . ' 00:00:00';
     $sql = "SELECT\n                    p.*,\n                    pl.*,\n                    (DATEDIFF(\n\t\t\t\tp.`date_add`,\n\t\t\t\tDATE_SUB(\n\t\t\t\t\t'{$now}',\n\t\t\t\t\tINTERVAL {$nb_days_new_product} DAY\n\t\t\t\t)\n\t\t\t) > 0) as new\n                FROM {$prefix}product p\n                INNER JOIN {$prefix}product_lang pl\n                    ON pl.id_product = p.id_product\n                    AND pl.id_shop = {$id_shop}\n                    AND pl.id_lang = {$id_lang}\n                    AND p.id_product = {$id_product}";
     $rows = Db::getInstance()->executeS($sql);
     return array_merge($rawProduct, $rows[0]);
 }
Example #15
0
 public function hookPayment($params)
 {
     if (!$this->active) {
         return;
     }
     global $smarty;
     // Check if cart has product download
     foreach ($params['cart']->getProducts() as $product) {
         $pd = ProductDownload::getIdFromIdProduct((int) $product['id_product']);
         if ($pd and Validate::isUnsignedInt($pd)) {
             return false;
         }
     }
     $smarty->assign(array('this_path' => $this->_path, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/'));
     return $this->display(__FILE__, 'payment.tpl');
 }
Example #16
0
 public function hookPayment($params)
 {
     if (!$this->active) {
         return;
     }
     global $smarty;
     // Check if cart has product download
     foreach ($params['cart']->getProducts() as $product) {
         $pd = ProductDownload::getIdFromIdProduct(intval($product['id_product']));
         if ($pd and Validate::isUnsignedInt($pd)) {
             return false;
         }
     }
     $smarty->assign(array('this_path' => $this->_path, 'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/'));
     return $this->display(__FILE__, 'payment.tpl');
 }
Example #17
0
 public function getContent()
 {
     $html = '';
     if (Tools::isSubmit('submitConfiguration')) {
         if (Validate::isUnsignedInt(Tools::getValue('PS_PAYMENT_LOGO_CMS_ID'))) {
             Configuration::updateValue('PS_PAYMENT_LOGO_CMS_ID', (int) Tools::getValue('PS_PAYMENT_LOGO_CMS_ID'));
             $this->_clearCache('blockpaymentlogo.tpl');
             $html .= $this->displayConfirmation($this->l('The settings have been updated.'));
         }
     }
     $cmss = CMS::listCms($this->context->language->id);
     if (!count($cmss)) {
         $html .= $this->displayError($this->l('No CMS page is available.'));
     } else {
         $html .= $this->renderForm();
     }
     return $html;
 }
Example #18
0
        /**
         * Get data source: 
         */
        function getProducts($where = '', $limiStart = 0, $limit = 10, $order = '')
        {
            global $cookie, $link;
            $id_lang = intval($cookie->id_lang);
            $context = Context::getContext();
            $id_country = (int) $context->country->id;
            $front = true;
            if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
                $front = false;
            }
            $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`id_product_attribute`, 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`, i.`id_image`,
					il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default,
					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,
					(product_shop.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) 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') . '
				LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product`)
				' . Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') . '
				' . Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) . '
				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` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
				LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = ' . (int) $context->country->id . '
					AND tr.`id_state` = 0
					AND tr.`zipcode_from` = 0)
				LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)
				LEFT JOIN `' . _DB_PREFIX_ . 'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
				
				LEFT JOIN `' . _DB_PREFIX_ . 'product_sale` ps ON ps.`id_product` = p.`id_product`
				LEFT JOIN `' . _DB_PREFIX_ . 'feature_product` fp ON fp.`id_product` = p.`id_product`
				
				WHERE product_shop.`id_shop` = ' . (int) $context->shop->id . '
				AND ((product_attribute_shop.id_product_attribute IS NOT NULL OR pa.id_product_attribute IS NULL) 
					OR (product_attribute_shop.id_product_attribute IS NULL AND pa.default_on=1))
					AND product_shop.`active` = 1' . $where . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . ' ORDER BY ' . $order . ' LIMIT ' . $limiStart . ',' . $limit;
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            return Product::getProductsProperties($id_lang, $result);
        }
Example #19
0
 public static function getContentFromId($id_cms, $id_lang = null)
 {
     /*
      * EU-Legal
      * own function: returns content from CMS ID
      */
     if (!Validate::isUnsignedInt($id_cms)) {
         return null;
     }
     if (empty($id_lang)) {
         $id_lang = Context::getContext()->cookie->id_lang;
     }
     $cms = new CMS((int) $id_cms, (int) $id_lang);
     if (Validate::isLoadedObject($cms)) {
         return $cms->content;
     } else {
         return '';
     }
 }
 public function getContent()
 {
     $output = null;
     if (Tools::isSubmit('submit' . $this->name)) {
         $dadata_token = strval(Tools::getValue('DADATA_SUGGESTIONS_TOKEN'));
         $dadata_count = strval(Tools::getValue('DADATA_SUGGESTIONS_COUNT'));
         $dadata_trig_sel_spc = strval(Tools::getValue('DADATA_SUGGESTIONS_TRIG_SEL_SPC'));
         $dadata_url = strval(Tools::getValue('DADATA_SUGGESTIONS_URL'));
         $dadata_fio = strval(Tools::getValue('DADATA_SUGGESTIONS_FIO'));
         $dadata_address = strval(Tools::getValue('DADATA_SUGGESTIONS_ADDRESS'));
         $dadata_region_field = strval(Tools::getValue('DADATA_SUGGESTIONS_REGION_FIELD'));
         if (!$dadata_token || empty($dadata_token) || !Validate::isSha1($dadata_token)) {
             $output .= $this->displayError($this->l('Invalid') . ' ' . $this->l('DaData.ru API Token'));
         } elseif (!Validate::isBool($dadata_trig_sel_spc)) {
             $output .= $this->displayError($this->l('Invalid auto correct selection'));
         } elseif (!Validate::isBool($dadata_fio)) {
             $output .= $this->displayError($this->l('Invalid hide selection'));
         } elseif (!Validate::isBool($dadata_address)) {
             $output .= $this->displayError($this->l('Invalid hide selection'));
         } elseif (!array_key_exists($dadata_url, $this->available_urls)) {
             $output .= $this->displayError($this->l('Invalid url selection'));
         } elseif (!in_array($dadata_region_field, $this->valid_fields)) {
             $output .= $this->displayError($this->l('Invalid field name'));
         } elseif (!$dadata_count || empty($dadata_count) || !Validate::isUnsignedInt($dadata_count) || $dadata_count == '0') {
             $output .= $this->displayError($this->l('Invalid') . ' ' . $this->l('Maximum suggestions count in list'));
         } else {
             Configuration::updateValue('DADATA_SUGGESTIONS_TOKEN', $dadata_token);
             Configuration::updateValue('DADATA_SUGGESTIONS_COUNT', $dadata_count);
             Configuration::updateValue('DADATA_SUGGESTIONS_TRIG_SEL_SPC', $dadata_trig_sel_spc);
             Configuration::updateValue('DADATA_SUGGESTIONS_URL', $dadata_url);
             Configuration::updateValue('DADATA_SUGGESTIONS_FIO', $dadata_fio);
             Configuration::updateValue('DADATA_SUGGESTIONS_ADDRESS', $dadata_address);
             Configuration::updateValue('DADATA_SUGGESTIONS_REGION_FIELD', $dadata_region_field);
             $output .= $this->displayConfirmation($this->l('Settings updated'));
         }
     }
     return $output . $this->displayForm();
 }
Example #21
0
 function getContent()
 {
     $output = '<h2>' . $this->displayName . '</h2>';
     if (Tools::isSubmit('submitBlockSuppliers')) {
         $text_list = intval(Tools::getValue('text_list'));
         $text_nb = intval(Tools::getValue('text_nb'));
         $form_list = intval(Tools::getValue('form_list'));
         if ($text_list and !Validate::isUnsignedInt($text_nb)) {
             $errors[] = $this->l('Invalid number of elements');
         } elseif (!$text_list and !$form_list) {
             $errors[] = $this->l('Please activate at least one system list');
         } else {
             Configuration::updateValue('SUPPLIER_DISPLAY_TEXT', $text_list);
             Configuration::updateValue('SUPPLIER_DISPLAY_TEXT_NB', $text_nb);
             Configuration::updateValue('SUPPLIER_DISPLAY_FORM', $form_list);
         }
         if (isset($errors) and sizeof($errors)) {
             $output .= $this->displayError(implode('<br />', $errors));
         } else {
             $output .= $this->displayConfirmation($this->l('Settings updated'));
         }
     }
     return $output . $this->displayForm();
 }
Example #22
0
 private function _update_configuration_key($key, $value)
 {
     $interface = PS_CLI_Interface::getInterface();
     $validValue = true;
     switch ($key) {
         case 'PS_PASSWD_TIME_BACK':
             $validValue = Validate::isUnsignedInt($value);
             break;
         case 'PS_BO_ALLOW_EMPLOYEE_FORM_LANG':
             $validValue = Validate::isBool($value);
             break;
         default:
             $interface->error("This configuration key is not handled by this plugin");
             break;
     }
     if (!$validValue) {
         $interface->error("'{$value}' is not a valid value for configuration key '{$key}'");
     }
     if (PS_CLI_Utils::update_configuration_value($key, $value)) {
         $interface->success("Configuration key '{$key}' successfully updated");
     } else {
         $interface->error("Could not update configuration key '{$key}'");
     }
 }
 public function setSize($width, $height)
 {
     if (Validate::isUnsignedInt($width) and Validate::isUnsignedInt($height)) {
         $this->_graph->setSize($width, $height);
     }
 }
Example #24
0
    public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        if (!Module::isInstalled('agilemultipleseller') and !Module::isInstalled('agilesellerlistoptions')) {
            return parent::searchTag($id_lang, $expr, $pageNumber, $pageSize, $orderBy, $orderWay, $ajax, $useCookie, $context);
        }
        $agile_sql_parts = AgileSellerManager::getAdditionalSqlForProducts("p");
        if ($useCookie) {
            $id_customer = (int) $context->customer->id;
        } else {
            $id_customer = 0;
        }
        if (!is_numeric($pageNumber) || !is_numeric($pageSize) || !Validate::isBool($count) || !Validate::isValidSearch($tag) || $orderBy && !$orderWay || $orderBy && !Validate::isOrderBy($orderBy) || $orderWay && !Validate::isOrderBy($orderWay)) {
            return false;
        }
        if ($pageNumber < 1) {
            $pageNumber = 1;
        }
        if ($pageSize < 1) {
            $pageSize = 10;
        }
        $id = Context::getContext()->shop->id;
        $id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT');
        if ($count) {
            $sql = 'SELECT COUNT(DISTINCT pt.`id_product`) nb
					FROM `' . _DB_PREFIX_ . 'product` p
		            ' . $agile_sql_parts['joins'] . '
					' . Shop::addSqlAssociation('product', 'p') . '
					LEFT JOIN `' . _DB_PREFIX_ . 'product_tag` pt ON (p.`id_product` = pt.`id_product`)
					LEFT JOIN `' . _DB_PREFIX_ . 'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = ' . (int) $id_lang . ')
					LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = p.`id_product`)
					LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')
					LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = cp.`id_category`)
					WHERE product_shop.`active` = 1
						' . $agile_sql_parts['wheres'] . '
						AND cs.`id_shop` = ' . (int) Context::getContext()->shop->id . '
						AND cg.`id_group` ' . (!$id_customer ? '= ' . (int) Configuration::get('PS_UNIDENTIFIED_GROUP') : 'IN (
							SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group
							WHERE id_customer = ' . (int) $id_customer . ')') . '
						AND t.`name` LIKE \'%' . pSQL($tag) . '%\'';
            return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
        }
        $sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`,
					MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` manufacturer_name, 1 position,
					DATEDIFF(
						p.`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 new
	            ' . $agile_sql_parts['selects'] . '
				FROM `' . _DB_PREFIX_ . 'product` p
	            ' . $agile_sql_parts['joins'] . '
				INNER 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', false) . '
				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 . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
				LEFT JOIN `' . _DB_PREFIX_ . 'product_tag` pt ON (p.`id_product` = pt.`id_product`)
				LEFT JOIN `' . _DB_PREFIX_ . 'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = p.`id_product`)
				LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = cp.`id_category`)
				LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cg.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')
				' . Product::sqlStock('p', 0) . '
				WHERE product_shop.`active` = 1
					' . $agile_sql_parts['wheres'] . '
					AND cs.`id_shop` = ' . (int) Context::getContext()->shop->id . '
					AND cg.`id_group` ' . (!$id_customer ? '= ' . (int) Configuration::get('PS_UNIDENTIFIED_GROUP') : 'IN (
						SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group
						WHERE id_customer = ' . (int) $id_customer . ')') . '
					AND t.`name` LIKE \'%' . pSQL($tag) . '%\'
					GROUP BY product_shop.id_product
				ORDER BY position DESC' . ($orderBy ? ', ' . $orderBy : '') . ($orderWay ? ' ' . $orderWay : '') . '
				LIMIT ' . (int) (($pageNumber - 1) * $pageSize) . ',' . (int) $pageSize;
        if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))) {
            return false;
        }
        $results = Product::getProductsProperties((int) $id_lang, $result);
        $results = AgileSellerManager::prepareSellerRattingInfo($results);
        return $results;
    }
Example #25
0
    /**
     * Get Wishlist products by Customer ID
     *
     * @return array Results
     */
    public static function getProductByIdCustomer($id_wishlist, $id_customer, $id_lang, $id_product = null, $quantity = false)
    {
        if (!Validate::isUnsignedId($id_customer) or !Validate::isUnsignedId($id_lang) or !Validate::isUnsignedId($id_wishlist)) {
            die(Tools::displayError());
        }
        $products = Db::getInstance()->ExecuteS('
		SELECT wp.`id_product`, wp.`quantity`, p.`quantity` AS product_quantity, pl.`name`, wp.`id_product_attribute`, wp.`priority`, pl.link_rewrite, cl.link_rewrite AS category_rewrite
	  FROM `' . _DB_PREFIX_ . 'wishlist_product` wp
		JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = wp.`id_product`
		JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON pl.`id_product` = wp.`id_product`
		JOIN `' . _DB_PREFIX_ . 'wishlist` w ON w.`id_wishlist` = wp.`id_wishlist`
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON cl.`id_category` = p.`id_category_default` AND cl.id_lang=' . (int) $id_lang . '
		WHERE w.`id_customer` = ' . (int) $id_customer . '
		AND pl.`id_lang` = ' . (int) $id_lang . '
		AND wp.`id_wishlist` = ' . (int) $id_wishlist . (empty($id_product) === false ? ' AND wp.`id_product` = ' . (int) $id_product : '') . ($quantity == true ? ' AND wp.`quantity` != 0' : ''));
        if (empty($products) === true or !sizeof($products)) {
            return array();
        }
        for ($i = 0; $i < sizeof($products); ++$i) {
            if (isset($products[$i]['id_product_attribute']) and Validate::isUnsignedInt($products[$i]['id_product_attribute'])) {
                $result = Db::getInstance()->ExecuteS('
				SELECT al.`name` AS attribute_name, pa.`quantity` AS "attribute_quantity"
				  FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac
				LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON (a.`id_attribute` = pac.`id_attribute`)
				LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`)
				LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = ' . (int) $id_lang . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
				WHERE pac.`id_product_attribute` = ' . (int) $products[$i]['id_product_attribute']);
                $products[$i]['attributes_small'] = '';
                if ($result) {
                    foreach ($result as $k => $row) {
                        $products[$i]['attributes_small'] .= $row['attribute_name'] . ', ';
                    }
                }
                $products[$i]['attributes_small'] = rtrim($products[$i]['attributes_small'], ', ');
                if (isset($result[0])) {
                    $products[$i]['attribute_quantity'] = $result[0]['attribute_quantity'];
                }
            } else {
                $products[$i]['attribute_quantity'] = $products[$i]['product_quantity'];
            }
        }
        return $products;
    }
 public function postProcess()
 {
     $this->context = Context::getContext();
     $this->query = trim(Tools::getValue('bo_query'));
     $searchType = (int) Tools::getValue('bo_search_type');
     /* Handle empty search field */
     if (!empty($this->query)) {
         if (!$searchType && strlen($this->query) > 1) {
             $this->searchFeatures();
         }
         /* Product research */
         if (!$searchType || $searchType == 1) {
             /* Handle product ID */
             if ($searchType == 1 && (int) $this->query && Validate::isUnsignedInt((int) $this->query)) {
                 if (($product = new Product($this->query)) && Validate::isLoadedObject($product)) {
                     Tools::redirectAdmin('index.php?tab=AdminProducts&id_product=' . (int) $product->id . '&addproduct' . '&token=' . Tools::getAdminTokenLite('AdminProducts'));
                 }
             }
             /* Normal catalog search */
             $this->searchCatalog();
         }
         /* Customer */
         if (!$searchType || $searchType == 2 || $searchType == 6) {
             if (!$searchType || $searchType == 2) {
                 /* Handle customer ID */
                 if ($searchType && (int) $this->query && Validate::isUnsignedInt((int) $this->query)) {
                     if (($customer = new Customer($this->query)) && Validate::isLoadedObject($customer)) {
                         Tools::redirectAdmin('index.php?tab=AdminCustomers&id_customer=' . (int) $customer->id . '&viewcustomer' . '&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id));
                     }
                 }
                 /* Normal customer search */
                 $this->searchCustomer();
             }
             if ($searchType == 6) {
                 $this->searchIP();
             }
         }
         /* Order */
         if (!$searchType || $searchType == 3) {
             if (Validate::isUnsignedInt(trim($this->query)) && (int) $this->query && ($order = new Order((int) $this->query)) && Validate::isLoadedObject($order)) {
                 if ($searchType == 3) {
                     Tools::redirectAdmin('index.php?tab=AdminOrders&id_order=' . (int) $order->id . '&vieworder' . '&token=' . Tools::getAdminTokenLite('AdminOrders'));
                 } else {
                     $row = get_object_vars($order);
                     $row['id_order'] = $row['id'];
                     $customer = $order->getCustomer();
                     $row['customer'] = $customer->firstname . ' ' . $customer->lastname;
                     $order_state = $order->getCurrentOrderState();
                     $row['osname'] = $order_state->name[$this->context->language->id];
                     $this->_list['orders'] = array($row);
                 }
             } else {
                 $orders = Order::getByReference($this->query);
                 $nb_orders = count($orders);
                 if ($nb_orders == 1 && $searchType == 3) {
                     Tools::redirectAdmin('index.php?tab=AdminOrders&id_order=' . (int) $orders[0]->id . '&vieworder' . '&token=' . Tools::getAdminTokenLite('AdminOrders'));
                 } elseif ($nb_orders) {
                     $this->_list['orders'] = array();
                     foreach ($orders as $order) {
                         $row = get_object_vars($order);
                         $row['id_order'] = $row['id'];
                         $customer = $order->getCustomer();
                         $row['customer'] = $customer->firstname . ' ' . $customer->lastname;
                         $order_state = $order->getCurrentOrderState();
                         $row['osname'] = $order_state->name[$this->context->language->id];
                         $this->_list['orders'][] = $row;
                     }
                 } elseif ($searchType == 3) {
                     $this->errors[] = Tools::displayError('No order was found with this ID:') . ' ' . Tools::htmlentitiesUTF8($this->query);
                 }
             }
         }
         /* Invoices */
         if ($searchType == 4) {
             if (Validate::isOrderInvoiceNumber($this->query) && ($invoice = OrderInvoice::getInvoiceByNumber($this->query))) {
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf') . '&submitAction=generateInvoicePDF&id_order=' . (int) $invoice->id_order);
             }
             $this->errors[] = Tools::displayError('No invoice was found with this ID:') . ' ' . Tools::htmlentitiesUTF8($this->query);
         }
         /* Cart */
         if ($searchType == 5) {
             if ((int) $this->query && Validate::isUnsignedInt((int) $this->query) && ($cart = new Cart($this->query)) && Validate::isLoadedObject($cart)) {
                 Tools::redirectAdmin('index.php?tab=AdminCarts&id_cart=' . (int) $cart->id . '&viewcart' . '&token=' . Tools::getAdminToken('AdminCarts' . (int) Tab::getIdFromClassName('AdminCarts') . (int) $this->context->employee->id));
             }
             $this->errors[] = Tools::displayError('No cart was found with this ID:') . ' ' . Tools::htmlentitiesUTF8($this->query);
         }
         /* IP */
         // 6 - but it is included in the customer block
         /* Module search */
         if (!$searchType || $searchType == 7) {
             /* Handle module name */
             if ($searchType == 7 && Validate::isModuleName($this->query) and ($module = Module::getInstanceByName($this->query)) && Validate::isLoadedObject($module)) {
                 Tools::redirectAdmin('index.php?tab=AdminModules&tab_module=' . $module->tab . '&module_name=' . $module->name . '&anchor=' . ucfirst($module->name) . '&token=' . Tools::getAdminTokenLite('AdminModules'));
             }
             /* Normal catalog search */
             $this->searchModule();
         }
     }
     $this->display = 'view';
 }
Example #27
0
 protected function doEditProductValidation(OrderDetail $order_detail, Order $order, OrderInvoice $order_invoice = null)
 {
     if (!Validate::isLoadedObject($order_detail)) {
         die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The Order Detail object could not be loaded.'))));
     }
     if (!empty($order_invoice) && !Validate::isLoadedObject($order_invoice)) {
         die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The invoice object cannot be loaded.'))));
     }
     if (!Validate::isLoadedObject($order)) {
         die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The order object cannot be loaded.'))));
     }
     if ($order_detail->id_order != $order->id) {
         die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('You cannot edit the order detail for this order.'))));
     }
     // We can't edit a delivered order
     if ($order->hasBeenDelivered()) {
         die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('You cannot edit a delivered order.'))));
     }
     if (!empty($order_invoice) && $order_invoice->id_order != Tools::getValue('id_order')) {
         die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('You cannot use this invoice for the order'))));
     }
     // Clean price
     $product_price_tax_incl = str_replace(',', '.', Tools::getValue('product_price_tax_incl'));
     $product_price_tax_excl = str_replace(',', '.', Tools::getValue('product_price_tax_excl'));
     if (!Validate::isPrice($product_price_tax_incl) || !Validate::isPrice($product_price_tax_excl)) {
         die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('Invalid price'))));
     }
     if (!is_array(Tools::getValue('product_quantity')) && !Validate::isUnsignedInt(Tools::getValue('product_quantity'))) {
         die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('Invalid quantity'))));
     } elseif (is_array(Tools::getValue('product_quantity'))) {
         foreach (Tools::getValue('product_quantity') as $qty) {
             if (!Validate::isUnsignedInt($qty)) {
                 die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('Invalid quantity'))));
             }
         }
     }
 }
Example #28
0
 /**
  * Check any submitted form
  */
 private function _postValidation()
 {
     // Account settings form validation
     if (Tools::isSubmit('submit_account_detail')) {
         if (Tools::getValue('MR_enseigne_webservice') == '' || !preg_match("#^[0-9A-Z]{2}[0-9A-Z ]{6}\$#", Tools::getValue('MR_enseigne_webservice'))) {
             $this->_postErrors[] = $this->l('Invalid Enseigne');
         }
         if (Tools::getValue('MR_code_marque') == '' || !preg_match("#^[0-9]{2}\$#", Tools::getValue('MR_code_marque'))) {
             $this->_postErrors[] = $this->l('Invalid Mark code');
         }
         if (Tools::getValue('MR_webservice_key') == '' || !preg_match("#^[0-9A-Za-z_\\'., /\\-]{2,32}\$#", Tools::getValue('MR_webservice_key'))) {
             $this->_postErrors[] = $this->l('Invalid Webservice Key');
         }
         if (Tools::getValue('MR_language') == '' || !preg_match("#^[A-Z]{2}\$#", Tools::getValue('MR_language'))) {
             $this->_postErrors[] = $this->l('Invalid Language');
         }
         if (!Tools::getValue('MR_weight_coefficient') or !Validate::isInt(Tools::getValue('MR_weight_coefficient'))) {
             $this->_postErrors[] = $this->l('Invalid Weight Coefficient');
         }
     } else {
         if (Tools::isSubmit('submitMethod')) {
             if (!preg_match("#^[0-9A-Za-z_\\'., /\\-]{2,32}\$#", Tools::getValue('mr_Name'))) {
                 $this->_postErrors[] = $this->l('Invalid carrier name');
             }
             if (Tools::getValue('mr_ModeCol') != 'CCC') {
                 $this->_postErrors[] = $this->l('Invalid Col mode');
             }
             if (!preg_match("#^REL|24R|ESP|DRI|LDS|LDR|LD1\$#", Tools::getValue('mr_ModeLiv'))) {
                 $this->_postErrors[] = $this->l('Invalid delivery mode');
             }
             if (!Validate::isInt(Tools::getValue('mr_ModeAss')) or Tools::getValue('mr_ModeAss') > 5 or Tools::getValue('mr_ModeAss') < 0) {
                 $this->_postErrors[] = $this->l('Invalid Assurance mode');
             }
             if (!Tools::getValue('mr_Pays_list')) {
                 $this->_postErrors[] = $this->l('You must choose at least one delivery country.');
             }
         } else {
             if (Tools::isSubmit('submit_order_state')) {
                 if (!Validate::isUnsignedInt(Tools::getValue('id_order_state'))) {
                     $this->_postErrors[] = $this->l('Invalid order state');
                 }
             }
         }
     }
 }
Example #29
0
    public static function getProducts($id_supplier, $id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true)
    {
        $context = Context::getContext();
        $front = true;
        if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
            $front = false;
        }
        if ($p < 1) {
            $p = 1;
        }
        if (empty($order_by) || $order_by == 'position') {
            $order_by = 'name';
        }
        if (empty($order_way)) {
            $order_way = 'ASC';
        }
        if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
            die(Tools::displayError());
        }
        $groups = FrontController::getCurrentCustomerGroups();
        $sql_groups = count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1';
        /* Return only the number of products */
        if ($get_total) {
            $sql = '
				SELECT DISTINCT(ps.`id_product`)
				FROM `' . _DB_PREFIX_ . 'product_supplier` ps
				JOIN `' . _DB_PREFIX_ . 'product` p ON (ps.`id_product`= p.`id_product`)
				' . Shop::addSqlAssociation('product', 'p') . '
				WHERE ps.`id_supplier` = ' . (int) $id_supplier . '
				AND ps.id_product_attribute = 0' . ($active ? ' AND product_shop.`active` = 1' : '') . '
				' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . '
				AND p.`id_product` IN (
					SELECT cp.`id_product`
					FROM `' . _DB_PREFIX_ . 'category_group` cg
					LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)' . ($active_category ? ' INNER JOIN `' . _DB_PREFIX_ . 'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '') . '
					WHERE cg.`id_group` ' . $sql_groups . '
				)';
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            return (int) count($result);
        }
        $nb_days_new_product = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20;
        if (strpos('.', $order_by) > 0) {
            $order_by = explode('.', $order_by);
            $order_by = pSQL($order_by[0]) . '.`' . pSQL($order_by[1]) . '`';
        }
        $alias = '';
        if (in_array($order_by, array('price', 'date_add', 'date_upd'))) {
            $alias = 'product_shop.';
        } elseif ($order_by == 'id_product') {
            $alias = 'p.';
        } elseif ($order_by == 'manufacturer_name') {
            $order_by = 'name';
            $alias = 'm.';
        }
        $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock,
					IFNULL(stock.quantity, 0) as quantity,
					pl.`description`,
					pl.`description_short`,
					pl.`link_rewrite`,
					pl.`meta_description`,
					pl.`meta_keywords`,
					pl.`meta_title`,
					pl.`name`,
					MAX(image_shop.`id_image`) id_image,
					il.`legend`,
					s.`name` AS supplier_name,
					DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL ' . $nb_days_new_product . ' DAY)) > 0 AS new,
					m.`name` AS manufacturer_name
				FROM `' . _DB_PREFIX_ . 'product` p
				' . Shop::addSqlAssociation('product', 'p') . '
				JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (ps.id_product = p.id_product
					AND ps.id_product_attribute = 0)
				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` 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 . ')
				LEFT JOIN `' . _DB_PREFIX_ . 'supplier` s ON s.`id_supplier` = p.`id_supplier`
				LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
				' . Product::sqlStock('p') . '
				WHERE ps.`id_supplier` = ' . (int) $id_supplier . ($active ? ' AND product_shop.`active` = 1' : '') . '
					' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . '
					AND p.`id_product` IN (
						SELECT cp.`id_product`
						FROM `' . _DB_PREFIX_ . 'category_group` cg
						LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)' . ($active_category ? ' INNER JOIN `' . _DB_PREFIX_ . 'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '') . '
						WHERE cg.`id_group` ' . $sql_groups . '
					)
				GROUP BY product_shop.id_product
				ORDER BY ' . $alias . pSQL($order_by) . ' ' . pSQL($order_way) . '
				LIMIT ' . ((int) $p - 1) * (int) $n . ',' . (int) $n;
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
        if (!$result) {
            return false;
        }
        if ($order_by == 'price') {
            Tools::orderbyPrice($result, $order_way);
        }
        return Product::getProductsProperties($id_lang, $result);
    }
 public function getContent()
 {
     $output = '<h2>' . $this->displayName . '</h2>';
     if (Tools::isSubmit('submitBlockManufacturers')) {
         $text_list = (int) Tools::getValue('text_list');
         $text_nb = (int) Tools::getValue('text_nb');
         $form_list = (int) Tools::getValue('form_list');
         if ($text_list && !Validate::isUnsignedInt($text_nb)) {
             $errors[] = $this->l('There is an invalid number of elements');
         } elseif (!$text_list && !$form_list) {
             $errors[] = $this->l('Please activate at least one system list.');
         } else {
             Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT', $text_list);
             Configuration::updateValue('MANUFACTURER_DISPLAY_TEXT_NB', $text_nb);
             Configuration::updateValue('MANUFACTURER_DISPLAY_FORM', $form_list);
             $this->_clearCache('blockmanufacturer.tpl');
         }
         if (isset($errors) && count($errors)) {
             $output .= $this->displayError(implode('<br />', $errors));
         } else {
             $output .= $this->displayConfirmation($this->l('Settings updated'));
         }
     }
     return $output . $this->displayForm();
 }