public function hookproductnavs() { $id_product = (int) Tools::getValue('id_product'); if (!$id_product) { return true; } $product = new Product($id_product, false, (int) Context::getContext()->language->id); $productInLastVisitedCategory = Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => (int) $this->context->cookie->last_visited_category))); if ((!isset($this->context->cookie->last_visited_category) or !$productInLastVisitedCategory) and Validate::isLoadedObject($product)) { $this->context->cookie->last_visited_category = (int) $product->id_category_default; } $cur_position = $this->getPositionInCategory($id_product, $this->context->cookie->last_visited_category); $nextProductId = $this->getNextInCategory($cur_position, $this->context->cookie->last_visited_category); $prevProductId = $this->getPreviousInCategory($cur_position, $this->context->cookie->last_visited_category); $prevLink = NULL; $prevName = NULL; $nextLink = NULL; $nextName = NULL; if (isset($prevProductId)) { $cat_product = new Product($prevProductId, false, (int) Context::getContext()->language->id); $prevLink = $this->context->link->getProductLink($cat_product); $prevName = $cat_product->name; } if (isset($nextProductId)) { $cat_product = new Product($nextProductId, false, (int) Context::getContext()->language->id); $nextLink = $this->context->link->getProductLink($cat_product); $nextName = $cat_product->name; } $this->context->smarty->assign(array('prevLink' => $prevLink, 'prevName' => $prevName, 'nextLink' => $nextLink, 'nextName' => $nextName)); if ($this->context->cookie->last_visited_category == 2) { $this->context->cookie->last_visited_category = (int) $product->id_category_default; } return $this->display(__FILE__, 'productsnavpn.tpl'); }
public function setLastVisitedCategory() { $cache_id = 'pspagebuilder::setLastVisitedCategory'; $context = Context::getContext(); if (!Cache::isStored($cache_id)) { if (method_exists($context->controller, 'getCategory') && ($category = $context->controller->getCategory())) { $context->cookie->last_visited_category = $category->id; } elseif (method_exists($context->controller, 'getProduct') && ($product = $context->controller->getProduct())) { if (!isset($context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, array(array('id_category' => $context->cookie->last_visited_category))) || !Category::inShopStatic($context->cookie->last_visited_category, $context->shop)) { $context->cookie->last_visited_category = (int) $product->id_category_default; } } Cache::store($cache_id, $context->cookie->last_visited_category); } return Cache::retrieve($cache_id); }
public function init() { parent::init(); $pagerCat = FALSE; if (isset($_SERVER['HTTP_REFERER'])) { $parseQuery = explode('id_category=', $_SERVER['HTTP_REFERER']); if (count($parseQuery) == 2) { $parseQuery[1] = (int) $parseQuery[1]; if ($parseQuery[1]) { $pagerCat = $parseQuery[1]; } } } if ((int) Tools::getValue('pagerCat')) { $pagerCat = (int) Tools::getValue('pagerCat'); } if ($pagerCat) { if (Product::idIsOnCategoryId((int) $this->product->id, array(array('id_category' => $pagerCat)))) { $this->category = new Category($pagerCat, (int) $this->context->cookie->id_lang); } } }
public function process() { global $cart, $currency; parent::process(); if (!Validate::isLoadedObject($this->product)) { $this->errors[] = Tools::displayError('Product not found'); } else { if (!$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) { header('HTTP/1.1 404 page not found'); $this->errors[] = Tools::displayError('Product is no longer available.'); } elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) { $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); if (!$this->product->active) { self::$smarty->assign('adminActionDisplay', true); } /* Product pictures management */ require_once 'images.inc.php'; if ($this->product->customizable) { self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { $this->pictureUpload($this->product, $cart); $this->textRecord($this->product, $cart); $this->formTargetFormat(); } elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture'); } $files = self::$cookie->getFamily('pictures_' . (int) $this->product->id); $textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id); foreach ($textFields as $key => $textField) { $textFields[$key] = str_replace('<br />', "\n", $textField); } self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields)); } /* Features / Values */ $features = $this->product->getFrontFeatures((int) self::$cookie->id_lang); $attachments = $this->product->cache_has_attachments ? $this->product->getAttachments((int) self::$cookie->id_lang) : array(); /* Category */ $category = false; if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) { $category = new Category((int) $regs[2], (int) self::$cookie->id_lang); } } elseif (isset($regs[5]) and is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) { $category = new Category((int) $regs[5], (int) self::$cookie->id_lang); } } } if (!$category) { $category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang); } if (isset($category) and Validate::isLoadedObject($category)) { self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name))); } else { self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name)); } self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();'); if (Pack::isPack((int) $this->product->id) and !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100; $id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0; $id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_; $id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT')); // Tax $tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); self::$smarty->assign('tax_rate', $tax); $productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6); if (Product::$_taxCalculationMethod == PS_TAX_INC) { $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2); } $productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax); $ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) { $ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2); } self::$smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $this->product->id, (int) Shop::getCurrentShop(), (int) self::$cookie->id_currency, $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (double) $tax), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'homeSize' => Image::getSize('home'), 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, self::$cookie->id_lang), 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => (double) $productPriceWithoutEcoTax, 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'group_reduction' => $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_)); self::$smarty->assign(array('HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent'))); $images = $this->product->getImages((int) self::$cookie->id_lang); $productImages = array(); foreach ($images as $k => $image) { if ($image['cover']) { self::$smarty->assign('mainImage', $images[0]); $cover = $image; $cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image']; $cover['id_image_only'] = (int) $image['id_image']; } $productImages[(int) $image['id_image']] = $image; } if (!isset($cover)) { $cover = array('id_image' => Language::getIsoById(self::$cookie->id_lang) . '-default', 'legend' => 'No picture', 'title' => 'No picture'); } $size = Image::getSize('large'); self::$smarty->assign(array('cover' => $cover, 'imgWidth' => (int) $size['width'], 'mediumSize' => Image::getSize('medium'), 'largeSize' => Image::getSize('large'), 'accessories' => $this->product->getAccessories((int) self::$cookie->id_lang))); if (count($productImages)) { self::$smarty->assign('images', $productImages); } /* Attributes / Groups & colors */ $colors = array(); $attributesGroups = $this->product->getAttributesGroups((int) self::$cookie->id_lang); // @todo (RM) should only get groups and not all declination ? if (is_array($attributesGroups) and $attributesGroups) { $groups = array(); $combinationImages = $this->product->getCombinationImages((int) self::$cookie->id_lang); foreach ($attributesGroups as $k => $row) { /* Color management */ if ((isset($row['attribute_color']) and $row['attribute_color'] or file_exists(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) and $row['id_attribute_group'] == $this->product->id_color_default) { $colors[$row['id_attribute']]['value'] = $row['attribute_color']; $colors[$row['id_attribute']]['name'] = $row['attribute_name']; if (!isset($colors[$row['id_attribute']]['attributes_quantity'])) { $colors[$row['id_attribute']]['attributes_quantity'] = 0; } $colors[$row['id_attribute']]['attributes_quantity'] += (int) $row['quantity']; } if (!isset($groups[$row['id_attribute_group']])) { $groups[$row['id_attribute_group']] = array('name' => $row['public_group_name'], 'is_color_group' => $row['is_color_group'], 'default' => -1); } $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) { $groups[$row['id_attribute_group']]['default'] = (int) $row['id_attribute']; } if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) { $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0; } $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int) $row['quantity']; $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = (int) $row['id_attribute']; $combinations[$row['id_product_attribute']]['price'] = (double) $row['price']; $combinations[$row['id_product_attribute']]['ecotax'] = (double) $row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (double) $row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int) $row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; $combinations[$row['id_product_attribute']]['id_image'] = isset($combinationImages[$row['id_product_attribute']][0]['id_image']) ? $combinationImages[$row['id_product_attribute']][0]['id_image'] : -1; } //wash attributes list (if some attributes are unavailables and if allowed to wash it) if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) { foreach ($groups as &$group) { foreach ($group['attributes_quantity'] as $key => &$quantity) { if (!$quantity) { unset($group['attributes'][$key]); } } } foreach ($colors as $key => $color) { if (!$color['attributes_quantity']) { unset($colors[$key]); } } } foreach ($groups as &$group) { natcasesort($group['attributes']); } foreach ($combinations as $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] as $id_attribute) { $attributeList .= '\'' . (int) $id_attribute . '\','; } $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } self::$smarty->assign(array('groups' => $groups, 'combinaisons' => $combinations, 'combinations' => $combinations, 'colors' => (sizeof($colors) and $this->product->id_color_default) ? $colors : false, 'combinationImages' => $combinationImages)); } self::$smarty->assign(array('no_tax' => Tax::excludeTaxeOption() or !Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), 'customizationFields' => $this->product->customizable ? $this->product->getCustomizationFields((int) self::$cookie->id_lang) : false)); // Pack management self::$smarty->assign('packItems', $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, (int) self::$cookie->id_lang, true) : array()); self::$smarty->assign('packs', Pack::getPacksTable($this->product->id, (int) self::$cookie->id_lang, true, 1)); } } self::$smarty->assign(array('ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'categories' => Category::getHomeCategories((int) self::$cookie->id_lang), 'have_image' => isset($cover) ? (int) $cover['id_image'] : false, 'tax_enabled' => Configuration::get('PS_TAX'), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'ecotax' => !sizeof($this->errors) and $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'currencySign' => $currency->sign, 'currencyRate' => $currency->conversion_rate, 'currencyFormat' => $currency->format, 'currencyBlank' => $currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'))); }
public function hookFooter($params) { // Get all groups for this customer and concatenate them as a string: "1,2,3..." if (!$this->isCached('blockcategories_footer.tpl', $this->getCacheId())) { $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); $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` = 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; $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)))) { $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', $this->getCacheId()); return $display; }
public function hookFooter($params) { global $smarty, $cookie; $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|' . $groups . '_' . $id_lang . '_' . $id_product . '_' . $id_category; 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 LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . $id_lang . ') 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`' : 'c.`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(sizeof($result) / $nbrColumns); $widthColumn = floor(100 / $nbrColumns); $smarty->assign('numberColumn', $numberColumn); $smarty->assign('widthColumn', $widthColumn); $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); unset($resultParents); unset($resultIds); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; if (Tools::isSubmit('id_category')) { $cookie->last_visited_category = $id_category; $smarty->assign('currentCategoryId', $cookie->last_visited_category); } if (Tools::isSubmit('id_product')) { if (!isset($cookie->last_visited_category) or !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product($id_product); if (isset($product) and Validate::isLoadedObject($product)) { $cookie->last_visited_category = (int) $product->id_category_default; } } $smarty->assign('currentCategoryId', (int) $cookie->last_visited_category); } $smarty->assign('blockCategTree', $blockCategTree); if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories_footer.tpl')) { $smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl'); } else { $smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl'); } $smarty->assign('isDhtml', $isDhtml); } $smarty->cache_lifetime = 31536000; // 1 Year $display = $this->display(__FILE__, 'blockcategories_footer.tpl', $smartyCacheId); Tools::restoreCacheSettings(); return $display; }
public static function getCartNbPoints($cart, $newProduct = NULL) { $total = 0; if (Validate::isLoadedObject($cart)) { $currentContext = Context::getContext(); $context = clone $currentContext; $context->cart = $cart; // if customer is logged we do not recreate it if (!$context->customer->isLogged(true)) { $context->customer = new Customer($context->cart->id_customer); } $context->language = new Language($context->cart->id_lang); $context->shop = new Shop($context->cart->id_shop); $context->currency = new Currency($context->cart->id_currency, null, $context->shop->id); $categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY_SOURCE'); if ($categories != '' && $categories != 0) { $categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY_SOURCE')); } else { die(Tools::displayError()); } $categories_array = array(); foreach ($categories as $id_category) { array_push($categories_array, array('id_category' => $id_category)); } $cartProducts = $cart->getProducts(); $taxesEnabled = Product::getTaxCalculationMethod(); if (isset($newProduct) and !empty($newProduct)) { $cartProductsNew['id_product'] = (int) $newProduct->id; if ($taxesEnabled == PS_TAX_EXC) { $cartProductsNew['price'] = number_format($newProduct->getPrice(false, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', ''); } else { $cartProductsNew['price_wt'] = number_format($newProduct->getPrice(true, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', ''); } $cartProductsNew['cart_quantity'] = 1; $cartProducts[] = $cartProductsNew; } foreach ($cartProducts as $product) { if (!(int) Configuration::get('PS_LOYALTY_NONE_AWARD') and Product::isDiscounted((int) $product['id_product'])) { if (isset(Context::getContext()->smarty) and is_object($newProduct) and $product['id_product'] == $newProduct->id) { Context::getContext()->smarty->assign('no_pts_discounted', 1); } continue; } /* Avoid generate points for product is not in source category */ if (!Product::idIsOnCategoryId((int) $product['id_product'], $categories_array)) { continue; } $total += ($taxesEnabled == PS_TAX_EXC ? $product['price'] : $product['price_wt']) * (int) $product['cart_quantity']; } foreach ($cart->getCartRules(false) as $cart_rule) { if ($taxesEnabled == PS_TAX_EXC) { $total -= $cart_rule['value_tax_exc']; } else { $total -= $cart_rule['value_real']; } } } return self::getNbPointsByPrice($total); }
/** * Initialize product controller * @see FrontController::init() */ public function init() { parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } else { $this->canonicalRedirection(); } if (!Validate::isLoadedObject($this->product)) { $this->errors[] = Tools::displayError('Product not found'); } else { if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $this->product->description = $this->transformDescriptionWithImg($this->product->description); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active && (Tools::getValue('adtoken') != Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) || !file_exists(_PS_ROOT_DIR_ . '/' . Tools::getValue('ad') . '/index.php'))) { header('HTTP/1.1 404 page not found'); $this->errors[] = Tools::displayError('Product is no longer available.'); } else { if (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) { $this->errors[] = Tools::displayError('You do not have access to this product.'); } } // Load category if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category if (isset($regs[2]) && is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) { $this->category = new Category($regs[2], (int) $this->context->cookie->id_lang); } } else { if (isset($regs[5]) && is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) { $this->category = new Category($regs[5], (int) $this->context->cookie->id_lang); } } } } else { // Set default product category $this->category = new Category($this->product->id_category_default, (int) $this->context->cookie->id_lang); } } }
public function process() { global $cart, $currency; parent::process(); if (!($id_product = (int) Tools::getValue('id_product')) or !Validate::isUnsignedId($id_product)) { $this->errors[] = Tools::displayError('Product not found'); } else { if (!Validate::isLoadedObject($this->product) or !$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) { header('HTTP/1.1 404 page not found'); $this->errors[] = Tools::displayError('Product is no longer available.'); } elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) { $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); if (!$this->product->active) { self::$smarty->assign('adminActionDisplay', true); } /* rewrited url set */ $rewrited_url = self::$link->getProductLink($this->product->id, $this->product->link_rewrite); /* Product pictures management */ require_once 'images.inc.php'; self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { $this->pictureUpload($this->product, $cart); $this->textRecord($this->product, $cart); $this->formTargetFormat(); } elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture'); } $files = self::$cookie->getFamily('pictures_' . (int) $this->product->id); $textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id); foreach ($textFields as $key => $textField) { $textFields[$key] = str_replace('<br />', "\n", $textField); } self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields)); if ((int) Tools::getValue('pp') == 1) { echo 'here1'; } $productPriceWithTax = Product::getPriceStatic($id_product, true, NULL, 6); if (Product::$_taxCalculationMethod == PS_TAX_INC) { $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2); } if ((int) Tools::getValue('pp') == 1) { $time2 = time(); echo 'time2: ' . $time2; } $productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax); $configs = Configuration::getMultiple(array('PS_ORDER_OUT_OF_STOCK', 'PS_LAST_QTIES')); /* Features / Values */ $features = $this->product->getFrontFeatures((int) self::$cookie->id_lang); $attachments = $this->product->getAttachments((int) self::$cookie->id_lang); /* Category */ $category = false; if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) { $category = new Category((int) $regs[2], (int) self::$cookie->id_lang); } } elseif (isset($regs[5]) and is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) { $category = new Category((int) $regs[5], (int) self::$cookie->id_lang); } } } if (!$category) { $category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang); } if (isset($category) and Validate::isLoadedObject($category)) { self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name))); } else { self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name)); } self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();'); $lang = Configuration::get('PS_LANG_DEFAULT'); if (Pack::isPack((int) $this->product->id, (int) $lang) and !Pack::isInStock((int) $this->product->id, (int) $lang)) { $this->product->quantity = 0; } $group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100; $id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0; $id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_; $id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT')); if ((int) Tools::getValue('pp') == 1) { $time3 = time(); echo 'time3: ' . $time3; } // Tax $tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); self::$smarty->assign('tax_rate', $tax); $ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) { $ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2); } $manufacturer = new Manufacturer((int) $this->product->id_manufacturer, 1); $sizechart = new Sizechart((int) $this->product->id_sizechart, 1); //see if the product is already in the wishlist if ($id_customer) { $sql = "select id from ps_wishlist where id_customer = " . $id_customer . " and id_product = " . $this->product->id; $res = Db::getInstance()->ExecuteS($sql); if ($res) { self::$smarty->assign("in_wishlist", true); } else { self::$smarty->assign("in_wishlist", false); } } else { self::$smarty->assign("in_wishlist", false); } self::$smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $this->product->id, (int) Shop::getCurrentShop(), (int) self::$cookie->id_currency, $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (double) $tax), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'homeSize' => Image::getSize('home'), 'product_manufacturer' => $manufacturer, 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => (double) $productPriceWithoutEcoTax, 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) $configs['PS_LAST_QTIES'], 'group_reduction' => $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_, 'sizechart' => $sizechart->sizechart, 'sizechart_data' => $sizechart->sizechart_data)); self::$smarty->assign(array('HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent'))); if ((int) Tools::getValue('pp') == 1) { $time4 = time(); echo 'time4: ' . $time4; } $images = $this->product->getImages((int) self::$cookie->id_lang); $productImages = array(); foreach ($images as $k => $image) { if ($image['cover']) { self::$smarty->assign('mainImage', $images[0]); $cover = $image; $cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image']; $cover['id_image_only'] = (int) $image['id_image']; } $productImages[(int) $image['id_image']] = $image; } if (!isset($cover)) { $cover = array('id_image' => Language::getIsoById(self::$cookie->id_lang) . '-default', 'legend' => 'No picture', 'title' => 'No picture'); } $size = Image::getSize('large'); self::$smarty->assign(array('cover' => $cover, 'imgWidth' => (int) $size['width'], 'mediumSize' => Image::getSize('medium'), 'largeSize' => Image::getSize('large'), 'accessories' => $this->product->getAccessories((int) self::$cookie->id_lang))); if (sizeof($productImages)) { self::$smarty->assign('images', $productImages); } if ((int) Tools::getValue('pp') == 1) { $time5 = time(); echo 'time5: ' . $time5; } /* Attributes / Groups & colors */ $colors = array(); //see if the product has shades if ($this->product->id_group && $this->product->id_group > 0) { global $link; $related_productIds = $this->product->getRelatedProducts(); $related_products = array(); foreach ($related_productIds as &$productId) { $relProduct = new Product((int) $productId['id_product'], true, self::$cookie->id_lang); $idImage = $relProduct->getCoverWs(); if ($idImage) { $idImage = $relProduct->id . '-' . $idImage; } else { $idImage = Language::getIsoById(1) . '-default'; } $relProduct->image_link = $link->getImageLink($relProduct->link_rewrite, $idImage, 'small'); $relProduct->link = $relProduct->getLink(); $related_products[] = $relProduct; } self::$smarty->assign('relatedProducts', $related_products); } if ((int) Tools::getValue('pp') == 1) { $time6 = time(); echo 'time6: ' . $time6; } $attributesGroups = $this->product->getAttributesGroups((int) self::$cookie->id_lang); // @todo (RM) should only get groups and not all declination ? if (is_array($attributesGroups) and $attributesGroups) { $groups = array(); $combinationImages = $this->product->getCombinationImages((int) self::$cookie->id_lang); foreach ($attributesGroups as $k => $row) { /* Color management */ if ((isset($row['attribute_color']) and $row['attribute_color'] or file_exists(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) and $row['id_attribute_group'] == $this->product->id_color_default) { $colors[$row['id_attribute']]['value'] = $row['attribute_color']; $colors[$row['id_attribute']]['name'] = $row['attribute_name']; if (!isset($colors[$row['id_attribute']]['attributes_quantity'])) { $colors[$row['id_attribute']]['attributes_quantity'] = 0; } $colors[$row['id_attribute']]['attributes_quantity'] += (int) $row['quantity']; } if (!isset($groups[$row['id_attribute_group']])) { $groups[$row['id_attribute_group']] = array('name' => $row['public_group_name'], 'is_color_group' => $row['is_color_group'], 'default' => -1); } $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) { $groups[$row['id_attribute_group']]['default'] = (int) $row['id_attribute']; } if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) { $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0; } $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int) $row['quantity']; $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = (int) $row['id_attribute']; $combinations[$row['id_product_attribute']]['price'] = (double) $row['price']; $combinations[$row['id_product_attribute']]['ecotax'] = (double) $row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (double) $row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int) $row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; $combinations[$row['id_product_attribute']]['id_image'] = isset($combinationImages[$row['id_product_attribute']][0]['id_image']) ? $combinationImages[$row['id_product_attribute']][0]['id_image'] : -1; } if ((int) Tools::getValue('pp') == 1) { $time7 = time(); echo 'time7: ' . $time7; } //wash attributes list (if some attributes are unavailables and if allowed to wash it) if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) { foreach ($groups as &$group) { foreach ($group['attributes_quantity'] as $key => &$quantity) { if (!$quantity) { unset($group['attributes'][$key]); } } } foreach ($colors as $key => $color) { if (!$color['attributes_quantity']) { unset($colors[$key]); } } } if ((int) Tools::getValue('pp') == 1) { $time71 = time(); echo 'time71: ' . $time71; } foreach ($groups as &$group) { natcasesort($group['attributes']); } foreach ($combinations as $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] as $id_attribute) { $attributeList .= '\'' . (int) $id_attribute . '\','; } $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } self::$smarty->assign(array('groups' => $groups, 'combinaisons' => $combinations, 'combinations' => $combinations, 'colors' => (sizeof($colors) and $this->product->id_color_default) ? $colors : false, 'combinationImages' => $combinationImages)); } if ((int) Tools::getValue('pp') == 1) { $time72 = time(); echo 'time72: ' . $time72; } //$newProducts = Product::getNewProducts((int)(self::$cookie->id_lang), 0, 10, false, 'date_add', 'desc'); /*$categoryProducts = $this->getRandomCatProducts(); self::$smarty->assign('cat_products', $categoryProducts);*/ //$brandProducts = $this->getRandomBrandProducts(); //self::$smarty->assign('brand_products', $brandProducts); if ((int) Tools::getValue('pp') == 1) { $time73 = time(); echo ' time73: ' . $time73; } self::$smarty->assign(array('no_tax' => Tax::excludeTaxeOption() or !Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), 'customizationFields' => $this->product->getCustomizationFields((int) self::$cookie->id_lang))); if ((int) Tools::getValue('pp') == 1) { $time74 = time(); echo 'time74: ' . $time74; } // Pack management self::$smarty->assign('packItems', $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, (int) self::$cookie->id_lang, true) : array()); self::$smarty->assign('packs', Pack::getPacksTable($this->product->id, (int) self::$cookie->id_lang, true, 1)); if ((int) Tools::getValue('pp') == 1) { print_r('pack done'); } } } if ((int) Tools::getValue('pp') == 1) { $time8 = time(); echo 'time8: ' . $time8; } if ($this->is_saree || $this->is_lehenga) { if ($this->is_lehenga) { self::$smarty->assign('is_lehenga', $this->is_lehenga); } self::$smarty->assign('as_shown', (bool) $this->product->as_shown); /*if($blouse_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 1)) self::$smarty->assign('measurement_info', $blouse_measurements); if($skirt_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 2)) self::$smarty->assign('skirt_measurement_info', $skirt_measurements);*/ if ((int) Tools::getValue('pp') == 1) { $time81 = time(); echo 'time81: ' . $time81; } if ($this->is_saree) { //count of all styles mapped to this product $res = Db::getInstance()->getRow("select count(s.id_style) as style_count from ps_styles s inner join ps_product_style ps on ps.id_style = s.id_style and ps.id_product = {$id_product} and s.style_type = 1"); $style_count = (int) $res['style_count']; if ($style_count === 0) { // show the default style for sarees $style = array('id_style' => 1, 'style_image_small' => '1-small.png', 'style_name' => 'Round'); } else { $res = Db::getInstance()->getRow("select s.id_style, s.style_name, s.style_image_small from ps_styles s inner join ps_product_style ps on ps.id_style = s.id_style and ps.id_product = {$id_product} and s.style_type = 1 and ps.is_default = 1"); if (!empty($res)) { //show the default style for this product $style = array('id_style' => $res['id_style'], 'style_image_small' => $res['style_image_small'], 'style_name' => $res['style_name']); } } if ((int) Tools::getValue('pp') == 1) { $time82 = time(); echo 'time82: ' . $time82; } self::$smarty->assign('blouse_style_count', $style_count); self::$smarty->assign('blouse_style', $style); } } else { if ($this->is_skd || $this->is_skd_rts) { self::$smarty->assign('is_anarkali', $this->is_anarkali); if ($this->is_anarkali) { if ($kurta_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 5)) { self::$smarty->assign('kurta_measurement_info', $kurta_measurements); } } else { if ($kurta_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 3)) { self::$smarty->assign('kurta_measurement_info', $kurta_measurements); } } if ($salwar_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 4)) { self::$smarty->assign('salwar_measurement_info', $salwar_measurements); } //get default styles for this product (RTS) if ($this->is_skd_rts) { $res = Db::getInstance()->ExecuteS("select count(s.id_style) as style_count, s.style_type, ps.id_product from ps_styles s inner join ps_product_style ps on ps.id_style = s.id_style and ps.id_product = {$id_product} group by ps.id_product,s.style_type"); foreach ($res as $s) { $style_count = (int) $s['style_count']; if ((int) $s['style_type'] === 4) { self::$smarty->assign('kurta_style_count', $style_count); } else { if ((int) $s['style_type'] === 5) { self::$smarty->assign('salwar_style_count', $style_count); } } } $res = Db::getInstance()->ExecuteS("select s.id_style, s.style_type, s.style_image_small, s.style_name from ps_styles s inner join ps_product_style ps on ps.id_style = s.id_style and ps.id_product = {$id_product} and ps.is_default = 1"); foreach ($res as $s) { $style = array('id_style' => $s['id_style'], 'style_image_small' => $s['style_image_small'], 'style_name' => $s['style_name']); if ((int) $s['style_type'] === 4) { self::$smarty->assign('kurta_style', $style); } else { if ((int) $s['style_type'] === 5) { self::$smarty->assign('salwar_style', $style); } } } } } } self::$smarty->assign('is_bottoms', $this->is_bottoms); self::$smarty->assign('is_abaya', $this->is_abaya); self::$smarty->assign('is_wristwear', $this->is_wristwear); self::$smarty->assign('is_pakistani_rts', $this->is_pakistani_rts); if ((int) Tools::getValue('pp') == 1) { $time85 = time(); echo 'time85: ' . $time85; } self::$smarty->assign(array('ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'categories' => Category::getHomeCategories((int) self::$cookie->id_lang), 'have_image' => Product::getCover((int) Tools::getValue('id_product')), 'tax_enabled' => Configuration::get('PS_TAX'), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'ecotax' => !sizeof($this->errors) and $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'currencySign' => $currency->sign, 'currencyRate' => $currency->conversion_rate, 'currencyFormat' => $currency->format, 'currencyBlank' => $currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'))); if ((int) Tools::getValue('pp') == 1) { $time9 = time(); echo 'time9: ' . $time9; } //add this to product stats //Tools::captureActivity(PSTAT_VIEWS,$id_product); if ((int) Tools::getValue('pp') == 1) { $time1 = time(); echo 'process end: ' . $time1; } }
date_default_timezone_set($timezone); } /* Category */ $category = false; $cookie = new Cookie('ps'); if (!defined('PS_ADMIN_DIR')) { if (!$category && isset($_GET['id_category'])) { $category = new Category($_GET['id_category'], intval($cookie->id_lang)); } if (!$category && isset($_SERVER['HTTP_REFERER']) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { if (!isset($_GET['id_product']) || Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => intval($regs[2]))))) { $category = new Category(intval($regs[2]), intval($cookie->id_lang)); } } elseif (isset($regs[5]) and is_numeric($regs[5]) && isset($_GET['id_product'])) { if (!isset($_GET['id_product']) || Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => intval($regs[5]))))) { $category = new Category(intval($regs[5]), intval($cookie->id_lang)); } } } if (!$category && isset($_GET['id_product'])) { $product = new Product(intval($_GET['id_product']), true, intval($cookie->id_lang)); $category_ids = array(); foreach (Product::getIndexedCategories($product->id) as $row) { $category_ids[] = $row['id_category']; } $category_id = $product->id_category_default; if (isset($cookie->last_visited_category) && in_array(intval($cookie->last_visited_category), $category_ids)) { $category_id = intval($cookie->last_visited_category); } $category = new Category($category_id, intval($cookie->id_lang));
$productPriceWithTax = Tools::ps_round($productPriceWithTax, 2); } $productPriceWithoutEcoTax = floatval($productPriceWithTax - $product->ecotax); $configs = Configuration::getMultiple(array('PS_ORDER_OUT_OF_STOCK', 'PS_LAST_QTIES')); /* Features / Values */ $features = $product->getFrontFeatures(intval($cookie->id_lang)); $attachments = $product->getAttachments(intval($cookie->id_lang)); /* Category */ $category = false; if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { if (Product::idIsOnCategoryId(intval($product->id), array('0' => array('id_category' => intval($regs[2]))))) { $category = new Category(intval($regs[2]), intval($cookie->id_lang)); } } elseif (isset($regs[5]) and is_numeric($regs[5])) { if (Product::idIsOnCategoryId(intval($product->id), array('0' => array('id_category' => intval($regs[5]))))) { $category = new Category(intval($regs[5]), intval($cookie->id_lang)); } } } if (!$category) { $category = new Category($product->id_category_default, intval($cookie->id_lang)); } if (isset($category) and Validate::isLoadedObject($category)) { $smarty->assign(array('category' => $category, 'subCategories' => $category->getSubCategories(intval($cookie->id_lang), true), 'id_category_current' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)))); } $smarty->assign(array('return_link' => (isset($category->id) and $category->id) ? Tools::safeOutput($link->getCategoryLink($category)) : 'javascript: history.back();', 'path' => (isset($category->id) and $category->id) ? Tools::getFullPath(intval($category->id), $product->name) : Tools::getFullPath(intval($product->id_category_default), $product->name))); $lang = Configuration::get('PS_LANG_DEFAULT'); if (Pack::isPack(intval($product->id), intval($lang)) and !Pack::isInStock(intval($product->id), intval($lang))) { $product->quantity = 0; }
public function setLastVisitedCategory() { if (method_exists($this->context->controller, 'getCategory') && ($category = $this->context->controller->getCategory())) { $this->context->cookie->last_visited_category = $category->id; } elseif (method_exists($this->context->controller, 'getProduct') && ($product = $this->context->controller->getProduct())) { if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, array(array('id_category' => $this->context->cookie->last_visited_category))) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop)) { $this->context->cookie->last_visited_category = (int) $product->id_category_default; } } }
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; }
private function _getCategoryId($id_lang) { $category = false; if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->_getId(), array('0' => array('id_category' => (int) $regs[2])))) { $category = new Category((int) $regs[2], $id_lang); } } elseif (isset($regs[5]) and is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->_getId(), array('0' => array('id_category' => (int) $regs[5])))) { $category = new Category((int) $regs[5], $id_lang); } } } if ($category) { return $category->id; } }
/** * Return discount value * * @param integer $nb_discounts Number of discount currently in cart * @param boolean $order_total_products Total cart products amount * @return mixed Return a float value or '!' if reduction is 'Shipping free' */ function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true) { $totalAmount = 0; if (!$this->cumulable and intval($nb_discounts) > 1) { return 0; } if (!$this->active) { return 0; } if (!$this->quantity) { return 0; } $date_start = strtotime($this->date_from); $date_end = strtotime($this->date_to); if (time() < $date_start or time() > $date_end) { return 0; } $cart = new Cart(intval($idCart)); $products = $cart->getProducts(); $categories = Discount::getCategories(intval($this->id)); $in_category = false; foreach ($products as $product) { if (count($categories)) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { $totalAmount += $useTax ? $product['total_wt'] : $product['total']; } } } $totalAmount += floatval($shipping_fees); if ($this->minimal > 0 and $totalAmount < $this->minimal) { return 0; } switch ($this->id_discount_type) { case 1: // % on order $amount = 0; $percentage = $this->value / 100; foreach ($products as $product) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { $amount += ($useTax ? $product['total_wt'] : $product['total']) * $percentage; } } return $amount; case 2: // amount foreach ($products as $product) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { $in_category = true; break; } } return $in_category ? $this->value : 0; case 3: // Shipping is free return '!'; } return 0; }
/** * Initialize product controller * @see FrontController::init() */ public function init() { if (Tools::getValue('product_rewrite')) { $rewrite_url = Tools::getValue('product_rewrite'); $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `link_rewrite` = \'' . $rewrite_url . '\''); if ($id_product > 0) { $_GET['id_product'] = $id_product; $_GET['noredirect'] = 1; } else { $redirect_url = str_replace('.html', '', $_SERVER['REQUEST_URI']); $redirect_type = Configuration::get('PS_CANONICAL_REDIRECT') == 2 ? '301' : '302'; header('HTTP/1.0 ' . $redirect_type . ' Moved'); header('Cache-Control: no-cache'); Tools::redirectLink('http://' . $_SERVER['HTTP_HOST'] . $redirect_url); Tools::display404Error(); die; } } parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('Product not found'); } else { $this->canonicalRedirection(); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active) { if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) { // If the product is not active, it's the admin preview mode $this->context->smarty->assign('adminActionDisplay', true); } else { $this->context->smarty->assign('adminActionDisplay', false); if ($this->product->id_product_redirected == $this->product->id) { $this->product->redirect_type = '404'; } switch ($this->product->redirect_type) { case '301': header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '302': header('HTTP/1.1 302 Moved Temporarily'); header('Cache-Control: no-cache'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '404': default: header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('This product is no longer available.'); break; } } } elseif (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { // Load category $id_category = false; if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) && preg_match('~^.*(?<!\\/content)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category $id_object = false; if (isset($regs[1]) && is_numeric($regs[1])) { $id_object = (int) $regs[1]; } elseif (isset($regs[5]) && is_numeric($regs[5])) { $id_object = (int) $regs[5]; } if ($id_object) { $referers = array($_SERVER['HTTP_REFERER'], urldecode($_SERVER['HTTP_REFERER'])); if (in_array($this->context->link->getCategoryLink($id_object), $referers)) { $id_category = (int) $id_object; } elseif (isset($this->context->cookie->last_visited_category) && (int) $this->context->cookie->last_visited_category && in_array($this->context->link->getProductLink($id_object), $referers)) { $id_category = (int) $this->context->cookie->last_visited_category; } } } if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => $id_category)))) { $id_category = (int) $this->product->id_category_default; } if (Category::inDecor($id_category) && !$this->ajax && strpos($_SERVER['SERVER_NAME'], 'decor') <= -1) { $final_url = $this->context->link->getProductLink($this->product); $redirect_type = Configuration::get('PS_CANONICAL_REDIRECT') == 2 ? '301' : '302'; header('HTTP/1.0 ' . $redirect_type . ' Moved'); header('Cache-Control: no-cache'); Tools::redirectLink($final_url); } $this->category = new Category((int) $id_category, (int) $this->context->cookie->id_lang); if (isset($this->context->cookie) && isset($this->category->id_category) && !(Module::isInstalled('blockcategories') && Module::isEnabled('blockcategories'))) { $this->context->cookie->last_visited_category = (int) $this->category->id_category; } } } }
/** * Initialize product controller * @see FrontController::init() */ public function init() { parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('Product not found'); } else { $this->canonicalRedirection(); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active) { if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee'))) { // If the product is not active, it's the admin preview mode $this->context->smarty->assign('adminActionDisplay', true); } else { $this->context->smarty->assign('adminActionDisplay', false); if ($this->product->id_product_redirected == $this->product->id) { $this->product->redirect_type = '404'; } switch ($this->product->redirect_type) { case '301': header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '302': header('HTTP/1.1 302 Moved Temporarily'); header('Cache-Control: no-cache'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '404': default: header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('This product is no longer available.'); break; } } } elseif (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { // Load category if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category if (isset($regs[2]) && is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) { $this->category = new Category($regs[2], (int) $this->context->cookie->id_lang); } } else { if (isset($regs[5]) && is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) { $this->category = new Category($regs[5], (int) $this->context->cookie->id_lang); } } } } else { // Set default product category $this->category = new Category($this->product->id_category_default, (int) $this->context->cookie->id_lang); } } } }
function hookLeftColumn($params) { global $smarty, $cookie; /* ONLY FOR THEME OLDER THAN v1.0 */ global $link; $smarty->assign(array('categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true), 'link' => $link)); /* ELSE */ $id_customer = intval($params['cookie']->id_customer); $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (!($result = Db::getInstance()->ExecuteS(' SELECT DISTINCT c.*, cl.* FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . intval($params['cookie']->id_lang) . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE 1' . (intval($maxdepth) != 0 ? ' AND `level_depth` <= ' . intval($maxdepth) : '') . ' AND (c.`active` = 1 OR c.`id_category`= 1) AND cg.`id_group` ' . (!$cookie->id_customer ? '= 1' : 'IN (SELECT id_group FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . intval($cookie->id_customer) . ')') . ' ORDER BY `level_depth` ASC, cl.`name` ASC'))) { return; } $resultParents = array(); $resultIds = array(); foreach ($result as $row) { ${$row}['name'] = Category::hideCategoryPosition($row['name']); $resultParents[$row['id_parent']][] = $row; $resultIds[$row['id_category']] = $row; } $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; if (isset($_GET['id_category'])) { $cookie->last_visited_category = intval($_GET['id_category']); $smarty->assign('currentCategoryId', intval($_GET['id_category'])); } if (isset($_GET['id_product'])) { if (!isset($cookie->last_visited_category) or !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) and Validate::isLoadedObject($product)) { $cookie->last_visited_category = intval($product->id_category_default); } } $smarty->assign('currentCategoryId', intval($cookie->last_visited_category)); } $smarty->assign('blockCategTree', $blockCategTree); if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories.tpl')) { $smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl'); } else { $smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl'); } $smarty->assign('isDhtml', $isDhtml); /* /ONLY FOR THEME OLDER THAN v1.0 */ return $this->display(__FILE__, 'blockcategories.tpl'); }
private function makeMegaDrown() { $IdLang = $this->context->cookie->id_lang; if (Tools::getIsset('id_category')) { $ActiveCategory = (int) Tools::getValue('id_category'); } else { $ActiveCategory = null; } if (Tools::getIsset('id_product')) { if (!isset($this->context->cookie->last_visited_category) or !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $this->context->cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) and Validate::isLoadedObject($product)) { $ActiveCategory = (int) $product->id_category_default; } } else { $ActiveCategory = (int) $this->context->cookie->last_visited_category; } } if ($ActiveCategory !== null) { $resultCat = Db::getInstance()->ExecuteS(' SELECT * FROM ' . _DB_PREFIX_ . 'admevo_button_link_cat WHERE id_link_cat=' . $ActiveCategory); } $MDParameters = $this->getParameters(); $MDConfiguration = $this->getConfigurations(); if (sizeof($MDConfiguration)) { foreach ($MDConfiguration as $kButton => $ValButton) { $tabLinkButton[$ValButton['id_button']] = array(); $tabIdLinkCat[$ValButton['id_button']] = array(); $tabLinkCustom[$ValButton['id_button']] = array(); $CatMenu = array(); $CatMenu = $this->getButtonLinksCat($ValButton['id_button']); $LinkButton = $this->getButtonLinks($ValButton['id_button']); if (array_key_exists(0, $LinkButton)) { $linkButton = $LinkButton[0]['link']; } else { $linkButton = ""; } $tabLinkButton[$ValButton['id_button']][] = basename($linkButton); if (sizeof($CatMenu)) { foreach ($CatMenu as $kMenu => $ValCat) { $tabIdLinkCat[$ValButton['id_button']][$ValCat['id_link_cat']] = $ValCat['id_link_cat']; $DescendantCateogries = Db::getInstance()->ExecuteS(' SELECT * FROM ' . _DB_PREFIX_ . 'category WHERE id_parent=' . $ValCat['id_link_cat']); if (sizeof($DescendantCateogries)) { foreach ($DescendantCateogries as $kDescCat => $ValDescCat) { $tabIdLinkCat[$ValButton['id_button']][$ValDescCat['id_category']] = $ValDescCat['id_category']; } } } } $CustomMenu = array(); $CustomMenu = $this->getButtonLinksCustom($ValButton['id_button'], $this->context->cookie->id_lang); if (sizeof($CustomMenu)) { foreach ($CustomMenu as $kMenu => $ValMenu) { $tabLinkCustom[$ValButton['id_button']][$ValMenu['id_custom']] = basename($ValMenu['link']); $CustomMenuUnder = array(); $CustomMenuUnder = $this->getButtonLinksCustomUnder($ValButton['id_button'], $ValMenu['id_custom'], $this->context->cookie->id_lang); if (sizeof($CustomMenuUnder)) { foreach ($CustomMenuUnder as $kDescCustom => $ValDescCustom) { $tabLinkCustom[$ValButton['id_button']][$ValDescCustom['id_custom']] = basename($ValDescCustom['link']); } } } } } } if (sizeof($MDConfiguration)) { $b = 0; foreach ($MDConfiguration as $kButton => $ValButton) { $LinkButton = $this->getButtonLinks($ValButton['id_button']); !array_key_exists(0, $LinkButton) ? $linkButton = "#" : ($linkButton = $LinkButton[0]['link']); $this->_menu .= '<li style="background-color: #' . $ValButton['buttonColor'] . '" class="liBouton liBouton' . $b . '">' . $this->eol; strpos(strtolower($ValButton['name_button']), "<br />") ? $decal = "margin-top : -5px;" : ($decal = ""); $this->_menu .= '<div' . ($decal != 0 ? ' style="' . $decal . '"' : '') . '><a href="' . $linkButton . '" ' . ($linkButton == "#" ? "onclick='return false'" : false) . ' class="buttons" ' . (in_array($ActiveCategory, $tabIdLinkCat[$ValButton['id_button']]) || in_array(basename($_SERVER['REQUEST_URI']), $tabLinkCustom[$ValButton['id_button']]) || in_array(basename($_SERVER['REQUEST_URI']), $tabLinkButton[$ValButton['id_button']]) ? 'style="background-position : 0 -' . $MDParameters[0]['MenuHeight'] . 'px; color: #' . $MDParameters[0]['ColorFontMenuHover'] . '"' : false) . '>' . $ValButton['name_button'] . '</a></div>' . $this->eol; $CatMenu = array(); $CatMenu = $this->getButtonLinksCat($ValButton['id_button']); $CustomMenu = array(); $CustomMenu = $this->getButtonLinksCustom($ValButton['id_button'], $this->context->cookie->id_lang); $NbColsMax = $this->getMaxColumns($ValButton['id_button']); $MaxCols = 0; $MaxLines = 0; $tabLines = array(); $m = 0; if (sizeof($CatMenu)) { foreach ($CatMenu as $kMenu => $ValCat) { $tabLines[$kButton][$ValCat['num_ligne']] = $ValCat['num_ligne']; $tabLinesOrder[$kButton][$ValCat['num_ligne']][$ValCat['num_column']] = $ValCat['num_column']; $tabLinesDatas[$kButton][$ValCat['num_ligne']][$ValCat['num_column']][$m] = $ValCat; $tabLinesType[$kButton][$ValCat['num_ligne']][$ValCat['num_column']][$m] = 'category'; $tabColumn[$kButton][$ValCat['num_ligne']] = $ValCat['num_column']; $tabColumnOrder[$kButton][$ValCat['num_column']][$ValCat['num_ligne']] = $ValCat['num_ligne']; $tabColumnDatas[$kButton][$ValCat['num_column']][$ValCat['num_ligne']][$m] = $ValCat; $tabColumnType[$kButton][$ValCat['num_column']][$ValCat['num_ligne']][$m] = 'category'; $m++; $MaxCols < $ValCat['num_column'] * 1 ? $MaxCols = $ValCat['num_column'] : false; $MaxLines < $ValCat['num_ligne'] * 1 ? $MaxLines = $ValCat['num_ligne'] : false; } } if (sizeof($CustomMenu)) { foreach ($CustomMenu as $kCustom => $ValCustom) { $tabLines[$kButton][$ValCustom['num_ligne']] = $ValCustom['num_ligne']; $tabLinesOrder[$kButton][$ValCustom['num_ligne']][$ValCustom['num_column']] = $ValCustom['num_column']; $tabLinesDatas[$kButton][$ValCustom['num_ligne']][$ValCustom['num_column']][$m] = $ValCustom; $tabLinesType[$kButton][$ValCustom['num_ligne']][$ValCustom['num_column']][$m] = 'custom'; $tabColumn[$kButton][$ValCustom['num_ligne']] = $ValCustom['num_column']; $tabColumnOrder[$kButton][$ValCustom['num_column']][$ValCustom['num_ligne']] = $ValCustom['num_ligne']; $tabColumnDatas[$kButton][$ValCustom['num_column']][$ValCustom['num_ligne']][$m] = $ValCustom; $tabColumnType[$kButton][$ValCustom['num_column']][$ValCustom['num_ligne']][$m] = 'custom'; $m++; $MaxCols < $ValCustom['num_column'] * 1 ? $MaxCols = $ValCustom['num_column'] : false; $MaxLines < $ValCustom['num_ligne'] * 1 ? $MaxLines = $ValCustom['num_ligne'] : false; } } if (array_key_exists($kButton, $tabLines)) { if (sizeof($tabLines[$kButton])) { $this->_menu .= '<div class="sub" style="width: ' . ($MDParameters[0]['MenuWidth'] - 2) . 'px; background-color: #' . $ValButton['buttonColor'] . '; ' . ($ValButton['img_name_background'] != "" ? 'background-image: url(' . $this->_path . 'views/img/menu/' . $ValButton['img_name_background'] . '); background-repeat:no-repeat; background-position:top left; ' : false) . ' ">' . $this->eol; $this->_menu .= '<table class="megaDrownTable" cellpadding="0" cellspacing="0" width="100%">'; if ($MDParameters[0]['stateTR1'] == "on") { $this->_menu .= '<tr style="height:' . $MDParameters[0]['heightTR1'] . 'px">'; $MDParameters[0]['stateTD1'] == "on" ? $nbColspan = 2 : ($nbColspan = 1); $this->_menu .= '<td class="megaDrownTR1" valign="top" colspan="' . $nbColspan . '">' . $this->eol; $this->_menu .= $ValButton['detailSubTR'] == "" ? " " : html_entity_decode($ValButton['detailSubTR']); $this->_menu .= '</td>'; $this->_menu .= '<td rowspan="2" class="megaDrownTD3" valign="top" style="width:' . $MDParameters[0]['widthTD3'] . 'px">' . ($ValButton['detailSub'] == "" ? " " : html_entity_decode($ValButton['detailSub'])) . '</td>' . $this->eol; $this->_menu .= '</tr>'; } $this->_menu .= '<tr>'; if ($MDParameters[0]['stateTD1'] == "on") { $this->_menu .= '<td class="megaDrownTD1" valign="top" style="width:' . $MDParameters[0]['widthTD1'] . 'px">' . $this->eol; if ($ValButton['img_name'] != '') { if ($ValButton['img_link'] != '') { $this->_menu .= '<a href="' . urldecode($ValButton['img_link']) . '" style="float:none; margin:0; padding:0">'; } $this->_menu .= '<img src="' . $this->_path . 'views/img/menu/' . $ValButton['img_name'] . '" style="border:0px" alt="' . $ValButton['img_name'] . '"/>' . $this->eol; if ($ValButton['img_link'] != '') { $this->_menu .= '</a>'; } } $this->_menu .= '<br />' . html_entity_decode($ValButton['detailSubLeft']) . '</td>'; } $this->_menu .= '<td class="megaDrownTD2" valign="top">' . $this->eol; $this->_menu .= '<table class="MegaEvoLinks" style="border:0px">' . $this->eol; $this->_menu .= '<tr>' . $this->eol; for ($c = 1; $c <= $MaxCols; $c++) { $this->_menu .= '<td valign="top" class="col' . $c . '">' . $this->eol; for ($l = 1; $l <= $MaxLines; $l++) { if (array_key_exists($c, $tabColumnDatas[$kButton])) { if (array_key_exists($l, $tabColumnDatas[$kButton][$c])) { if (sizeof(@$tabColumnDatas[$kButton][$c][$l])) { $this->_menu .= '<table border="0" style="width:' . $MDParameters[0]['columnSize'] . 'px">' . $this->eol; foreach ($tabColumnDatas[$kButton][$c][$l] as $keyMenu => $ValMenu) { $this->_menu .= '<tr>' . $this->eol; $this->_menu .= '<td style="width:' . $MDParameters[0]['columnSize'] . 'px" class="ligne' . $l . '">' . $this->eol; switch ($tabColumnType[$kButton][$c][$l][$keyMenu]) { case 'category': $category = new Category((int) $ValMenu['id_link_cat']); if (!$category->checkAccess($this->context->customer->id)) { break; } else { $this->_menu .= '<ul>' . $this->eol; $NameCategory = $this->getNameCategory($ValMenu['id_link_cat'], $this->context->cookie->id_lang, $ValButton['id_button']); $NameSubstitute = $this->getNameSubstitute($ValMenu['id_link_cat'], $this->context->cookie->id_lang, $ValButton['id_button']); $Category = new Category(intval($ValMenu['id_link_cat']), intval($this->context->cookie->id_lang)); $rewrited_url = $this->link->getCategoryLink($ValMenu['id_link_cat'], $Category->link_rewrite); $this->_menu .= ' <li class="stitle"> <a href="' . $rewrited_url . '" style="text-align:left">' . (trim($NameSubstitute[0]['name_substitute']) != '' ? $NameSubstitute[0]['name_substitute'] : $NameCategory[0]['name']) . '</a> </li>' . $this->eol; if ($ValMenu['view_products'] != 'on') { $NameCategoryUnder = array(); $NameCategoryUnder = $this->getNameCategoryUnder($ValMenu['id_link_cat'], $ValButton['id_button']); if (sizeof($NameCategoryUnder)) { foreach ($NameCategoryUnder as $KUnderCat => $ValUnderCat) { $Category = new Category(intval($ValUnderCat['id_category']), intval($this->context->cookie->id_lang)); if ($Category->checkAccess($this->context->customer->id)) { $rewrited_url = $this->link->getCategoryLink($ValUnderCat['id_category'], $Category->link_rewrite); $NameCategoryUnder = $this->getNameCategory($ValUnderCat['id_category'], $this->context->cookie->id_lang, $ValButton['id_button']); $NameSubstitute = $this->getNameSubstitute($ValUnderCat['id_category'], $this->context->cookie->id_lang, $ValButton['id_button']); $this->_menu .= ' <li> <a href="' . $rewrited_url . '" style="text-align:left">' . (trim($NameSubstitute[0]['name_substitute']) != '' ? $NameSubstitute[0]['name_substitute'] : $NameCategoryUnder[0]['name']) . ' </a> </li>' . $this->eol; } } } } else { $NameProductsUnder = array(); $NameProductsUnder = $this->getProductsUnder($ValMenu['id_link_cat'], $this->context->cookie->id_lang, $this->context->shop->id); if (sizeof($NameProductsUnder)) { foreach ($NameProductsUnder as $KUnderProd => $ValUnderProd) { $Products = new Product(intval($ValUnderProd['id_product']), true, intval($this->context->cookie->id_lang)); $rewrited_url = $Products->getLink(); $NameProduct = $Products->name; $this->_menu .= '<li><a href="' . $rewrited_url . '" style="text-align:left">' . (strlen($NameProduct) > 20 ? substr($NameProduct, 0, 40) . "..." : $NameProduct) . '</a></li>' . $this->eol; } } } $this->_menu .= '</ul>' . $this->eol; } break; case 'custom': $this->_menu .= '<ul>' . $this->eol; $this->_menu .= '<li class="stitle"><a href="' . $ValMenu['link'] . '" ' . ($ValMenu['link'] == "#" || $ValMenu['link'] == "" ? "onclick='return false'" : false) . ' style="text-align:left">' . $ValMenu['name_menu'] . '</a></li>' . $this->eol; $NameLinkUnder = array(); $NameLinkUnder = $this->getButtonLinksCustomUnder($ValButton['id_button'], $ValMenu['id_custom'], $this->context->cookie->id_lang); if (sizeof($NameLinkUnder)) { foreach ($NameLinkUnder as $KUnderLink => $ValUnderLink) { $this->_menu .= '<li><a href="' . $ValUnderLink['link'] . '" ' . ($ValUnderLink['link'] == "#" || $ValUnderLink['link'] == "" ? "onclick='return false'" : false) . ' style="text-align:left">' . $ValUnderLink['name_menu'] . '</a></li>' . $this->eol; } } $this->_menu .= '</ul>' . $this->eol; break; } $this->_menu .= '</td>' . $this->eol; $this->_menu .= '</tr>' . $this->eol; } $this->_menu .= '</table>' . $this->eol; } } } } $this->_menu .= '</td>' . $this->eol; } $this->_menu .= '</tr>' . $this->eol; $this->_menu .= '</table>' . $this->eol; $this->_menu .= '</td>' . $this->eol; //Colonne droite; if ($MDParameters[0]['stateTD3'] == "on" && $MDParameters[0]['stateTR1'] != "on") { $this->_menu .= '<td class="megaDrownTD3" valign="top" style="width:' . $MDParameters[0]['widthTD3'] . 'px">' . ($ValButton['detailSub'] == "" ? " " : html_entity_decode($ValButton['detailSub'])) . '</td>' . $this->eol; } $this->_menu .= '</tr></table></div>' . $this->eol; } } $this->_menu .= '</li>' . $this->eol; $b++; } } }
function prepareDisplay($params) { global $smarty, $cookie; /* ONLY FOR THEME OLDER THAN v1.0 */ global $link; $smarty->assign(array('categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true), 'link' => $link)); /* ELSE */ $id_customer = intval($params['cookie']->id_customer); $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); if (!($result = Db::getInstance()->ExecuteS(' SELECT DISTINCT c.*, cl.* FROM `' . _DB_PREFIX_ . 'category` c LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . intval($params['cookie']->id_lang) . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_group` ctg ON (ctg.`id_category` = c.`id_category`) ' . ($id_customer ? 'INNER JOIN `' . _DB_PREFIX_ . 'customer_group` cg ON (cg.`id_group` = ctg.`id_group` AND cg.`id_customer` = ' . intval($id_customer) . ')' : '') . ' WHERE 1' . (intval($maxdepth) != 0 ? ' AND `level_depth` <= ' . intval($maxdepth) : '') . ' AND (c.`active` = 1 OR c.`id_category`= 1) ' . (!$id_customer ? 'AND ctg.`id_group` = 1' : '') . ' ORDER BY `level_depth` ASC, cl.`name` ASC'))) { return; } $resultParents = array(); $resultIds = array(); foreach ($result as $row) { ${$row}['name'] = Category::hideCategoryPosition($row['name']); $resultParents[$row['id_parent']][] = $row; $resultIds[$row['id_category']] = $row; } $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; if (isset($_GET['id_category'])) { $cookie->last_visited_category = intval($_GET['id_category']); } if (isset($_GET['id_product'])) { if (!isset($cookie->last_visited_category) or !Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product(intval($_GET['id_product'])); if (isset($product) and Validate::isLoadedObject($product)) { $cookie->last_visited_category = intval($product->id_category_default); } } } if (isset($cookie->last_visited_category)) { $smarty->assign('currentCategoryId', $cookie->last_visited_category); $smarty->assign('currentCategoryPath', array_reverse($this->findCurrentCategoryPath($blockCategTree, $cookie->last_visited_category))); } $smarty->assign('blockCategTree', $blockCategTree); $smarty->assign('isDhtml', $isDhtml); /* /ONLY FOR THEME OLDER THAN v1.0 */ }
/** * Initialize product controller * @see FrontController::init() */ public function init() { parent::init(); //by webkul for product page searching if (Tools::isSubmit('product_page_search_submit')) { $hotel_cat_id = Tools::getValue('hotel_cat_id'); $check_in = Tools::getValue('check_in_time'); $check_out = Tools::getValue('check_out_time'); $error = false; if ($hotel_cat_id == '') { $error = 1; } elseif ($check_in == '' || !Validate::isDate($check_in)) { $error = 1; } elseif ($check_out == '' || !Validate::isDate($check_out)) { $error = 1; } elseif ($check_out <= $check_in) { $error = 1; } if (!$error) { if (Configuration::get('PS_REWRITING_SETTINGS')) { $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '?date_from=' . $check_in . '&date_to=' . $check_out; } else { $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '&date_from=' . $check_in . '&date_to=' . $check_out; } } else { $id_product = Tools::getValue("id_product"); if (Configuration::get('PS_REWRITING_SETTINGS')) { $redirect_link = $this->context->link->getCategoryLink(new Category($hotel_cat_id, $this->context->language->id), null, $this->context->language->id) . '?error=' . $error; } else { $redirect_link = $this->context->link->getProductLink(new Product($id_product, false, $this->context->language->id), null, null, null, $this->context->language->id) . '&error=' . $error; } } Tools::redirect($redirect_link); } //by webkul to check available rooms quantity on product page $product_quantity_up = Tools::getValue('product_quantity_up'); $product_quantity_down = Tools::getValue('product_quantity_down'); $change_date = Tools::getValue('change_date'); if (isset($product_quantity_down) && $product_quantity_down) { $id_product = Tools::getValue('id_product'); $date_from = Tools::getValue('date_from'); $date_to = Tools::getValue('date_to'); $quantity = Tools::getValue('qty'); $result = $this->checkRoomQuantityAvailability($id_product, $date_from, $date_to, $quantity); die($result); } else { if (isset($product_quantity_up) && $product_quantity_up) { $id_product = Tools::getValue('id_product'); $date_from = Tools::getValue('date_from'); $date_to = Tools::getValue('date_to'); $quantity = Tools::getValue('qty'); $result = $this->checkRoomQuantityAvailability($id_product, $date_from, $date_to, $quantity); die($result); } else { if (isset($change_date) && $change_date) { $id_product = Tools::getValue('id_product'); $date_from = Tools::getValue('date_from'); $date_to = Tools::getValue('date_to'); $quantity = Tools::getValue('qty'); $result = $this->checkRoomQuantityAvailability($id_product, $date_from, $date_to, $quantity); die($result); } } } // // by webkul to delete cart rooms individually // $delete_room_from_current_cart = Tools::getValue('delete_room_from_cart'); // if (isset($delete_room_from_current_cart) && $delete_room_from_current_cart) // { // //code for // } if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('Product not found'); } else { $this->canonicalRedirection(); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active) { if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) { // If the product is not active, it's the admin preview mode $this->context->smarty->assign('adminActionDisplay', true); } else { $this->context->smarty->assign('adminActionDisplay', false); if (!$this->product->id_product_redirected || $this->product->id_product_redirected == $this->product->id) { $this->product->redirect_type = '404'; } switch ($this->product->redirect_type) { case '301': header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); exit; break; case '302': header('HTTP/1.1 302 Moved Temporarily'); header('Cache-Control: no-cache'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); exit; break; case '404': default: header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('This product is no longer available.'); break; } } } elseif (!$this->product->checkAccess(isset($this->context->customer->id) && $this->context->customer->id ? (int) $this->context->customer->id : 0)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { // Load category $id_category = false; if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) && preg_match('~^.*(?<!\\/content)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category $id_object = false; if (isset($regs[1]) && is_numeric($regs[1])) { $id_object = (int) $regs[1]; } elseif (isset($regs[5]) && is_numeric($regs[5])) { $id_object = (int) $regs[5]; } if ($id_object) { $referers = array($_SERVER['HTTP_REFERER'], urldecode($_SERVER['HTTP_REFERER'])); if (in_array($this->context->link->getCategoryLink($id_object), $referers)) { $id_category = (int) $id_object; } elseif (isset($this->context->cookie->last_visited_category) && (int) $this->context->cookie->last_visited_category && in_array($this->context->link->getProductLink($id_object), $referers)) { $id_category = (int) $this->context->cookie->last_visited_category; } } } if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => $id_category)))) { $id_category = (int) $this->product->id_category_default; } $this->category = new Category((int) $id_category, (int) $this->context->cookie->id_lang); if (isset($this->context->cookie) && isset($this->category->id_category) && !(Module::isInstalled('blockcategories') && Module::isEnabled('blockcategories'))) { $this->context->cookie->last_visited_category = (int) $this->category->id_category; } } } }
/** * @param Discount $discountObj * @return bool * @deprecated */ public function hasProductInCategory($discountObj) { Tools::displayAsDeprecated(); $products = $this->getProducts(); $categories = Discount::getCategories($discountObj->id); foreach ($products as $product) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { return true; } } return false; }
public function hookLeftColumn($params) { global $smarty, $cookie; $id_customer = (int) $params['cookie']->id_customer; $id_group = $id_customer ? Customer::getDefaultGroupId($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|' . $id_group . '_' . $id_lang . '_' . $id_product . '_' . $id_category; Tools::enableCache(); if (!$this->isCached('blockcategories.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 LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . $id_lang . ') 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` = ' . $id_group . ' ORDER BY `level_depth` ASC, c.`position` 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); unset($resultIds); $isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false; if (Tools::isSubmit('id_category')) { $cookie->last_visited_category = $id_category; $smarty->assign('currentCategoryId', $cookie->last_visited_category); } if (Tools::isSubmit('id_product')) { if (!isset($cookie->last_visited_category) or !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category)))) { $product = new Product($id_product); if (isset($product) and Validate::isLoadedObject($product)) { $cookie->last_visited_category = (int) $product->id_category_default; } } $smarty->assign('currentCategoryId', (int) $cookie->last_visited_category); } $smarty->assign('blockCategTree', $blockCategTree); if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories.tpl')) { $smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl'); } else { $smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl'); } $smarty->assign('isDhtml', $isDhtml); } $smarty->cache_lifetime = 31536000; // 1 Year $display = $this->display(__FILE__, 'blockcategories.tpl', $smartyCacheId); Tools::restoreCacheSettings(); return $display; }
/** * Initialize product controller * @see FrontController::init() */ public function init() { parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('Product not found'); } else { $this->canonicalRedirection(); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active) { if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) { // If the product is not active, it's the admin preview mode $this->context->smarty->assign('adminActionDisplay', true); } else { $this->context->smarty->assign('adminActionDisplay', false); if (!$this->product->id_product_redirected || $this->product->id_product_redirected == $this->product->id) { $this->product->redirect_type = '404'; } switch ($this->product->redirect_type) { case '301': header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); exit; break; case '302': header('HTTP/1.1 302 Moved Temporarily'); header('Cache-Control: no-cache'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); exit; break; case '404': default: header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('This product is no longer available.'); break; } } } elseif (!$this->product->checkAccess(isset($this->context->customer->id) && $this->context->customer->id ? (int) $this->context->customer->id : 0)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { // Load category $id_category = false; if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) && preg_match('~^.*(?<!\\/content)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category $id_object = false; if (isset($regs[1]) && is_numeric($regs[1])) { $id_object = (int) $regs[1]; } elseif (isset($regs[5]) && is_numeric($regs[5])) { $id_object = (int) $regs[5]; } if ($id_object) { $referers = array($_SERVER['HTTP_REFERER'], urldecode($_SERVER['HTTP_REFERER'])); if (in_array($this->context->link->getCategoryLink($id_object), $referers)) { $id_category = (int) $id_object; } elseif (isset($this->context->cookie->last_visited_category) && (int) $this->context->cookie->last_visited_category && in_array($this->context->link->getProductLink($id_object), $referers)) { $id_category = (int) $this->context->cookie->last_visited_category; } } } if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => $id_category)))) { $id_category = (int) $this->product->id_category_default; } $this->category = new Category((int) $id_category, (int) $this->context->cookie->id_lang); if (isset($this->context->cookie) && isset($this->category->id_category) && !(Module::isInstalled('blockcategories') && Module::isEnabled('blockcategories'))) { $this->context->cookie->last_visited_category = (int) $this->category->id_category; } } } }
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; }
/** * Return discount value * * @param integer $nb_discounts Number of discount currently in cart * @param boolean $order_total_products Total cart products amount * @return mixed Return a float value or '!' if reduction is 'Shipping free' */ public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true) { $totalAmount = 0; $cart = new Cart((int) $idCart); if (!Validate::isLoadedObject($cart)) { return 0; } if (!$this->cumulable and (int) $nb_discounts > 1 or !$this->active or !$this->quantity and !$cart->OrderExists()) { return 0; } if ($this->usedByCustomer((int) $cart->id_customer) >= $this->quantity_per_user and !$cart->OrderExists()) { return 0; } $date_start = strtotime($this->date_from); $date_end = strtotime($this->date_to); if ((time() < $date_start or time() > $date_end) and !$cart->OrderExists()) { return 0; } $products = $cart->getProducts(); $categories = Discount::getCategories((int) $this->id); foreach ($products as $product) { if (count($categories) and Product::idIsOnCategoryId($product['id_product'], $categories)) { $totalAmount += $this->include_tax ? $product['total_wt'] : $product['total']; } } if ($this->minimal > 0 and $totalAmount < $this->minimal) { return 0; } switch ($this->id_discount_type) { /* Relative value (% of the order total) */ case 1: $amount = 0; $percentage = $this->value / 100; foreach ($products as $product) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { if ($this->cumulable_reduction or !$product['reduction_applies'] and !$product['on_sale']) { $amount += ($useTax ? $product['total_wt'] : $product['total']) * $percentage; } } } return $amount; /* Absolute value */ /* Absolute value */ case 2: // An "absolute" voucher is available in one currency only $currency = (int) $cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : Currency::getCurrent(); if ($this->id_currency != $currency->id) { return 0; } $taxDiscount = Cart::getTaxesAverageUsed((int) $cart->id); if (!$useTax and isset($taxDiscount) and $taxDiscount != 1) { $this->value = abs($this->value / (1 + $taxDiscount * 0.01)); } // Main return $value = 0; foreach ($products as $product) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { $value = $this->value; } } // Return 0 if there are no applicable categories return $value; /* Free shipping (does not return a value but a special code) */ /* Free shipping (does not return a value but a special code) */ case 3: return '!'; } return 0; }
/** * Return discount value * * @param integer $nb_discounts Number of discount currently in cart * @param boolean $order_total_products Total cart products amount * @param boolean $shipping_fees Total cart products amount * @param integer $id_cart Cart ID * @param boolean $use_tax Enable tax calculations * @return mixed Return a float value or '!' if reduction is 'Shipping free' */ public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $id_cart = 0, $use_tax = true) { global $cart; $c = $id_cart && isset($cart->id) && $cart->id == $id_cart ? $cart : ($id_cart ? new Cart((int) $id_cart) : null); if (!Validate::isLoadedObject($c) || (!$this->cumulable && (int) $nb_discounts > 1 || !$this->active || !$this->quantity && !$c->OrderExists()) || $c->id_customer && $this->usedByCustomer((int) $c->id_customer, false) >= $this->quantity_per_user && !$c->OrderExists() || (time() < strtotime($this->date_from) || time() > strtotime($this->date_to)) && !$c->OrderExists()) { return 0; } $products = $c->getProducts(); $categories = self::getCategories((int) $this->id, false); $totalAmount = 0; foreach ($products as $product) { if (count($categories) && Product::idIsOnCategoryId($product['id_product'], $categories)) { $totalAmount += $this->include_tax ? $product['total_wt'] : $product['total']; } } if ($this->minimal > 0 && $totalAmount < $this->minimal) { return 0; } switch ($this->id_discount_type) { /* Relative value (% of the order total) */ case 1: $amount = 0; $percentage = $this->value / 100; foreach ($products as $product) { if (Product::idIsOnCategoryId($product['id_product'], $categories) && ($this->cumulable_reduction || !$product['reduction_applies'] && !$product['on_sale'])) { $amount += ($use_tax ? $product['total_wt'] : $product['total']) * $percentage; } } return $amount; /* Absolute value */ /* Absolute value */ case 2: /* This type of voucher is restricted to a specific currency */ if ($c->id_currency) { $id_currency = (int) $c->id_currency; } else { global $cookie; if ($cookie->id_currency) { $id_currency = (int) $cookie->id_currency; } } if (!isset($id_currency)) { $id_currency = (int) _PS_CURRENCY_DEFAULT_; } if ($this->id_currency != $id_currency) { return 0; } if (!$use_tax) { $taxDiscount = Cart::getTaxesAverageUsed((int) $c->id); if ($taxDiscount != 1) { $this->value = abs($this->value / (1 + $taxDiscount * 0.01)); } } // Main return $value = 0; foreach ($products as $product) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { $value = $this->value; } } // Return 0 if there are no applicable categories return $value; /* Free shipping (does not return a value but a special code) */ /* Free shipping (does not return a value but a special code) */ case 3: return '!'; } return 0; }