public function renderContent($setting) { $t = array('categ_root_category' => '1', 'categ_max_depth' => 4, 'categ_dhtml' => 1, 'categ_sort' => 0, 'categ_sort_way' => 0); $setting = array_merge($t, $setting); $context = Context::getContext(); $this->setLastVisitedCategory(); $max_depth = $setting['categ_max_depth']; $result_ids = array(); $result_parents = array(); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `' . _DB_PREFIX_ . 'category` c INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $context->language->id . Shop::addSqlRestrictionOnLang('cl') . ') INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $context->shop->id . ') WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ') AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . ((int) $max_depth != 0 ? ' AND `level_depth` <= ' . (int) $max_depth : '') . ' AND c.id_category IN ( SELECT id_category FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_group` IN (' . pSQL(implode(', ', Customer::getGroupsStatic((int) $context->customer->id))) . ') ) ORDER BY `level_depth` ASC, ' . ($setting['categ_sort'] ? 'cl.`name`' : 'cs.`position`') . ' ' . ($setting['categ_sort_way'] ? 'DESC' : 'ASC')); foreach ($result as &$row) { $result_parents[$row['id_parent']][] =& $row; $result_ids[$row['id_category']] =& $row; } $block_categ_tree = $this->getTree($result_parents, $result_ids, $max_depth, null); $setting['blockCategTree'] = $block_categ_tree; if ((Tools::getValue('id_product') || Tools::getValue('id_category')) && isset($context->cookie->last_visited_category) && $context->cookie->last_visited_category) { $category = new Category($context->cookie->last_visited_category, $context->language->id); if (Validate::isLoadedObject($category)) { $setting['currentCategory'] = $category; $setting['currentCategoryId'] = $category->id; } } $setting['isDhtml'] = $setting['categ_dhtml']; if (file_exists(_PS_THEME_DIR_ . 'modules/pspagebuilder/views/templates/front/widgets/sub/category-tree-branch.tpl')) { $setting['branche_tpl_path'] = _PS_THEME_DIR_ . 'modules/pspagebuilder/views/templates/front/widgets/sub/category-tree-branch.tpl'; } else { $setting['branche_tpl_path'] = _PS_MODULE_DIR_ . 'pspagebuilder/views/templates/front/widgets/sub/category-tree-branch.tpl'; } $output = array('type' => 'categoriesblock', 'data' => $setting); return $output; }
/** * @static * @param $id_lang * @param $id_customer * @param bool $active * @param bool $includeGeneric * @param bool $inStock * @param Cart|null $cart * @return array */ public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null) { if (!CartRule::isFeatureActive()) { return array(); } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT * FROM `' . _DB_PREFIX_ . 'cart_rule` cr LEFT JOIN `' . _DB_PREFIX_ . 'cart_rule_lang` crl ON (cr.`id_cart_rule` = crl.`id_cart_rule` AND crl.`id_lang` = ' . (int) $id_lang . ') WHERE ( cr.`id_customer` = ' . (int) $id_customer . ' OR cr.group_restriction = 1 ' . ($includeGeneric ? 'OR cr.`id_customer` = 0' : '') . ' ) AND cr.date_from < "' . date('Y-m-d H:i:s') . '" AND cr.date_to > "' . date('Y-m-d H:i:s') . '" ' . ($active ? 'AND cr.`active` = 1' : '') . ' ' . ($inStock ? 'AND cr.`quantity` > 0' : '')); // Remove cart rule that does not match the customer groups $customerGroups = Customer::getGroupsStatic($id_customer); foreach ($result as $key => $cart_rule) { if ($cart_rule['group_restriction']) { $cartRuleGroups = Db::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'cart_rule_group WHERE id_cart_rule = ' . (int) $cart_rule['id_cart_rule']); foreach ($cartRuleGroups as $cartRuleGroup) { if (in_array($cartRuleGroup['id_group'], $customerGroups)) { continue 2; } } unset($result[$key]); } } foreach ($result as &$cart_rule) { if ($cart_rule['quantity_per_user']) { $quantity_used = Order::getDiscountsCustomer((int) $id_customer, (int) $cart_rule['id_cart_rule']); if (isset($cart) && isset($cart->id)) { $quantity_used += $cart->getDiscountsCustomer((int) $cart_rule['id_cart_rule']); } $cart_rule['quantity_for_user'] = $cart_rule['quantity_per_user'] - $quantity_used; } else { $cart_rule['quantity_for_user'] = 0; } } unset($cart_rule); foreach ($result as $cart_rule) { if ($cart_rule['shop_restriction']) { $cartRuleShops = Db::getInstance()->executeS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'cart_rule_shop WHERE id_cart_rule = ' . (int) $cart_rule['id_cart_rule']); foreach ($cartRuleShops as $cartRuleShop) { if (Shop::isFeatureActive() && $cartRuleShop['id_shop'] == Context::getContext()->shop->id) { continue 2; } } unset($result[$key]); } } // Retrocompatibility with 1.4 discounts foreach ($result as &$cart_rule) { $cart_rule['value'] = 0; $cart_rule['minimal'] = $cart_rule['minimum_amount']; $cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction']; $cart_rule['id_discount_type'] = false; if ($cart_rule['free_shipping']) { $cart_rule['id_discount_type'] = Discount::FREE_SHIPPING; } elseif ($cart_rule['reduction_percent'] > 0) { $cart_rule['id_discount_type'] = Discount::PERCENT; $cart_rule['value'] = $cart_rule['reduction_percent']; } elseif ($cart_rule['reduction_amount'] > 0) { $cart_rule['id_discount_type'] = Discount::AMOUNT; $cart_rule['value'] = $cart_rule['reduction_amount']; } } return $result; }
function getReduction($va92811717d11, $v0688afdf8a14, $cookie) { if (isset($cookie->id_customer)) { $v4612b6226467 = $cookie->id_customer; $v156e9bc09d33 = $cookie->id_currency; $v1d6e2b7aff3f = implode(', ', Customer::getGroupsStatic($v4612b6226467)); } else { $v156e9bc09d33 = 0; $v1d6e2b7aff3f = 0; } $v85f53d729293 = '0'; $v0c695db2467f = DB::getInstance()->ExecuteS('SELECT from_quantity, reduction FROM ' . _DB_PREFIX_ . 'specific_price WHERE reduction_type = "percentage" AND id_product=' . $va92811717d11 . ' AND (`from` < NOW() OR `from`="0000-00-00 00:00:00") AND (`to` > NOW() OR `to`="0000-00-00 00:00:00") AND id_group IN (0, ' . $v1d6e2b7aff3f . ') AND id_currency IN(0, ' . (int) $v156e9bc09d33 . ') ORDER BY reduction DESC'); foreach ($v0c695db2467f as $v71979fa1b961) { if (intval($v71979fa1b961['from_quantity']) <= $v0688afdf8a14) { $v85f53d729293 = $v71979fa1b961['reduction']; break; } } return $v85f53d729293; }
public function getGroups() { return Customer::getGroupsStatic((int) $this->id); }
/** * Get CartRules for the given Customer * * @param int $id_lang Language ID * @param int $id_customer Customer ID * @param bool $active Active vouchers only * @param bool $includeGeneric Include generic AND highlighted vouchers, regardless of highlight_only setting * @param bool $inStock Vouchers in stock only * @param Cart|null $cart Cart * @param bool $free_shipping_only Free shipping only * @param bool $highlight_only Highlighted vouchers only * @return array * @throws PrestaShopDatabaseException */ public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null, $free_shipping_only = false, $highlight_only = false) { if (!CartRule::isFeatureActive()) { return array(); } $sql_part1 = '* FROM `' . _DB_PREFIX_ . 'cart_rule` cr LEFT JOIN `' . _DB_PREFIX_ . 'cart_rule_lang` crl ON (cr.`id_cart_rule` = crl.`id_cart_rule` AND crl.`id_lang` = ' . (int) $id_lang . ')'; $sql_part2 = ' AND cr.date_from < "' . date('Y-m-d H:i:s') . '" AND cr.date_to > "' . date('Y-m-d H:i:s') . '" ' . ($active ? 'AND cr.`active` = 1' : '') . ' ' . ($inStock ? 'AND cr.`quantity` > 0' : ''); if ($free_shipping_only) { $sql_part2 .= ' AND free_shipping = 1 AND carrier_restriction = 1'; } if ($highlight_only) { $sql_part2 .= ' AND highlight = 1 AND code NOT LIKE "' . pSQL(CartRule::BO_ORDER_CODE_PREFIX) . '%"'; } $sql = '(SELECT SQL_NO_CACHE ' . $sql_part1 . ' WHERE cr.`id_customer` = ' . (int) $id_customer . ' ' . $sql_part2 . ')'; $sql .= ' UNION (SELECT ' . $sql_part1 . ' WHERE cr.`group_restriction` = 1 ' . $sql_part2 . ')'; if ($includeGeneric && (int) $id_customer != 0) { $sql .= ' UNION (SELECT ' . $sql_part1 . ' WHERE cr.`id_customer` = 0 ' . $sql_part2 . ')'; } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, true, false); if (empty($result)) { return array(); } // Remove cart rule that does not match the customer groups $customerGroups = Customer::getGroupsStatic($id_customer); foreach ($result as $key => $cart_rule) { if ($cart_rule['group_restriction']) { $cartRuleGroups = Db::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'cart_rule_group WHERE id_cart_rule = ' . (int) $cart_rule['id_cart_rule']); foreach ($cartRuleGroups as $cartRuleGroup) { if (in_array($cartRuleGroup['id_group'], $customerGroups)) { continue 2; } } unset($result[$key]); } } foreach ($result as &$cart_rule) { if ($cart_rule['quantity_per_user']) { $quantity_used = Order::getDiscountsCustomer((int) $id_customer, (int) $cart_rule['id_cart_rule']); if (isset($cart) && isset($cart->id)) { $quantity_used += $cart->getDiscountsCustomer((int) $cart_rule['id_cart_rule']); } $cart_rule['quantity_for_user'] = $cart_rule['quantity_per_user'] - $quantity_used; } else { $cart_rule['quantity_for_user'] = 0; } } unset($cart_rule); foreach ($result as $key => $cart_rule) { if ($cart_rule['shop_restriction']) { $cartRuleShops = Db::getInstance()->executeS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'cart_rule_shop WHERE id_cart_rule = ' . (int) $cart_rule['id_cart_rule']); foreach ($cartRuleShops as $cartRuleShop) { if (Shop::isFeatureActive() && $cartRuleShop['id_shop'] == Context::getContext()->shop->id) { continue 2; } } unset($result[$key]); } } if (isset($cart) && isset($cart->id)) { foreach ($result as $key => $cart_rule) { if ($cart_rule['product_restriction']) { $cr = new CartRule((int) $cart_rule['id_cart_rule']); $r = $cr->checkProductRestrictions(Context::getContext(), false, false); if ($r !== false) { continue; } unset($result[$key]); } } } $result_bak = $result; $result = array(); $country_restriction = false; foreach ($result_bak as $key => $cart_rule) { if ($cart_rule['country_restriction']) { $country_restriction = true; $countries = Db::getInstance()->ExecuteS(' SELECT `id_country` FROM `' . _DB_PREFIX_ . 'address` WHERE `id_customer` = ' . (int) $id_customer . ' AND `deleted` = 0'); if (is_array($countries) && count($countries)) { foreach ($countries as $country) { $id_cart_rule = (bool) Db::getInstance()->getValue(' SELECT crc.id_cart_rule FROM ' . _DB_PREFIX_ . 'cart_rule_country crc WHERE crc.id_cart_rule = ' . (int) $cart_rule['id_cart_rule'] . ' AND crc.id_country = ' . (int) $country['id_country']); if ($id_cart_rule) { $result[] = $result_bak[$key]; break; } } } } else { $result[] = $result_bak[$key]; } } if (!$country_restriction) { $result = $result_bak; } // Retrocompatibility with 1.4 discounts // TODO: remove? We're at 1.7 now foreach ($result as &$cart_rule) { $cart_rule['value'] = 0; $cart_rule['minimal'] = Tools::convertPriceFull($cart_rule['minimum_amount'], new Currency($cart_rule['minimum_amount_currency']), Context::getContext()->currency); $cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction']; $cart_rule['id_discount_type'] = false; if ($cart_rule['free_shipping']) { $cart_rule['id_discount_type'] = Discount::FREE_SHIPPING; } elseif ($cart_rule['reduction_percent'] > 0) { $cart_rule['id_discount_type'] = Discount::PERCENT; $cart_rule['value'] = $cart_rule['reduction_percent']; } elseif ($cart_rule['reduction_amount'] > 0) { $cart_rule['id_discount_type'] = Discount::AMOUNT; $cart_rule['value'] = $cart_rule['reduction_amount']; } } unset($cart_rule); return $result; }
public function init() { global $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files; if (self::$initialized) { return; } self::$initialized = true; $css_files = array(); $js_files = array(); if ($this->ssl and (empty($_SERVER['HTTPS']) or strtolower($_SERVER['HTTPS']) == 'off') and Configuration::get('PS_SSL_ENABLED')) { header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']); exit; } ob_start(); /* Loading default country */ $defaultCountry = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); $cookie = new Cookie('ps'); $link = new Link(); if ($this->auth and !$cookie->isLogged($this->guestAllowed)) { Tools::redirect('authentication.php' . ($this->authRedirection ? '?back=' . $this->authRedirection : '')); } /* Theme is missing or maintenance */ if (!is_dir(_PS_THEME_DIR_)) { die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.')); } elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' and !(int) Configuration::get('PS_SHOP_ENABLE')) { $this->maintenance = true; } elseif (Configuration::get('PS_GEOLOCATION_ENABLED')) { if (!isset($cookie->iso_code_country)) { if ($cookie->logged) { $id_country = Customer::getCurrentCountry((int) $cookie->id_customer); $cookie->iso_code_country = Country::getIsoById($id_country); } else { $this->geolocationManagement(); } } if (!isset($cookie->iso_code_country)) { $current_country_id = Customer::getCurrentCountry((int) $cookie->id_customer); } else { $current_country_id = Country::getByIso($cookie->iso_code_country); } $current_country = new Country($current_country_id, 1); $cookie->id_country = $current_country->id; $smarty->assign('current_country', $current_country->name); $smarty->assign('current_country_id', $current_country->id); if ($cookie->id_country == 110 && !isset($cookie->id_currency)) { $cookie->id_currency = 4; } } //set imagesize if not set if (!isset($cookie->image_size)) { $cookie->image_size = IMAGE_SIZE_LARGE; $cookie->write(); } if (!isset($cookie->greetings) && !$cookie->logged) { $cookie->greetings = 1; $cookie->write(); $smarty->assign('show_greetings', 1); } //echo $cookie->image_size; if ($image_size = Tools::getValue("is")) { if ($image_size == "s" && $cookie->image_size == IMAGE_SIZE_LARGE) { $cookie->image_size = IMAGE_SIZE_SMALL; $cookie->write(); } else { if ($image_size == "l" && $cookie->image_size == IMAGE_SIZE_SMALL) { $cookie->image_size = IMAGE_SIZE_LARGE; $cookie->write(); } } } // Switch language if needed and init cookie language if ($iso = Tools::getValue('isolang') and Validate::isLanguageIsoCode($iso) and $id_lang = (int) Language::getIdByIso($iso)) { $_GET['id_lang'] = $id_lang; } Tools::switchLanguage(); Tools::setCookieLanguage(); /* attribute id_lang is often needed, so we create a constant for performance reasons */ if (!defined('_USER_ID_LANG_')) { define('_USER_ID_LANG_', (int) $cookie->id_lang); } if (isset($_GET['logout']) or $cookie->logged and Customer::isBanned((int) $cookie->id_customer)) { $cookie->logout(); Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL); } elseif (isset($_GET['mylogout'])) { $this->logoutFacebook(); $cookie->mylogout(); Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL); } if ($source = Tools::getValue('utm_source')) { $cookie->last_source = $source; $cookie->write(); } if ($ref_source = Tools::getValue('vbref')) { $cookie->last_ref_source = $ref_source; $cookie->write(); } /*else { if(!isset($cookie->last_ref_source)) { $cookie->last_ref_source = 0; $cookie->write(); } }*/ global $currency; $currency = Tools::setCurrency(); $_MODULES = array(); /* Cart already exists */ if ((int) $cookie->id_cart) { $cart = new Cart((int) $cookie->id_cart); if ($cart->OrderExists()) { unset($cookie->id_cart, $cart, $cookie->checkedTOS); } elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) and !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) and $cart->nbProducts() and intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 and !self::isInWhitelistForGeolocation()) { unset($cookie->id_cart, $cart); } elseif ($cookie->id_customer != $cart->id_customer or $cookie->id_lang != $cart->id_lang or $cookie->id_currency != $cart->id_currency) { if ($cookie->id_customer) { $cart->id_customer = (int) $cookie->id_customer; } $cart->id_lang = (int) $cookie->id_lang; $cart->id_currency = (int) $cookie->id_currency; $cart->update(); } /* Select an address if not set */ if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $cookie->id_customer) { $to_update = false; if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) { $to_update = true; $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer); } if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) { $to_update = true; $cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer); } if ($to_update) { $cart->update(); } } } if (!isset($cart) or !$cart->id) { $this->checkIDS(); $cart = new Cart(); $cart->id_lang = (int) $cookie->id_lang; $cart->id_currency = (int) $cookie->id_currency; $cart->id_guest = (int) $cookie->id_guest; if ($cookie->id_customer) { $cart->id_customer = (int) $cookie->id_customer; $cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer); $cart->id_address_invoice = $cart->id_address_delivery; } else { $cart->id_address_delivery = 0; $cart->id_address_invoice = 0; } } if (!$cart->nbProducts()) { $cart->id_carrier = NULL; } $locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')) . '_' . strtoupper(Configuration::get('PS_LOCALE_COUNTRY') . '.UTF-8'); setlocale(LC_COLLATE, $locale); setlocale(LC_CTYPE, $locale); setlocale(LC_TIME, $locale); setlocale(LC_NUMERIC, 'en_US.UTF-8'); if (Validate::isLoadedObject($currency)) { $smarty->ps_currency = $currency; } if (Validate::isLoadedObject($ps_language = new Language((int) $cookie->id_lang))) { $smarty->ps_language = $ps_language; } /* get page name to display it in body id */ $pathinfo = pathinfo(__FILE__); $page_name = basename($_SERVER['PHP_SELF'], '.' . $pathinfo['extension']); $page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name; $smarty->assign(Tools::getMetaTags($cookie->id_lang, $page_name)); $smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); /* Breadcrumb */ $navigationPipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>'; $smarty->assign('navigationPipe', $navigationPipe); $protocol_link = (Configuration::get('PS_SSL_ENABLED') or !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://'; $protocol_content = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED') or !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://'; if (!defined('_PS_BASE_URL_')) { define('_PS_BASE_URL_', Tools::getShopDomain(true)); } if (!defined('_PS_BASE_URL_SSL_')) { define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true)); } $link->preloadPageLinks(); $this->canonicalRedirection(); Product::initPricesComputation(); $display_tax_label = $defaultCountry->display_tax_label; if ($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) { $infos = Address::getCountryAndState((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $country = new Country((int) $infos['id_country']); if (Validate::isLoadedObject($country)) { $display_tax_label = $country->display_tax_label; } } global $isBetaUser, $conversion_rate_inr; $conversion_rate_inr = 55; if (!$cookie->isLogged()) { $this->initFacebook(); } else { $customer_groups = Customer::getGroupsStatic((int) $cookie->id_customer); if (in_array(2, $customer_groups)) { $smarty->assign('internal_vb_user', 1); } if (in_array(3, $customer_groups)) { $isBetaUser = true; } else { $isBetaUser = false; } /*$reward_points = VBRewards::getCustomerPoints($cookie->id_customer); $can_redeem = VBRewards::checkPointsValidity($cookie->id_customer, 0); if($can_redeem) $smarty->assign('can_redeem_points', 1); $smarty->assign('balance_points', $reward_points);*/ } $smarty->assign('img_version', IMG_VERSION); $this->setRecaptchaHTML(); if ($page_name === "index") { $sql = "select title,image_path,url from ps_banner where is_active = 1 order by display_order asc"; $home_banners = Db::getInstance()->ExecuteS($sql); $smarty->assign("home_banners", $home_banners); } $smarty->assign(array('lazy' => 1, 'link' => $link, 'cart' => $cart, 'currency' => $currency, 'cookie' => $cookie, 'page_name' => $page_name, 'base_dir' => _PS_BASE_URL_ . __PS_BASE_URI__, 'base_dir_ssl' => $protocol_link . Tools::getShopDomainSsl() . __PS_BASE_URI__, 'content_dir' => $protocol_content . Tools::getShopDomain() . __PS_BASE_URI__, 'tpl_dir' => _PS_THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'lang_iso' => $ps_language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . Tools::htmlentitiesUTF8(str_replace('\'', '', urldecode($_SERVER['REQUEST_URI']))), 'cart_qties' => (int) $cart->nbProducts(), 'currencies' => Currency::getCurrencies(), 'languages' => Language::getLanguages(), 'priceDisplay' => Product::getTaxCalculationMethod(), 'add_prod_display' => (int) Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'roundMode' => (int) Configuration::get('PS_PRICE_ROUND_MODE'), 'use_taxes' => (int) Configuration::get('PS_TAX'), 'display_tax_label' => (bool) $display_tax_label, 'vat_management' => (int) Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool) Configuration::get('PS_CATALOG_MODE'), 'conversion_rate' => $conversion_rate_inr)); // Deprecated $smarty->assign(array('id_currency_cookie' => (int) $currency->id, 'logged' => $cookie->isLogged(), 'customerName' => $cookie->logged ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : false)); // TODO for better performances (cache usage), remove these assign and use a smarty function to get the right media server in relation to the full ressource name $assignArray = array('img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_store_dir' => _THEME_STORE_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_); foreach ($assignArray as $assignKey => $assignValue) { if (substr($assignValue, 0, 1) == '/' or $protocol_content == 'https://') { $smarty->assign($assignKey, $protocol_content . Tools::getMediaServer($assignValue) . $assignValue); } else { $smarty->assign($assignKey, $assignValue); } } // setting properties from global var self::$cookie = $cookie; self::$cart = $cart; self::$smarty = $smarty; self::$link = $link; if ($this->maintenance) { $this->displayMaintenancePage(); } if ($this->restrictedCountry) { $this->displayRestrictedCountryPage(); } //live edit if (Tools::isSubmit('live_edit') and $ad = Tools::getValue('ad') and Tools::getValue('liveToken') == sha1(Tools::getValue('ad') . _COOKIE_KEY_)) { if (!is_dir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $ad)) { die(Tools::displayError()); } } $this->iso = $iso; $this->setMedia(); //For sokrati pixel self::$smarty->assign("new_customer_regd", false); if ((int) self::$cookie->new_reg === 1) { self::$smarty->assign("new_customer_regd", true); unset(self::$cookie->new_reg); } if (self::$cookie->id_customer) { self::$smarty->assign("balance_points", VBRewards::getCustomerPoints(self::$cookie->id_customer)); } }
public function getblockCategTree() { // Get all groups for this customer and concatenate them as a string: "1,2,3..." $groups = implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id)); $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `' . _DB_PREFIX_ . 'category` c INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ') INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $this->context->shop->id . ') WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ') AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . ' ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' AND c.id_category IN (SELECT id_category FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_group` IN (' . pSQL($groups) . ')) ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')))) { return; } $resultParents = array(); $resultIds = array(); foreach ($result as &$row) { $resultParents[$row['id_parent']][] =& $row; $resultIds[$row['id_category']] =& $row; } $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); unset($resultParents, $resultIds); $id_category = (int) Tools::getValue('id_category'); $id_product = (int) Tools::getValue('id_product'); if (Tools::isSubmit('id_category')) { $this->context->cookie->last_visited_category = $id_category; $this->smarty->assign('currentCategoryId', $this->context->cookie->last_visited_category); } if (Tools::isSubmit('id_product')) { if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category))) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop)) { $product = new Product($id_product); if (isset($product) && Validate::isLoadedObject($product)) { $this->context->cookie->last_visited_category = (int) $product->id_category_default; } } $this->smarty->assign('currentCategoryId', (int) $this->context->cookie->last_visited_category); } return $blockCategTree; }
/** * Check discount validity * * @return mixed Return a string if an error occurred and false otherwise */ function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = false) { global $cookie; if (!$order_total) { return Tools::displayError('Cannot add voucher if order is free.'); } if (!$discountObj->active) { return Tools::displayError('This voucher has already been used or is disabled.'); } if (!$discountObj->quantity) { return Tools::displayError('This voucher has expired (usage limit attained).'); } if ($discountObj->id_discount_type == 2 and $this->id_currency != $discountObj->id_currency) { return Tools::displayError('This voucher can only be used in the following currency:') . ' ' . Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `name` FROM `' . _DB_PREFIX_ . 'currency` WHERE id_currency = ' . (int) $discountObj->id_currency); } if ($checkCartDiscount and ($this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user or (Order::getDiscountsCustomer((int) $cookie->id_customer, $discountObj->id) + $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user)) { return Tools::displayError('You cannot use this voucher anymore (usage limit attained).'); } if (strtotime($discountObj->date_from) > time()) { return Tools::displayError('This voucher is not yet valid'); } if (strtotime($discountObj->date_to) < time()) { return Tools::displayError('This voucher has expired.'); } if (sizeof($discounts) >= 1 and $checkCartDiscount) { if (!$discountObj->cumulable) { return Tools::displayError('This voucher is not valid with other current discounts.'); } foreach ($discounts as $discount) { if (!$discount['cumulable']) { return Tools::displayError('Voucher is not valid with other discounts.'); } } foreach ($discounts as $discount) { if ($discount['id_discount'] == $discountObj->id) { return Tools::displayError('This voucher is already in your cart'); } } } $groups = Customer::getGroupsStatic($this->id_customer); if (($discountObj->id_customer or $discountObj->id_group) and (($this->id_customer != $discountObj->id_customer or $this->id_customer == 0) and !in_array($discountObj->id_group, $groups))) { if (!$cookie->isLogged()) { return Tools::displayError('You cannot use this voucher.') . ' - ' . Tools::displayError('Please log in.'); } return Tools::displayError('You cannot use this voucher.'); } $onlyProductWithDiscount = true; if (!$discountObj->cumulable_reduction) { foreach ($products as $product) { if (!$product['reduction_applies'] and !$product['on_sale']) { $onlyProductWithDiscount = false; } } } if (!$discountObj->cumulable_reduction and $onlyProductWithDiscount) { return Tools::displayError('This voucher is not valid for marked or reduced products.'); } $total_cart = 0; $categories = Discount::getCategories($discountObj->id); $returnErrorNoProductCategory = true; foreach ($products as $product) { if (count($categories)) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { if (!$discountObj->cumulable_reduction and !$product['reduction_applies'] and !$product['on_sale'] or $discountObj->cumulable_reduction) { $total_cart += $discountObj->include_tax ? $product['total_wt'] : $product['total']; } $returnErrorNoProductCategory = false; } } } if ($returnErrorNoProductCategory) { return Tools::displayError('This discount does not apply to that product category.'); } if ($total_cart < $discountObj->minimal) { return Tools::displayError('The order total is not high enough or this voucher cannot be used with those products.'); } return false; }
protected function getCacheId($name = null) { $cache_array = array(); $cache_array[] = $name !== null ? $name : $this->name; if (Configuration::get('PS_SSL_ENABLED')) { $cache_array[] = (int) Tools::usingSecureMode(); } if (Shop::isFeatureActive()) { $cache_array[] = (int) $this->context->shop->id; } if (Group::isFeatureActive() && isset($this->context->customer)) { $cache_array[] = (int) Group::getCurrent()->id; $cache_array[] = implode('_', Customer::getGroupsStatic($this->context->customer->id)); } if (Language::isMultiLanguageActivated()) { $cache_array[] = (int) $this->context->language->id; } if (Currency::isMultiCurrencyActivated()) { $cache_array[] = (int) $this->context->currency->id; } $cache_array[] = (int) $this->context->country->id; return implode('|', $cache_array); }
public static function getCustomerGroups() { $groups = array(); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Group::isFeatureActive()) { if (Validate::isLoadedObject(Context::getContext()->customer)) { $groups = FrontController::getCurrentCustomerGroups(); } else { $groups = array((int) Configuration::get('PS_UNIDENTIFIED_GROUP')); } } else { if (version_compare(_PS_VERSION_, '1.4.0.2', '>=') && version_compare(_PS_VERSION_, '1.5.0.0', '<')) { global $cookie; $groups = Customer::getGroupsStatic((int) $cookie->id_customer); } else { if (version_compare(_PS_VERSION_, '1.4.0.2', '<') && version_compare(_PS_VERSION_, '1.2.5.0', '>=')) { global $cookie; $result = Db::getInstance()->ExecuteS('SELECT cg.`id_group` FROM ' . _DB_PREFIX_ . 'customer_group cg WHERE cg.`id_customer` = ' . (int) $cookie->id_customer); if ($result && is_array($result)) { foreach ($result as $group) { $groups[] = (int) $group['id_group']; } } } } } sort($groups); return $groups; }
function hookTop($params) { //get disable categories $CATS = Configuration::get('MEGAMENU_CATS'); $UN_CATS = array(); $UN_CATS = unserialize($CATS); $context = Context::getContext(); if (version_compare(_PS_VERSION_, '1.5.0.0') == +1) { $id_current_shop = $this->context->shop->id; $id_customer = (int) $params['cookie']->id_customer; // Get all groups for this customer and concatenate them as a string: "1,2,3..." // It is necessary to keep the group query separate from the main select query because it is used for the cache $groups = $id_customer ? implode(', ', Customer::getGroupsStatic($id_customer)) : Configuration::get('PS_UNIDENTIFIED_GROUP'); $id_product = (int) Tools::getValue('id_product', 0); $id_category = (int) Tools::getValue('id_category', 0); $id_lang = (int) $params['cookie']->id_lang; $smartyCacheId = 'megamenu|' . $id_current_shop . '_' . $groups . '_' . $id_lang . '_' . $id_product . '_' . $id_category; Tools::enableCache(); if (!$this->isCached('tmp/megamenu.tpl', $smartyCacheId)) { $maxdepth = 4; if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite, cs.position FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . $id_lang . Shop::addSqlRestrictionOnLang('cl') . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`) LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category`) WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ') AND c.`id_category` NOT IN (' . (count($UN_CATS) > 0 ? implode(",", $UN_CATS) : "-1") . ') ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' AND cg.`id_group` IN (' . pSQL($groups) . ') AND cs.`id_shop` = ' . (int) Context::getContext()->shop->id . ' GROUP BY id_category ORDER BY `level_depth` ASC, cs.`position` ASC'))) { return Tools::restoreCacheSettings(); } $customResult = Db::getInstance()->ExecuteS(' SELECT * FROM `' . _DB_PREFIX_ . 'megamenu` m LEFT JOIN `' . _DB_PREFIX_ . 'megamenu_lang` ml ON (m.`id_megamenu` = ml.`id_megamenu` AND ml.`id_lang` = ' . intval($params['cookie']->id_lang) . ') WHERE m.`active` = 1 AND m.`id_shop` = ' . (int) Context::getContext()->shop->id . ' ORDER BY m.`position` ASC'); $total = count($customResult); for ($i = 0; $i < $total; $i++) { $customResult[$i]['id_category'] = 'c' . $customResult[$i]['id_megamenu']; $customResult[$i]['type'] = 'custom'; if ($customResult[$i]['parent_custom'] == 1) { $customResult[$i]['id_parent'] = 'c' . $customResult[$i]['parent']; } else { $customResult[$i]['id_parent'] = $customResult[$i]['parent']; } } $mergeresult = array_merge($result, $customResult); $this->aasort($mergeresult, "position"); //echo print_r($mergeresult); $resultParents = array(); $resultIds = array(); foreach ($mergeresult as &$row) { $resultParents[$row['id_parent']][] =& $row; $resultIds[$row['id_category']] =& $row; } $blockCategTree = $this->getTree($resultParents, $resultIds, 3, (int) Configuration::get('PS_HOME_CATEGORY')); unset($resultParents); unset($resultIds); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; if (Tools::isSubmit('id_category')) { $this->context->cookie->last_visited_category = $id_category; $this->smarty->assign('currentCategoryId', $this->context->cookie->last_visited_category); } if (Tools::isSubmit('id_product')) { if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category)))) { $product = new Product($id_product); if (isset($product) && Validate::isLoadedObject($product)) { $this->context->cookie->last_visited_category = (int) $product->id_category_default; } } $this->smarty->assign('currentCategoryId', (int) $this->context->cookie->last_visited_category); } } } $tmp = null; $context->smarty->assign('blockCategTree', $blockCategTree); $context->smarty->assign('this_path', $this->_path); $context->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'megamenu/tmp/category-tree-branch.tpl'); $context->smarty->assign('MEGAMENU_COLOR', Configuration::get('MEGAMENU_COLOR')); $context->smarty->assign('MEGAMENU_ROWITEMS', Configuration::get('MEGAMENU_ROWITEMS')); $context->smarty->assign('MEGAMENU_SPEED', Configuration::get('MEGAMENU_SPEED')); $context->smarty->assign('MEGAMENU_EFFECT', Configuration::get('MEGAMENU_EFFECT')); $context->smarty->assign('MEGAMENU_EVENT', Configuration::get('MEGAMENU_EVENT')); $context->smarty->assign('MEGAMENU_FULLWIDTH', Configuration::get('MEGAMENU_FULLWIDTH')); $context->smarty->assign('MEGAMENU_DISPLAYIMAGES', Configuration::get('MEGAMENU_DISPLAYIMAGES')); $context->smarty->assign('MEGAMENU_MARGINLEFT', Configuration::get('MEGAMENU_MARGINLEFT')); $context->smarty->assign('MEGAMENU_MARGINTOP', Configuration::get('MEGAMENU_MARGINTOP')); $context->smarty->assign('MEGAMENU_MARGINRIGHT', Configuration::get('MEGAMENU_MARGINRIGHT')); $context->smarty->assign('MEGAMENU_MARGINBOTTOM', Configuration::get('MEGAMENU_MARGINBOTTOM')); $display = $this->display(__FILE__, 'tmp/megamenu.tpl', $smartyCacheId); Tools::restoreCacheSettings(); return $display; }
protected function getCacheId($name = null) { $name = ($name ? $name . '|' : '') . implode('-', Customer::getGroupsStatic($this->context->customer->id)); return parent::getCacheId($name); }
private function getCategories($category) { $range = ''; $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (Validate::isLoadedObject($category)) { if ($maxdepth > 0) { $maxdepth += $category->level_depth; } $range = 'AND nleft >= ' . (int) $category->nleft . ' AND nright <= ' . (int) $category->nright; } $resultIds = array(); $resultParents = array(); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `' . _DB_PREFIX_ . 'category` c INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ') INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $this->context->shop->id . ') WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ') AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . ' ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' ' . $range . ' AND c.id_category IN ( SELECT id_category FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_group` IN (' . pSQL(implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id))) . ') ) ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')); foreach ($result as &$row) { $resultParents[$row['id_parent']][] =& $row; $resultIds[$row['id_category']] =& $row; } return $this->getTree($resultParents, $resultIds, $maxdepth, $category ? $category->id : null); }
private function calculHookCommon($params) { $categories_selector = Configuration::get('iqitsearch_categories'); if ($categories_selector) { $range = ''; $maxdepth = (int) Configuration::get('iqitsearch_depth'); $homecat = (int) Configuration::get('PS_HOME_CATEGORY'); if ($homecat == 0) { $homecat = (int) Configuration::get('PS_ROOT_CATEGORY'); } $resultIds = array(); $resultParents = array(); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name FROM `' . _DB_PREFIX_ . 'category` c INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ') INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $this->context->shop->id . ') WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) $homecat . ') AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . ' ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' AND c.id_category IN ( SELECT id_category FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_group` IN (' . pSQL(implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id))) . ') ) ORDER BY `level_depth` ASC, cs.`position` ASC'); foreach ($result as &$row) { $resultParents[$row['id_parent']][] =& $row; $resultIds[$row['id_category']] =& $row; } $blockCategTree = $this->getTree($resultParents, $resultIds, $maxdepth, $homecat); $this->smarty->assign('blockCategTree', $blockCategTree); } $this->smarty->assign(array('ENT_QUOTES' => ENT_QUOTES, 'search_ssl' => Tools::usingSecureMode(), 'ajaxsearch' => Configuration::get('PS_SEARCH_AJAX'), 'instantsearch' => Configuration::get('PS_INSTANT_SEARCH'), 'self' => dirname(__FILE__))); return true; }
/** * Check discount validity * * @return mixed Return a string if an error occurred and false otherwise */ function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = true) { global $cookie; // if(strpos('B1G1', $discountObj->name) == 0) // return false; if (!$order_total) { return Tools::displayError('Cannot add voucher if order is free.'); } if (!$discountObj->active) { return Tools::displayError('This voucher has already been used or is disabled.'); } if (!$discountObj->quantity) { return Tools::displayError('This voucher has expired (usage limit attained).'); } //if (($discountObj->id_discount_type == 2 || $discountObj->id_discount_type == 4) AND $this->id_currency != $discountObj->id_currency) //return Tools::displayError('This voucher can only be used in the following currency:').' //'.Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `name` FROM `'._DB_PREFIX_.'currency` WHERE id_currency = '.(int)$discountObj->id_currency); if ($checkCartDiscount and ($this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user or (Order::getDiscountsCustomer((int) $cookie->id_customer, $discountObj->id) + $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user)) { return Tools::displayError('You cannot use this voucher anymore (usage limit attained).'); } /*if (( $this->getDiscountsGroupCustomer($discountObj->discount_group) >= $discountObj->quantity_per_user OR (Order::getDiscountsGroupCustomer((int)($cookie->id_customer), $discountObj->discount_group) + $this->getDiscountsGroupCustomer($discountObj->discount_group) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user ) ) return Tools::displayError('Vouchers from this promotion can only be used once by a customer.');*/ if (strtotime($discountObj->date_from) > time()) { return Tools::displayError('This voucher is not yet valid'); } if (strtotime($discountObj->date_to) < time()) { return Tools::displayError('This voucher has expired.'); } if (sizeof($discounts) >= 1 and $checkCartDiscount) { if (!$discountObj->cumulable) { return Tools::displayError('This voucher is not valid with other current discounts.'); } foreach ($discounts as $discount) { if (!$discount['cumulable']) { return Tools::displayError('Voucher is not valid with other discounts.'); } } foreach ($discounts as $discount) { if ($discount['id_discount'] == $discountObj->id) { return Tools::displayError('This voucher is already in your cart'); } } } $groups = Customer::getGroupsStatic($this->id_customer); if (($discountObj->id_customer or $discountObj->id_group) and ($this->id_customer != $discountObj->id_customer and !in_array($discountObj->id_group, $groups))) { if (!$cookie->isLogged()) { return Tools::displayError('You cannot use this voucher.') . ' - ' . Tools::displayError('Please log in.'); } return Tools::displayError('You cannot use this voucher.'); } $currentDate = date('Y-m-d'); $onlyProductWithDiscount = true; if (!$discountObj->cumulable_reduction) { foreach ($products as $product) { if (!$product['reduction_applies'] and !$product['on_sale']) { $onlyProductWithDiscount = false; } } } if (!$discountObj->cumulable_reduction and $onlyProductWithDiscount) { return Tools::displayError('This voucher is not valid for marked or reduced products.'); } $total_cart = 0; $categories = Discount::getCategories($discountObj->id); $returnErrorNoProductCategory = true; foreach ($products as $product) { if (count($categories)) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { if (!$discountObj->cumulable_reduction and !$product['reduction_applies'] and !$product['on_sale'] or $discountObj->cumulable_reduction) { $total_cart += $product['total_wt']; } $returnErrorNoProductCategory = false; } } } if (isset($discountObj->brands) && isset($discountObj->min_cart) && $discountObj->min_cart > 0) { $cartTotalForBrands = $this->getCartTotalForBrands($discountObj->brands); if ($cartTotalForBrands < $discountObj->min_cart) { return Tools::displayError('This discount applies to products worth atleast ' . $discountObj->min_cart . ' of specific brands.'); } } if ($returnErrorNoProductCategory) { return Tools::displayError('This discount does not apply to that product category.'); } //conver total to USD $total_cart = Tools::convertPrice($total_cart, $this->id_currency, false); if ($total_cart < $discountObj->minimal) { return Tools::displayError('The order total is not high enough or this voucher cannot be used with those products.'); } return false; }
public function getCategorie($submenu_catids, $context) { $groups = implode(', ', Customer::getGroupsStatic((int) $context->customer->id)); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT DISTINCT c.id_parent, c.id_category, c.level_depth ,cl.name, cl.link_rewrite FROM `' . _DB_PREFIX_ . 'category` c INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $context->language->id . Shop::addSqlRestrictionOnLang('cl') . ') INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $context->shop->id . ') WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ') AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . ' AND c.id_category IN (SELECT id_category FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_group` IN (' . pSQL($groups) . ') AND id_category IN (' . pSQL($submenu_catids) . ')) ORDER BY `level_depth` ASC, cs.`position`'); return $result; }
public function hookFooter($params) { $id_customer = (int) $params['cookie']->id_customer; // Get all groups for this customer and concatenate them as a string: "1,2,3..." $groups = $id_customer ? implode(', ', Customer::getGroupsStatic($id_customer)) : _PS_DEFAULT_CUSTOMER_GROUP_; $id_product = (int) Tools::getValue('id_product', 0); $id_category = (int) Tools::getValue('id_category', 0); $id_lang = (int) $params['cookie']->id_lang; $smartyCacheId = 'blockcategories|' . $this->context->shop->id . '_' . $groups . '_' . $id_lang . '_' . $id_product . '_' . $id_category; $this->context->smarty->cache_lifetime = 31536000; // 1 Year Tools::enableCache(); if (!$this->isCached('blockcategories_footer.tpl', $smartyCacheId)) { $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `' . _DB_PREFIX_ . 'category` c ' . Shop::addSqlAssociation('category', 'c') . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . $id_lang . Shop::addSqlRestrictionOnLang('cl') . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE (c.`active` = 1 OR c.`id_category` = 1) ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' AND cg.`id_group` IN (' . pSQL($groups) . ') ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'category_shop.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')))) { return; } $resultParents = array(); $resultIds = array(); foreach ($result as &$row) { $resultParents[$row['id_parent']][] =& $row; $resultIds[$row['id_category']] =& $row; } //$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMNS_FOOTER'); $nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER'); if (!$nbrColumns) { $nbrColumns = 3; } $numberColumn = abs(count($result) / $nbrColumns); $widthColumn = floor(100 / $nbrColumns); $this->smarty->assign('numberColumn', $numberColumn); $this->smarty->assign('widthColumn', $widthColumn); $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); unset($resultParents, $resultIds); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; if (Tools::isSubmit('id_category')) { $this->context->cookie->last_visited_category = $id_category; $this->smarty->assign('currentCategoryId', $this->context->cookie->last_visited_category); } if (Tools::isSubmit('id_product')) { if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category)))) { $product = new Product($id_product); if (isset($product) && Validate::isLoadedObject($product)) { $this->context->cookie->last_visited_category = (int) $product->id_category_default; } } $this->smarty->assign('currentCategoryId', (int) $this->context->cookie->last_visited_category); } $this->smarty->assign('blockCategTree', $blockCategTree); if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories_footer.tpl')) { $this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl'); } else { $this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl'); } $this->smarty->assign('isDhtml', $isDhtml); } $display = $this->display(__FILE__, 'blockcategories_footer.tpl', $smartyCacheId); Tools::restoreCacheSettings(); return $display; }
public function hookDisplayProductCategories($params) { $this->setLastVisitedCategory(); if (!$this->isCached('blockcategories_tabs.tpl', $this->getCacheId())) { $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); // Get all groups for this customer and concatenate them as a string: "1,2,3..." $groups = implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id)); if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `' . _DB_PREFIX_ . 'category` c ' . Shop::addSqlAssociation('category', 'c') . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_ROOT_CATEGORY') . ') ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' AND cg.`id_group` IN (' . pSQL($groups) . ') ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'category_shop.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')))) { return; } $resultParents = array(); $resultIds = array(); foreach ($result as &$row) { $resultParents[$row['id_parent']][] =& $row; $resultIds[$row['id_category']] =& $row; } //$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMNS_FOOTER'); $nbrColumns = (int) Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER'); if (!$nbrColumns or empty($nbrColumns)) { $nbrColumns = 3; } $numberColumn = abs(count($result) / $nbrColumns); $widthColumn = floor(100 / $nbrColumns); $this->smarty->assign('numberColumn', $numberColumn); $this->smarty->assign('widthColumn', $widthColumn); $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); unset($resultParents, $resultIds); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; $id_category = (int) Tools::getValue('id_category'); $id_product = (int) Tools::getValue('id_product'); $this->smarty->assign('blockCategTree', $blockCategTree); if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories_tabs.tpl')) { $this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl'); } else { $this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl'); } $this->smarty->assign('isDhtml', $isDhtml); } $display = $this->display(__FILE__, 'blockcategories_tabs.tpl', $this->getCacheId()); return $display; }
public function hookHome($params) { if (_THEME_NAME_ != 'prestashop_mobile') { return; } global $smarty, $link; $id_customer = (int) $params['cookie']->id_customer; $id_lang = (int) $params['cookie']->id_lang; $groups = $id_customer ? implode(', ', Customer::getGroupsStatic($id_customer)) : (int) _PS_DEFAULT_CUSTOMER_GROUP_; $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.`id_parent`, c.`id_category`, cl.`name`, cl.`description` as `desc`, cl.`link_rewrite` FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . (int) $id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE (c.`active` = 1 AND c.`id_parent` = 1) ' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . ' AND cg.`id_group` IN (' . pSQL($groups) . ') GROUP BY id_category ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'c.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')); if ($result) { foreach ($result as &$r) { $r['link'] = $link->getCategoryLink((int) $r['id_category'], $r['link_rewrite']); } $smarty->assign('block_category_mobile', $result); } $smarty->assign('meta_title', Configuration::get('PS_SHOP_NAME')); }