// Refacto of cartController

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8853 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-09-28 15:40:28 +00:00
parent c26b75987e
commit ccd0383e88
6 changed files with 263 additions and 228 deletions
+17 -17
View File
@@ -828,7 +828,7 @@ class CartCore extends ObjectModel
*/
public function deleteDiscount($id_discount)
{
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_discount` WHERE `id_discount` = '.(int)($id_discount).' AND `id_cart` = '.(int)($this->id).' LIMIT 1');
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_discount` WHERE `id_discount` = '.(int)$id_discount.' AND `id_cart` = '.(int)$this->id.' LIMIT 1');
}
/**
@@ -845,21 +845,21 @@ class CartCore extends ObjectModel
unset(self::$_nbProducts[$this->id]);
if (isset(self::$_totalWeight[$this->id]))
unset(self::$_totalWeight[$this->id]);
if ((int)($id_customization))
if ((int)$id_customization)
{
$productTotalQuantity = (int)(Db::getInstance()->getValue('SELECT `quantity`
$productTotalQuantity = (int)Db::getInstance()->getValue('SELECT `quantity`
FROM `'._DB_PREFIX_.'cart_product`
WHERE `id_product` = '.(int)($id_product).' AND `id_product_attribute` = '.(int)($id_product_attribute)));
$customizationQuantity = (int)(Db::getInstance()->getValue('SELECT `quantity`
WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute);
$customizationQuantity = (int)Db::getInstance()->getValue('SELECT `quantity`
FROM `'._DB_PREFIX_.'customization`
WHERE `id_cart` = '.(int)($this->id).'
AND `id_product` = '.(int)($id_product).'
AND `id_product_attribute` = '.(int)($id_product_attribute)));
if (!$this->_deleteCustomization((int)($id_customization), (int)($id_product), (int)($id_product_attribute)))
WHERE `id_cart` = '.(int)$this->id.'
AND `id_product` = '.(int)$id_product.'
AND `id_product_attribute` = '.(int)$id_product_attribute);
if (!$this->_deleteCustomization((int)$id_customization, (int)$id_product, (int)$id_product_attribute))
return false;
// refresh cache of self::_products
$this->_products = $this->getProducts(true);
return ($customizationQuantity == $productTotalQuantity AND $this->deleteProduct((int)($id_product), $id_product_attribute, NULL));
return ($customizationQuantity == $productTotalQuantity && $this->deleteProduct((int)$id_product, $id_product_attribute, null));
}
/* Get customization quantity */
@@ -882,7 +882,7 @@ class CartCore extends ObjectModel
($id_product_attribute != NULL ? ' AND `id_product_attribute` = '.(int)($id_product_attribute) : ''));
/* Product deletion */
if (Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_product` WHERE `id_product` = '.(int)($id_product).($id_product_attribute != NULL ? ' AND `id_product_attribute` = '.(int)($id_product_attribute) : '').' AND `id_cart` = '.(int)($this->id)))
if (Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_product` WHERE `id_product` = '.(int)($id_product).(!is_null($id_product_attribute) ? ' AND `id_product_attribute` = '.(int)($id_product_attribute) : '').' AND `id_cart` = '.(int)($this->id)))
{
// refresh cache of self::_products
$this->_products = $this->getProducts(true);
@@ -906,7 +906,7 @@ class CartCore extends ObjectModel
FROM `'._DB_PREFIX_.'customization`
WHERE `id_customization` = '.(int)($id_customization));
if ($customization and sizeof($customization))
if ($customization)
{
$custData = Db::getInstance()->getRow('SELECT *
FROM `'._DB_PREFIX_.'customized_data`
@@ -940,7 +940,7 @@ class CartCore extends ObjectModel
public static function getTotalCart($id_cart, $use_tax_display = false)
{
$cart = new Cart((int)($id_cart));
$cart = new Cart($id_cart);
if (!Validate::isLoadedObject($cart))
die(Tools::displayError());
$with_taxes = $use_tax_display ? $cart->_taxCalculationMethod != PS_TAX_EXC : true;
@@ -973,7 +973,7 @@ class CartCore extends ObjectModel
{
if (!$this->id)
return 0;
$type = (int)($type);
$type = (int)$type;
if (!in_array($type, array(Cart::ONLY_PRODUCTS, Cart::ONLY_DISCOUNTS, Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_SHIPPING, Cart::ONLY_WRAPPING, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)))
die(Tools::displayError());
@@ -1027,11 +1027,11 @@ class CartCore extends ObjectModel
$wrapping_fees = 0;
if ($this->gift)
{
$wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE'));
$wrapping_fees = (float)Configuration::get('PS_GIFT_WRAPPING_PRICE');
if ($withTaxes)
{
$wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX')));
$wrapping_fees *= 1 + (((float)($wrapping_fees_tax->rate) / 100));
$wrapping_fees_tax = new Tax(Configuration::get('PS_GIFT_WRAPPING_TAX'));
$wrapping_fees *= 1 + ((float)$wrapping_fees_tax->rate / 100);
}
$wrapping_fees = Tools::convertPrice(Tools::ps_round($wrapping_fees, 2), Currency::getCurrencyInstance((int)($this->id_currency)));
}
+1 -1
View File
@@ -111,7 +111,7 @@ abstract class ControllerCore
public function run()
{
$this->init();
if ($this->ajax && method_exists($this, 'ajaxProcess'))
$this->ajaxProcess();
else
+21 -11
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -50,7 +50,7 @@ class CookieCore
/** @var array cipher tool initilization vector */
protected $_iv;
protected $_modified = false;
/**
@@ -78,13 +78,13 @@ class CookieCore
$this->_cipherTool = new Blowfish($this->_key, $this->_iv);
$this->update();
}
protected function getDomain()
{
$r = '!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i';
preg_match ($r, Tools::getHttpHost(false, false), $out);
if (preg_match('/^(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{1}[0-9]|[1-9]).)'.
'{1}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9]).)'.
if (preg_match('/^(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{1}[0-9]|[1-9]).)'.
'{1}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9]).)'.
'{2}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9]){1}))$/', $out[4]))
return false;
if (!strstr(Tools::getHttpHost(false, false), '.'))
@@ -176,7 +176,7 @@ class CookieCore
Tools::displayAsDeprecated();
if (!$withGuest AND $this->is_guest == 1)
return false;
/* Customer is valid only if it can be load and if cookie password is the same as database one */
if ($this->logged == 1 AND $this->id_customer AND Validate::isUnsignedId($this->id_customer) AND Customer::checkPassword((int)($this->id_customer), $this->passwd))
return true;
@@ -235,7 +235,7 @@ class CookieCore
$this->_modified = true;
$this->write();
}
function makeNewLog()
{
unset($this->_content['id_customer']);
@@ -272,17 +272,17 @@ class CookieCore
/* Check if cookie has not been modified */
if (!isset($this->_content['checksum']) OR $this->_content['checksum'] != $checksum)
$this->logout();
if (!isset($this->_content['date_add']))
$this->_content['date_add'] = date('Y-m-d H:i:s');
}
else
$this->_content['date_add'] = date('Y-m-d H:i:s');
//checks if the language exists, if not choose the default language
if (!Language::getLanguage((int)$this->id_lang))
$this->id_lang = Configuration::get('PS_LANG_DEFAULT');
}
/**
@@ -350,11 +350,21 @@ class CookieCore
}
/**
*
* @return String name of cookie
*/
public function getName()
{
return $this->_name;
}
/**
* Check if the cookie exists
*
* @since 1.5.0
* @return bool
*/
public function exists()
{
return isset($_COOKIE[$this->_name]);
}
}
+11
View File
@@ -662,6 +662,17 @@ class FrontControllerCore extends Controller
return $allowed;
}
/**
* Check if token is valid
*
* @since 1.5.0
* @return bool
*/
public function isTokenValid()
{
return Configuration::get('PS_TOKEN_ENABLE') && strcasecmp(Tools::getToken(false), Tools::getValue('token')) && $this->context->customer->isLogged();
}
/**
* Add one or several CSS for front, checking if css files are overriden in theme/css/modules/ directory
*