// Context part 20

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7740 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-07-26 15:55:04 +00:00
parent fddc7a6a75
commit 51b4c8591d
10 changed files with 72 additions and 73 deletions
+5 -5
View File
@@ -235,10 +235,10 @@ class AddressFormatCore extends ObjectModel
* @addressFormat is the format
* @return double Array
*/
public static function getFormattedAddressFieldsValues($address, $addressFormat, Context $context = null)
public static function getFormattedAddressFieldsValues($address, $addressFormat, $id_lang = null)
{
if (!$context)
$context = Context::getContext();
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
$tab = array();
$temporyObject = array();
@@ -268,8 +268,8 @@ class AddressFormatCore extends ObjectModel
$temporyObject[$associateName[0]] = new $associateName[0]($address->{$idFieldName});
if ($temporyObject[$associateName[0]])
$tab[$pattern] = (is_array($temporyObject[$associateName[0]]->{$associateName[1]})) ?
((isset($temporyObject[$associateName[0]]->{$associateName[1]}[$context->language->id])) ?
$temporyObject[$associateName[0]]->{$associateName[1]}[$context->language->id] : '') :
((isset($temporyObject[$associateName[0]]->{$associateName[1]}[$id_lang])) ?
$temporyObject[$associateName[0]]->{$associateName[1]}[$id_lang] : '') :
$temporyObject[$associateName[0]]->{$associateName[1]};
}
}
+2 -6
View File
@@ -1803,14 +1803,10 @@ abstract class AdminTabCore
* @param integer $id_lang Language id (optional)
* @return string
*/
protected function getFieldValue($obj, $key, $id_lang = NULL, Context $context = NULL)
protected function getFieldValue($obj, $key, $id_lang = NULL, $id_shop = null)
{
$id_shop = ($context) ? $context->shop->getID() : null;
if (!$context)
$context = Context::getContext();
if (!$id_shop AND $obj->isLangMultishop())
$id_shop = $context->shop->getID();
$id_shop = Context::getContext()->shop->getID();
if ($id_lang)
$defaultValue = ($obj->id AND isset($obj->{$key}[$id_lang])) ? $obj->{$key}[$id_lang] : '';
+4 -4
View File
@@ -118,15 +118,15 @@ class AttributeCore extends ObjectModel
* @param integer $qty Quantity needed
* @return boolean Quantity is available or not
*/
static public function checkAttributeQty($id_product_attribute, $qty, Context $context = null)
static public function checkAttributeQty($id_product_attribute, $qty, Shop $shop = null)
{
if (!$context)
$context = Context::getContext();
if (!$shop)
$$shop = Context::getContext()->shop;
$sql = 'SELECT quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product_attribute = '.(int)$id_product_attribute
.$context->shop->sqlSharedStock();
.$shop->sqlSharedStock();
$result = (int)Db::getInstance()->getValue($sql);
return ($result AND $qty <= $result);
+17 -13
View File
@@ -399,14 +399,18 @@ class CarrierCore extends ObjectModel
return $carriers;
}
public static function getCarriersForOrder($id_zone, $groups = NULL, $context = null)
public static function getCarriersForOrder($id_zone, $groups = NULL, Cart $cart = null, $id_currency = null, $id_lang = null)
{
if (!$context)
$context = Context::getContext();
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
if (!$cart)
$cart = Context::getContext()->cart;
if (!$id_currency)
$id_currency = Context::getContext()->currency->id;
if (is_array($groups) AND !empty($groups))
$result = Carrier::getCarriers((int)$context->language->id, true, false, (int)$id_zone, $groups, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, $groups, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
else
$result = Carrier::getCarriers((int)$context->language->id, true, false, (int)$id_zone, array(1), PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
$result = Carrier::getCarriers($id_lang, true, false, (int)$id_zone, array(1), PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
$resultsArray = array();
foreach ($result AS $k => $row)
@@ -431,8 +435,8 @@ class CarrierCore extends ObjectModel
$id_zone = (int)$defaultCountry->id_zone;
// Get only carriers that have a range compatible with cart
if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT AND (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $context->cart->getTotalWeight(), $id_zone)))
OR ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE AND (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $context->cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $context->currency->id))))
if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT AND (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
OR ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE AND (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $id_currency))))
{
unset($result[$k]);
continue ;
@@ -441,8 +445,8 @@ class CarrierCore extends ObjectModel
}
$row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'));
$row['price'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $context->cart->getOrderShippingCost((int)$row['id_carrier']));
$row['price_tax_exc'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $context->cart->getOrderShippingCost((int)$row['id_carrier'], false));
$row['price'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier']));
$row['price_tax_exc'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'], false));
$row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)($row['id_carrier']).'.jpg') ? _THEME_SHIP_DIR_.(int)($row['id_carrier']).'.jpg' : '';
// If price is false, then the carrier is unavailable (carrier module)
@@ -724,13 +728,13 @@ class CarrierCore extends ObjectModel
return false;
}
public function getRangeSuffix($context = null)
public function getRangeSuffix($currency = null)
{
if (!$context)
$context = Context::getContext();
if (!$currency)
$currency = Context::getContext()->currency;
$suffix = Configuration::get('PS_WEIGHT_UNIT');
if ($this->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE)
$suffix = $context->currency->sign;
$suffix = $currency->sign;
return $suffix;
}
+31 -31
View File
@@ -333,7 +333,7 @@ class CartCore extends ObjectModel
*
* @result array Products
*/
public function getProducts($refresh = false, $id_product = false, Context $context = null)
public function getProducts($refresh = false, $id_product = false, $id_country = null)
{
if (!$this->id)
return array();
@@ -350,8 +350,8 @@ class CartCore extends ObjectModel
}
return $this->_products;
}
if (!$context)
$context = Context::getContext();
if (!$id_country)
$id_country = Context::getContext()->country->id;
$sql = 'SELECT cp.`id_product_attribute`, cp.`id_product`, cu.`id_customization`, cp.`quantity` AS cart_quantity, cp.id_shop, cu.`quantity` AS customization_quantity, pl.`name`,
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`,
@@ -368,7 +368,7 @@ class CartCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$this->id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = cp.`id_product_attribute`)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)$context->country->id.'
AND tr.`id_country` = '.(int)$id_country.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$this->id_lang.')
@@ -541,14 +541,14 @@ class CartCore extends ObjectModel
* @param integer $id_product_attribute Attribute ID if needed
* @param string $operator Indicate if quantity must be increased or decreased
*/
public function updateQty($quantity, $id_product, $id_product_attribute = NULL, $id_customization = false, $operator = 'up', Context $context = null)
public function updateQty($quantity, $id_product, $id_product_attribute = NULL, $id_customization = false, $operator = 'up', Shop $shop = null)
{
if (!$context)
$context = Context::getContext();
if (!$shop)
$shop = Context::getContext()->shop;
$quantity = (int)$quantity;
$id_product = (int)$id_product;
$id_product_attribute = (int)$id_product_attribute;
$product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), $context->shop->getID());
$product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), $shop->getID());
/* If we have a product combination, the minimal quantity is set with the one of this combination */
if (!empty($id_product_attribute))
@@ -579,7 +579,7 @@ class CartCore extends ObjectModel
{
$sql = 'SELECT p.out_of_stock, stock.quantity
FROM '._DB_PREFIX_.'product p
'.Product::sqlStock('p', $id_product_attribute, true, $context).'
'.Product::sqlStock('p', $id_product_attribute, true, $shop).'
WHERE p.id_product = '.$id_product;
$result2 = Db::getInstance()->getRow($sql);
$productQty = (int)$result2['quantity'];
@@ -1028,13 +1028,14 @@ class CartCore extends ObjectModel
* @param integer $id_carrier Carrier ID (default : current carrier)
* @return float Shipping total
*/
function getOrderShippingCost($id_carrier = NULL, $useTax = true, Context $context = null)
function getOrderShippingCost($id_carrier = NULL, $useTax = true, Country $default_country = null)
{
if (!$context)
$context = Context::getContext();
if ($this->isVirtualCart())
return 0;
if (!$default_country)
$default_country = Context::getContext()->country;
// Checking discounts in cart
$products = $this->getProducts();
$discounts = $this->getDiscounts(true);
@@ -1076,11 +1077,9 @@ class CartCore extends ObjectModel
$id_zone = Address::getZoneById((int)($this->id_address_delivery));
else
{
// This method can be called from the backend, and $defaultCountry won't be defined
$defaultCountry = $context->country;
if (!Validate::isLoadedObject($defaultCountry))
$defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
$id_zone = (int)$defaultCountry->id_zone;
if (!Validate::isLoadedObject($default_country))
$default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
$id_zone = (int)$default_country->id_zone;
}
// If no carrier, select default one
@@ -1199,7 +1198,7 @@ class CartCore extends ObjectModel
)
$id_zone = Address::getZoneById((int)($this->id_address_delivery));
else
$id_zone = (int)$defaultCountry->id_zone;
$id_zone = (int)$default_country->id_zone;
if (($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT AND (!Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), $id_zone)))
OR ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE AND (!Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int)($this->id_currency)))))
$shipping_cost += 0;
@@ -1284,10 +1283,13 @@ class CartCore extends ObjectModel
*
* @return mixed Return a string if an error occurred and false otherwise
*/
function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = false, Context $context = null)
function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = false,
Customer $customer = null, Shop $shop = null)
{
if (!$context)
$context = Context::getContext();
if (!$shop)
$shop = Context::getContext()->shop;
if (!$customer)
$customer = Context::getContext()->customer;
if (!$order_total)
return Tools::displayError('Cannot add voucher if order is free.');
if (!$discountObj->active)
@@ -1300,7 +1302,7 @@ class CartCore extends ObjectModel
if ($checkCartDiscount
AND (
$this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user
OR (Order::getDiscountsCustomer((int)($context->customer->id), $discountObj->id) + $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user
OR (Order::getDiscountsCustomer($customer->id, $discountObj->id) + $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user
)
)
return Tools::displayError('You cannot use this voucher anymore (usage limit attained).');
@@ -1308,7 +1310,7 @@ class CartCore extends ObjectModel
return Tools::displayError('This voucher is not yet valid');
if (strtotime($discountObj->date_to) < time())
return Tools::displayError('This voucher has expired.');
if (!$discountObj->availableWithShop($context->shop))
if (!$discountObj->availableWithShop($shop))
return Tools::displayError('This voucher is not available with this shop.');
if (sizeof($discounts) >= 1 AND $checkCartDiscount)
{
@@ -1327,7 +1329,7 @@ class CartCore extends ObjectModel
if (($discountObj->id_customer OR $discountObj->id_group) AND ($this->id_customer != $discountObj->id_customer AND !in_array($discountObj->id_group, $groups)))
{
if (!$context->customer->isLogged())
if (!$customer->isLogged())
return Tools::displayError('You cannot use this voucher.').' - '.Tools::displayError('Please log in.');
return Tools::displayError('You cannot use this voucher.');
}
@@ -1384,10 +1386,10 @@ class CartCore extends ObjectModel
*
* @return array Cart details
*/
function getSummaryDetails(Context $context = null)
function getSummaryDetails($id_lang = null)
{
if (!$context)
$context = Context::getContext();
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
$delivery = new Address((int)($this->id_address_delivery));
$invoice = new Address((int)($this->id_address_invoice));
@@ -1415,7 +1417,7 @@ class CartCore extends ObjectModel
'delivery_state' => State::getNameById($delivery->id_state),
'invoice' => $invoice,
'invoice_state' => State::getNameById($invoice->id_state),
'carrier' => new Carrier($this->id_carrier, $context->language->id),
'carrier' => new Carrier($this->id_carrier, $id_lang),
'products' => $this->getProducts(false),
'discounts' => $this->getDiscounts(false, true),
'is_virtual_cart' => (int)$this->isVirtualCart(),
@@ -1647,10 +1649,8 @@ class CartCore extends ObjectModel
$success = true;
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'cart_product` WHERE `id_cart` = '.(int)$this->id);
$newContext = Context::cloneContext();
$newContext->shop = new Shop($cart->id_shop);
foreach ($products AS $product)
$success &= $cart->updateQty($product['quantity'], (int)$product['id_product'], (int)$product['id_product_attribute'], NULL, 'up', $newContext);
$success &= $cart->updateQty($product['quantity'], (int)$product['id_product'], (int)$product['id_product_attribute'], NULL, 'up', new Shop($cart->id_shop));
// Customized products
$customs = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
+1 -1
View File
@@ -229,7 +229,7 @@ class DispatcherCore
else if (isset($_POST['controller']))
$_POST[$m[2]] = $m[3];
}
$this->controller (!empty($controller)) ? $controller : 'index';
$this->controller = (!empty($controller)) ? $controller : 'index';
}
$this->controller = str_replace('-', '', strtolower($this->controller));
+4 -4
View File
@@ -2060,10 +2060,10 @@ class ProductCore extends ObjectModel
* @param Context $context
* @return string
*/
public static function sqlStock($productAlias, $productAttribute = 0, $innerJoin = false, Context $context = null)
public static function sqlStock($productAlias, $productAttribute = 0, $innerJoin = false, Shop $shop = null)
{
if (!$context)
$context = Context::getContext();
if (!$shop)
$shop = Context::getContext()->shop;
$sql = (($innerJoin) ? ' INNER ' : ' LEFT ').'JOIN '._DB_PREFIX_.'stock stock ON stock.id_product = '.pSQL($productAlias).'.id_product';
if (!is_null($productAttribute))
@@ -2073,7 +2073,7 @@ class ProductCore extends ObjectModel
else if (is_string($productAttribute))
$sql .= ' AND stock.id_product_attribute = IFNULL('.pSQL($productAttribute).'.id_product_attribute, 0)';
}
$sql .= $context->shop->sqlSharedStock('stock') . ' ';
$sql .= $shop->sqlSharedStock('stock') . ' ';
return $sql;
}
+1 -1
View File
@@ -532,7 +532,7 @@ class ShopCore extends ObjectModel
{
if (!isset($context->shop))
return ($type == 'shop' || $type == 'group') ? '' : array('', '');
$shopID = (int)$context->shop->id_shop;
$shopID = (int)$context->shop->getID();
$shopGroupID = (int)$context->shop->id_group_shop;
}
$executed = true;
+4 -4
View File
@@ -55,10 +55,10 @@ class ToolsCore
* @param string $url Desired URL
* @param string $baseUri Base URI (optional)
*/
public static function redirect($url, $baseUri = __PS_BASE_URI__, Context $context = null)
public static function redirect($url, $baseUri = __PS_BASE_URI__, Link $link = null)
{
if (!$context)
$context = Context::getContext();
if (!$link)
$link = Context::getContext()->link;
if (strpos($url, 'http://') === FALSE && strpos($url, 'https://') === FALSE)
{
if (strpos($url, $baseUri) !== FALSE && strpos($url, $baseUri) == 0)
@@ -70,7 +70,7 @@ class ToolsCore
}
$explode = explode('?', $url);
$url = $context->link->getPageLink($explode[0], true);
$url = $link->getPageLink($explode[0], true);
if (isset($explode[1]))
$url .= '?'.$explode[1];
$baseUri = '';
+3 -4
View File
@@ -47,18 +47,18 @@ else
class Tools extends ToolsCore
{
/**
* Redirect user to another page after 5 sec
*
* @param string $url Desired URL
* @param string $baseUri Base URI (optional)
*/
public static function redirect($url, $baseUri = __PS_BASE_URI__)
public static function redirect($url, $baseUri = __PS_BASE_URI__, Link $link = null)
{
if (!$link)
$link = Context::getContext()->link;
if (strpos($url, 'http://') === FALSE && strpos($url, 'https://') === FALSE)
{
global $link;
if (strpos($url, $baseUri) !== FALSE && strpos($url, $baseUri) == 0)
$url = substr($url, strlen($baseUri));
$explode = explode('?', $url);
@@ -73,7 +73,6 @@ class Tools extends ToolsCore
else
header('Refresh: 5; url='.$baseUri.$url);
exit;
}