From df255f66c17fbd5c2685345bea7fdf4dc77a67be Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Wed, 27 Jul 2011 15:08:15 +0000 Subject: [PATCH] // Context part 23 git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7765 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Customer.php | 20 ++++++++++---------- classes/Discount.php | 23 ++++++++++++----------- classes/Link.php | 6 ++---- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/classes/Customer.php b/classes/Customer.php index 5b0fa1eea..435b0178a 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -382,11 +382,11 @@ class CustomerCore extends ObjectModel * @param string $query Searched string * @return array Corresponding customers */ - public static function searchByName($query, Context $context = null) + public static function searchByName($query, Shop $shop = null) { - if (!$context) - $context = Context::getContext(); - + if (!$shop) + $shop = Context::getContext()->shop; + $sql = 'SELECT * FROM `'._DB_PREFIX_.'customer` WHERE ( @@ -394,7 +394,7 @@ class CustomerCore extends ObjectModel OR `id_customer` LIKE \'%'.pSQL($query).'%\' OR `lastname` LIKE \'%'.pSQL($query).'%\' OR `firstname` LIKE \'%'.pSQL($query).'%\' - )'.$context->shop->sqlRestriction(Shop::SHARE_CUSTOMER); + )'.$shop->sqlRestriction(Shop::SHARE_CUSTOMER); return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql); } @@ -513,14 +513,14 @@ class CustomerCore extends ObjectModel return self::$_defaultGroupId[(int)($id_customer)]; } - static public function getCurrentCountry($id_customer, Context $context = null) + static public function getCurrentCountry($id_customer, Cart $cart = null) { - if (!$context) - $context = Context::getContext(); - if (!$context->cart OR !$context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) + if (!$cart) + $cart = Context::getContext()->cart; + if (!$cart OR !$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) $id_address = (int)(Db::getInstance()->getValue('SELECT `id_address` FROM `'._DB_PREFIX_.'address` WHERE `id_customer` = '.(int)($id_customer).' AND `deleted` = 0 ORDER BY `id`')); else - $id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; + $id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $ids = Address::getCountryAndState($id_address); return (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT')); } diff --git a/classes/Discount.php b/classes/Discount.php index c52ebccac..4378dd02b 100644 --- a/classes/Discount.php +++ b/classes/Discount.php @@ -223,10 +223,10 @@ class DiscountCore extends ObjectModel * @param boolean $id_customer Customer ID * @return array Discounts */ - static public function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $stock = false, Context $context = null) + static public function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $stock = false, Cart $cart = null) { - if (!$context) - $context = Context::getContext(); + if (!$cart) + $cart = Context::getContext()->cart; $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT d.*, dtl.`name` AS `type`, dl.`description` FROM `'._DB_PREFIX_.'discount` d @@ -242,8 +242,8 @@ class DiscountCore extends ObjectModel foreach ($res as &$discount) if ($discount['quantity_per_user']) { - $quantity_used = Order::getDiscountsCustomer((int)($id_customer), (int)($discount['id_discount'])); - if (isset($context->cart) AND $context->cart->id) + $quantity_used = Order::getDiscountsCustomer($id_customer, $discount['id_discount']); + if (isset($cart) AND $cart->id) $quantity_used += $cart->getDiscountsCustomer((int)($discount['id_discount'])); $discount['quantity_for_user'] = $discount['quantity_per_user'] - $quantity_used; } @@ -269,11 +269,12 @@ class DiscountCore extends ObjectModel * @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, Context $context = null) + public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true, Currency $currency = null, Shop $shop = null) { - if (!$context) - $context = Context::getContext(); - + if (!$currency) + $currency = Context::getContext()->currency; + if (!$shop) + $shop = Context::getContext()->shop; $totalAmount = 0; $cart = new Cart($idCart); if (!Validate::isLoadedObject($cart)) @@ -289,7 +290,7 @@ class DiscountCore extends ObjectModel $date_end = strtotime($this->date_to); if ((time() < $date_start OR time() > $date_end) AND !$cart->OrderExists()) return 0; - if (!$this->isAssociatedToShop($context->shop->shopID())) + if (!$this->isAssociatedToShop($shop->shopID())) return 0; $products = $cart->getProducts(); $categories = Discount::getCategories((int)$this->id); @@ -317,7 +318,7 @@ class DiscountCore extends ObjectModel /* Absolute value */ case 2: // An "absolute" voucher is available in one currency only - $currency = ((int)$cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : $context->currency); + $currency = ((int)$cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : $currency); if ($this->id_currency != $currency->id) return 0; diff --git a/classes/Link.php b/classes/Link.php index 69a8c0ff4..f9c7c718c 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -271,14 +271,12 @@ class LinkCore * @param string $request * @param Context $context */ - public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null, Context $context = null) + public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null) { $controller = str_replace('.php', '', $controller); - if (!$context) - $context = Context::getContext(); if (!$id_lang) - $id_lang = (int)$context->language->id; + $id_lang = (int)Context::getContext()->language->id; $uri_path = Dispatcher::getInstance()->createUrl($controller); $url = ($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);