From 3e2de4986b2d92cd196f4da5f0b419ece8de85a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Tue, 20 Nov 2012 19:05:21 +0100 Subject: [PATCH] [-] FO: Fix: many fixes - domain for cookies with different url for ssl / add to cart button for minimal quantities with product attributes --- classes/Category.php | 2 +- classes/Cookie.php | 2 +- classes/Dispatcher.php | 12 +++++++- classes/Hook.php | 28 ++++++++++-------- classes/Link.php | 4 --- classes/Media.php | 2 +- classes/Product.php | 6 ++-- classes/Supplier.php | 2 +- config/config.inc.php | 9 +++++- controllers/front/CategoryController.php | 7 +++++ themes/default/pdf/index.php | 36 ++++++++++++++++++++++++ 11 files changed, 87 insertions(+), 23 deletions(-) create mode 100755 themes/default/pdf/index.php diff --git a/classes/Category.php b/classes/Category.php index b7238464f..9d95a7cd9 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -608,7 +608,7 @@ class CategoryCore extends ObjectModel return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } - $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, + $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`id_product_attribute`, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, image_shop.`id_image`, il.`legend`, m.`name` AS manufacturer_name, cl.`name` AS category_default, DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(), diff --git a/classes/Cookie.php b/classes/Cookie.php index 18f21c3fa..83e3b8bda 100644 --- a/classes/Cookie.php +++ b/classes/Cookie.php @@ -92,7 +92,7 @@ class CookieCore return false; if (!strstr(Tools::getHttpHost(false, false), '.')) return false; - + $domain = false; if ($shared_urls !== null) { diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php index 861bedab1..2d0c46d3f 100644 --- a/classes/Dispatcher.php +++ b/classes/Dispatcher.php @@ -385,6 +385,15 @@ class DispatcherCore { $context = Context::getContext(); + // Load custom routes from modules + $modules_routes = Hook::exec('moduleRoutes', array(), null, true, false); + if (is_array($modules_routes) && count($modules_routes)) + foreach($modules_routes as $module_route) + foreach($module_route as $route => $route_details) + if (array_key_exists('controller', $route_details) && array_key_exists('rule', $route_details) + && array_key_exists('keywords', $route_details) && array_key_exists('params', $route_details)) + $this->addRoute($route, $route_details['rule'], $route_details['controller'], null, $route_details['keywords'], $route_details['params']); + // Set default routes foreach (Language::getLanguages() as $lang) foreach ($this->default_routes as $id => $route) @@ -579,7 +588,8 @@ class DispatcherCore if (!array_key_exists($key, $params)) die('Dispatcher::createUrl() miss required parameter "'.$key.'" for route "'.$route_id.'"'); - $query_params[$this->default_routes[$route_id]['keywords'][$key]['param']] = $params[$key]; + if (isset($this->default_routes[$route_id])) + $query_params[$this->default_routes[$route_id]['keywords'][$key]['param']] = $params[$key]; } // Build an url which match a route diff --git a/classes/Hook.php b/classes/Hook.php index d3b53d18a..538cf4cae 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -358,7 +358,7 @@ class HookCore extends ObjectModel * @param int $id_module Execute hook for this module only * @return string modules output */ - public static function exec($hook_name, $hook_args = array(), $id_module = null) + public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true) { // Check arguments validity if (($id_module && !is_numeric($id_module)) || !Validate::isHookName($hook_name)) @@ -397,11 +397,14 @@ class HookCore extends ObjectModel continue; // Check permissions - $exceptions = $moduleInstance->getExceptions($array['id_hook']); - if (in_array(Dispatcher::getInstance()->getController(), $exceptions)) - continue; - if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) - continue; + if ($check_exceptions) + { + $exceptions = $moduleInstance->getExceptions($array['id_hook']); + if (in_array(Dispatcher::getInstance()->getController(), $exceptions)) + continue; + if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) + continue; + } // Check which / if method is callable $hook_callable = is_callable(array($moduleInstance, 'hook'.$hook_name)); @@ -416,19 +419,22 @@ class HookCore extends ObjectModel else if ($hook_retro_callable) $display = $moduleInstance->{'hook'.$retro_hook_name}($hook_args); // Live edit - if ($array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions'.(int)Tab::getIdFromClassName('AdminModulesPositions').(int)Tools::getValue('id_employee'))) + if ($array_return && $array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions'.(int)Tab::getIdFromClassName('AdminModulesPositions').(int)Tools::getValue('id_employee'))) { $live_edit = true; $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']); } + else if ($array_return) + $output[] = $display; else $output .= $display; } } - - // Return html string - return ($live_edit ? ' -
' : '').$output.($live_edit ? '
' : ''); + if ($array_return) + return $output; + else + return ($live_edit ? ' +
' : '').$output.($live_edit ? '
' : '');// Return html string } public static function wrapLiveEdit($display, $moduleInstance, $id_hook) diff --git a/classes/Link.php b/classes/Link.php index 5eff92baa..f950f1950 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -322,10 +322,7 @@ class LinkCore // If the module has its own route ... just use it ! if (Dispatcher::getInstance()->hasRoute('module-'.$module.'-'.$controller, $id_lang)) - { - unset($params['module']); return $this->getPageLink('module-'.$module.'-'.$controller, $ssl, $id_lang, $params); - } else return $url.Dispatcher::getInstance()->createUrl('module', $id_lang, $params, $this->allow); } @@ -413,7 +410,6 @@ class LinkCore $request = urlencode($request); parse_str($request, $request); } - unset($request['controller']); $uri_path = Dispatcher::getInstance()->createUrl($controller, $id_lang, $request); $url = ($ssl && $this->ssl_enable) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true); diff --git a/classes/Media.php b/classes/Media.php index 49e7f430c..db69d26a6 100755 --- a/classes/Media.php +++ b/classes/Media.php @@ -325,7 +325,7 @@ class MediaCore $ui_tmp[] = Media::getJqueryUIPath($dependency, $theme, false); if (self::$jquery_ui_dependencies[$dependency]['theme']) $dep_css = Media::getCSSPath($folder.'themes/'.$theme.'/jquery.'.$dependency.'.css'); - if (!empty($dep_css) || $dep_css) + if (isset($dep_css) && (!empty($dep_css) || $dep_css)) $ui_path['css'] = array_merge($ui_path['css'], $dep_css); } } diff --git a/classes/Product.php b/classes/Product.php index 1f8b02688..78a1e694f 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3191,7 +3191,8 @@ class ProductCore extends ObjectModel { if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache)) self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array(); - self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][] = $row; + if (!isset(self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][$row['id_product']])) + self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][$row['id_product']] = $row; } } @@ -3588,8 +3589,9 @@ class ProductCore extends ObjectModel $cache_key = $row['id_product'].'-'.$row['id_product_attribute'].'-'.$id_lang.'-'.(int)$usetax; if (isset($row['id_product_pack'])) $cache_key .= '-pack'.$row['id_product_pack']; + if (isset(self::$producPropertiesCache[$cache_key])) - return self::$producPropertiesCache[$cache_key]; + return array_merge($row, self::$producPropertiesCache[$cache_key]); // Datas $row['category'] = Category::getLinkRewrite((int)$row['id_category_default'], (int)$id_lang); diff --git a/classes/Supplier.php b/classes/Supplier.php index 2c52b935a..816573b25 100644 --- a/classes/Supplier.php +++ b/classes/Supplier.php @@ -240,7 +240,7 @@ class SupplierCore extends ObjectModel $order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; } $alias = ''; - if ($order_by == 'price') + if (in_array($order_by, array('price', 'date_add', 'date_upd'))) $alias = 'product_shop.'; elseif ($order_by == 'id_product') $alias = 'p.'; diff --git a/config/config.inc.php b/config/config.inc.php index 5e56da050..4ecdb0184 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -110,6 +110,7 @@ Context::getContext()->country = $defaultCountry; /* Instantiate cookie */ $cookieLifetime = (time() + (((int)Configuration::get('PS_COOKIE_LIFETIME_BO') > 0 ? (int)Configuration::get('PS_COOKIE_LIFETIME_BO') : 1)* 3600)); + if (defined('_PS_ADMIN_DIR_')) $cookie = new Cookie('psAdmin', '', $cookieLifetime); else @@ -117,7 +118,13 @@ else if (Context::getContext()->shop->getGroup()->share_order) $cookie = new Cookie('ps-sg'.Context::getContext()->shop->getGroup()->id, '', $cookieLifetime, Context::getContext()->shop->getUrlsSharedCart()); else - $cookie = new Cookie('ps-s'.Context::getContext()->shop->id, '', $cookieLifetime); + { + $domains = null; + if(Context::getContext()->shop->domain != Context::getContext()->shop->domain_ssl) + $domains = array(Context::getContext()->shop->domain_ssl, Context::getContext()->shop->domain); + + $cookie = new Cookie('ps-s'.Context::getContext()->shop->id, '', $cookieLifetime, $domains); + } } Context::getContext()->cookie = $cookie; diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index e6b387d7b..366df5250 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -183,6 +183,13 @@ class CategoryControllerCore extends FrontController else // Pagination must be call after "getProducts" $this->pagination($this->nbProducts); + + foreach ($this->cat_products as &$product) + { + if ($product['id_product_attribute']) + $product['minimal_quantity'] = $product['product_attribute_minimal_quantity']; + } + $this->context->smarty->assign('nb_products', $this->nbProducts); } } diff --git a/themes/default/pdf/index.php b/themes/default/pdf/index.php new file mode 100755 index 000000000..60bc2ce27 --- /dev/null +++ b/themes/default/pdf/index.php @@ -0,0 +1,36 @@ + +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 6844 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit;