// Normalize

This commit is contained in:
rMalie
2012-01-25 16:13:36 +00:00
parent accafe14cb
commit cb9a7f281f
9 changed files with 50 additions and 47 deletions
+2 -2
View File
@@ -164,7 +164,7 @@ class AddressControllerCore extends FrontController
}
else if ($zip_code_format)
$this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is required.');
else if ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode))
else if ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode))
$this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.')
.'<br />'.Tools::displayError('Must be typed as follows:').' '
.str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
@@ -174,7 +174,7 @@ class AddressControllerCore extends FrontController
if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
$this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
else if (!$country->isNeedDni())
$address->dni = NULL;
$address->dni = null;
// Don't continue this process if we have errors !
if ($this->errors && !Tools::isSubmit('ajax'))
+3 -3
View File
@@ -231,7 +231,7 @@ class AuthControllerCore extends FrontController
$addressItems[] = trim($addressItem);
// Add missing require fields for a new user susbscription form
foreach($requireFormFieldsList as $fieldName)
foreach ($requireFormFieldsList as $fieldName)
if (!in_array($fieldName, $addressItems))
$addressItems[] = trim($fieldName);
@@ -450,7 +450,7 @@ class AuthControllerCore extends FrontController
$this->errors = array_unique(array_merge($this->errors, $address->validateController()));
// US customer: normalize the address
if($address->id_country == Country::getByIso('US'))
if ($address->id_country == Country::getByIso('US'))
{
include_once(_PS_TAASC_PATH_.'AddressStandardizationSolution.php');
$normalize = new AddressStandardizationSolution;
@@ -481,7 +481,7 @@ class AuthControllerCore extends FrontController
if (Country::isNeedDniByCountryId($address->id_country) && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
$this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
elseif (!Country::isNeedDniByCountryId($address->id_country))
$address->dni = NULL;
$address->dni = null;
}
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == ''))
+5 -7
View File
@@ -70,11 +70,11 @@ class CartControllerCore extends FrontController
$this->processChangeProductInCart();
else if (Tools::getIsset('delete'))
$this->processDeleteProductInCart();
else if(Tools::getIsset('changeAddressDelivery'))
else if (Tools::getIsset('changeAddressDelivery'))
$this->processChangeProductAddressDelivery();
else if(Tools::getIsset('allowSeperatedPackage'))
else if (Tools::getIsset('allowSeperatedPackage'))
$this->processAllowSeperatedPackage();
else if(Tools::getIsset('duplicate'))
else if (Tools::getIsset('duplicate'))
$this->processDuplicateProduct();
// Make redirection
if (!$this->errors && !$this->ajax)
@@ -147,14 +147,12 @@ class CartControllerCore extends FrontController
if (!Configuration::get('PS_ALLOW_MULTISHIPPING'))
return;
if (
!$this->context->cart->duplicateProduct(
if (!$this->context->cart->duplicateProduct(
$this->id_product,
$this->id_product_attribute,
$this->id_address_delivery,
(int)Tools::getValue('new_id_address_delivery')
)
)
))
{
//$error_message = $this->l('Error durring product duplication');
// For the moment no translations
+1 -1
View File
@@ -99,7 +99,7 @@ class CategoryControllerCore extends FrontController
$this->context->smarty->assign(array(
'category' => $this->category,
'products' => (isset($this->cat_products) && $this->cat_products) ? $this->cat_products : NULL,
'products' => (isset($this->cat_products) && $this->cat_products) ? $this->cat_products : null,
'id_category' => (int)$this->category->id,
'id_category_parent' => (int)$this->category->id_parent,
'return_category_name' => Tools::safeOutput($this->category->name),
+1 -1
View File
@@ -131,7 +131,7 @@ class OrderDetailControllerCore extends FrontController
*/
public function initContent()
{
if (!$id_order = (int)(Tools::getValue('id_order')) OR !Validate::isUnsignedId($id_order))
if (!$id_order = (int)(Tools::getValue('id_order')) || !Validate::isUnsignedId($id_order))
$this->errors[] = Tools::displayError('Order ID required');
else
{
+3 -3
View File
@@ -46,9 +46,9 @@ class OrderFollowControllerCore extends FrontController
Tools::redirect('index.php?controller=history');
if (!$order_qte_input = Tools::getValue('order_qte_input'))
Tools::redirect('index.php?controller=order-follow&errorDetail1');
if ($customizationIds = Tools::getValue('customization_ids') AND !$customizationQtyInput)
if ($customizationIds = Tools::getValue('customization_ids') && !$customizationQtyInput)
Tools::redirect('index.php?controller=order-follow&errorDetail1');
if (!$ids_order_detail = Tools::getValue('ids_order_detail') AND !$customizationIds)
if (!$ids_order_detail = Tools::getValue('ids_order_detail') && !$customizationIds)
Tools::redirect('index.php?controller=order-follow&errorDetail2');
$order = new Order((int)($id_order));
@@ -88,7 +88,7 @@ class OrderFollowControllerCore extends FrontController
elseif (Tools::isSubmit('errorDetail2'))
$this->context->smarty->assign('errorDetail2', true);
elseif (Tools::isSubmit('errorNotReturnable'))
$this->context->smarty->assign('errorNotReturnable',true);
$this->context->smarty->assign('errorNotReturnable', true);
$this->context->smarty->assign('ordersReturn', $ordersReturn);
+32 -27
View File
@@ -43,7 +43,7 @@ class OrderOpcControllerCore extends ParentOrderController
$this->context->smarty->assign('is_multi_address_delivery', $this->context->cart->isMultiAddressDelivery());
$this->isLogged = (bool)($this->context->customer->id AND Customer::customerIdExistsStatic((int)($this->context->cookie->id_customer)));
$this->isLogged = (bool)($this->context->customer->id && Customer::customerIdExistsStatic((int)($this->context->cookie->id_customer)));
if ($this->context->cart->nbProducts())
{
@@ -58,18 +58,18 @@ class OrderOpcControllerCore extends ParentOrderController
{
$txtMessage = urldecode(Tools::getValue('message'));
$this->_updateMessage($txtMessage);
if (sizeof($this->errors))
if (count($this->errors))
die('{"hasError" : true, "errors" : ["'.implode('\',\'', $this->errors).'"]}');
die(true);
}
break;
case 'updateCarrierAndGetPayments':
if ((Tools::isSubmit('delivery_option') || Tools::isSubmit('id_carrier')) AND Tools::isSubmit('recyclable') AND Tools::isSubmit('gift') AND Tools::isSubmit('gift_message'))
if ((Tools::isSubmit('delivery_option') || Tools::isSubmit('id_carrier')) && Tools::isSubmit('recyclable') && Tools::isSubmit('gift') && Tools::isSubmit('gift_message'))
{
if ($this->_processCarrier())
{
$carriers = $this->context->cart->simulateCarriersOutput();
$address_delivery = new Address($this->context->cart->id_address_delivery);
$return = array(
'summary' => $this->context->cart->getSummaryDetails(),
'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'),
@@ -82,11 +82,12 @@ class OrderOpcControllerCore extends ParentOrderController
}
else
$this->errors[] = Tools::displayError('Error occurred updating cart.');
if (sizeof($this->errors))
if (count($this->errors))
die('{"hasError" : true, "errors" : ["'.implode('\',\'', $this->errors).'"]}');
exit;
}
break;
case 'updateTOSStatusAndGetPayments':
if (Tools::isSubmit('checked'))
{
@@ -97,9 +98,11 @@ class OrderOpcControllerCore extends ParentOrderController
)));
}
break;
case 'getCarrierList':
die(Tools::jsonEncode($this->_getCarrierList()));
break;
case 'editCustomer':
if (!$this->isLogged)
exit;
@@ -116,12 +119,13 @@ class OrderOpcControllerCore extends ParentOrderController
'id_customer' => (int)$this->context->customer->id,
'token' => Tools::getToken(false)
);
if (!sizeof($this->errors))
if (!count($this->errors))
$return['isSaved'] = (bool)$this->context->customer->update();
else
$return['isSaved'] = false;
die(Tools::jsonEncode($return));
break;
case 'getAddressBlockAndCarriersAndPayments':
if ($this->context->customer->isLogged())
{
@@ -154,9 +158,10 @@ class OrderOpcControllerCore extends ParentOrderController
}
die(Tools::displayError());
break;
case 'makeFreeOrder':
/* Bypass payment step if total is 0 */
if (($id_order = $this->_checkFreeOrder()) AND $id_order)
if (($id_order = $this->_checkFreeOrder()) && $id_order)
{
$email = $this->context->customer->email;
if ($this->context->customer->is_guest)
@@ -165,6 +170,7 @@ class OrderOpcControllerCore extends ParentOrderController
}
exit;
break;
case 'updateAddressesSelected':
if ($this->context->customer->isLogged(true))
{
@@ -174,7 +180,7 @@ class OrderOpcControllerCore extends ParentOrderController
$this->errors[] = Tools::displayError('This address is not yours.');
elseif (!Address::isCountryActiveById((int)(Tools::getValue('id_address_delivery'))))
$this->errors[] = Tools::displayError('This address is not in a valid area.');
elseif (!Validate::isLoadedObject($address_delivery) OR !Validate::isLoadedObject($address_invoice) OR $address_invoice->deleted OR $address_delivery->deleted)
elseif (!Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted)
$this->errors[] = Tools::displayError('This address is invalid.');
else
{
@@ -183,7 +189,7 @@ class OrderOpcControllerCore extends ParentOrderController
if (!$this->context->cart->update())
$this->errors[] = Tools::displayError('An error occurred while updating your cart.');
if (!sizeof($this->errors))
if (!count($this->errors))
{
$result = $this->_getCarrierList();
// Wrapping fees
@@ -200,11 +206,12 @@ class OrderOpcControllerCore extends ParentOrderController
die(Tools::jsonEncode($result));
}
}
if (sizeof($this->errors))
if (count($this->errors))
die('{"hasError" : true, "errors" : ["'.implode('\',\'', $this->errors).'"]}');
}
die(Tools::displayError());
break;
case 'multishipping':
$this->_assignSummaryInformations();
if ($this->context->customer->id)
@@ -215,6 +222,7 @@ class OrderOpcControllerCore extends ParentOrderController
$this->display();
die();
break;
case 'cartReload':
$this->_assignSummaryInformations();
if ($this->context->customer->id)
@@ -226,10 +234,12 @@ class OrderOpcControllerCore extends ParentOrderController
$this->display();
die();
break;
case 'noMultiAddressDelivery':
$this->context->cart->setNoMultishipping();
die();
break;
default:
throw new PrestaShopException('Unknown method "'.Tools::getValue('method').'"');
}
@@ -280,7 +290,7 @@ class OrderOpcControllerCore extends ParentOrderController
'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'),
'errorCarrier' => Tools::displayError('You must choose a carrier before', false),
'errorTOS' => Tools::displayError('You must accept terms of service before', false),
'isPaymentStep' => (bool)(isset($_GET['isPaymentStep']) AND $_GET['isPaymentStep']),
'isPaymentStep' => (bool)(isset($_GET['isPaymentStep']) && $_GET['isPaymentStep']),
'genders' => Gender::getGenders(),
));
/* Call a hook to display more information on form */
@@ -298,7 +308,7 @@ class OrderOpcControllerCore extends ParentOrderController
));
/* Load guest informations */
if ($this->isLogged AND $this->context->cookie->is_guest)
if ($this->isLogged && $this->context->cookie->is_guest)
$this->context->smarty->assign('guestInformations', $this->_getGuestInformations());
if ($this->isLogged)
@@ -359,7 +369,7 @@ class OrderOpcControllerCore extends ParentOrderController
{
$carriers = $this->context->cart->simulateCarriersOutput();
$this->context->smarty->assign(array(
'HOOK_EXTRACARRIER' => NULL,
'HOOK_EXTRACARRIER' => null,
'HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array(
'carriers' => $carriers,
'checked' => $this->context->cart->simulateCarrierSelectedOutput(),
@@ -386,11 +396,11 @@ class OrderOpcControllerCore extends ParentOrderController
return '<p class="warning">'.Tools::displayError('Please sign in to see payment methods').'</p>';
if ($this->context->cart->OrderExists())
return '<p class="warning">'.Tools::displayError('Error: this order is already validated').'</p>';
if (!$this->context->cart->id_customer OR !Customer::customerIdExistsStatic($this->context->cart->id_customer) OR Customer::isBanned($this->context->cart->id_customer))
if (!$this->context->cart->id_customer || !Customer::customerIdExistsStatic($this->context->cart->id_customer) || Customer::isBanned($this->context->cart->id_customer))
return '<p class="warning">'.Tools::displayError('Error: no customer').'</p>';
$address_delivery = new Address($this->context->cart->id_address_delivery);
$address_invoice = ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice));
if (!$this->context->cart->id_address_delivery OR !$this->context->cart->id_address_invoice OR !Validate::isLoadedObject($address_delivery) OR !Validate::isLoadedObject($address_invoice) OR $address_invoice->deleted OR $address_delivery->deleted)
if (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted)
return '<p class="warning">'.Tools::displayError('Error: please choose an address').'</p>';
if (count($this->context->cart->getDeliveryOptionList()) == 0)
{
@@ -399,11 +409,11 @@ class OrderOpcControllerCore extends ParentOrderController
else
return '<p class="warning">'.Tools::displayError('Error: There are no carriers available that deliver to this address').'</p>';
}
if (!$this->context->cart->getDeliveryOption() AND !$this->context->cart->isVirtualCart())
if (!$this->context->cart->getDeliveryOption() && !$this->context->cart->isVirtualCart())
return '<p class="warning">'.Tools::displayError('Error: please choose a carrier').'</p>';
if (!$this->context->cart->id_currency)
return '<p class="warning">'.Tools::displayError('Error: no currency has been selected').'</p>';
if (!$this->context->cookie->checkedTOS AND Configuration::get('PS_CONDITIONS'))
if (!$this->context->cookie->checkedTOS && Configuration::get('PS_CONDITIONS'))
return '<p class="warning">'.Tools::displayError('Please accept Terms of Service').'</p>';
/* If some products have disappear */
@@ -465,14 +475,10 @@ class OrderOpcControllerCore extends ParentOrderController
Cart::addExtraCarriers($vars);
$this->context->smarty->assign($vars);
if ($this->context->customer->id)
$groups = $this->context->customer->getGroups();
else
$groups = array(1);
if (!Address::isCountryActiveById((int)($this->context->cart->id_address_delivery)) && $this->context->cart->id_address_delivery != 0)
$this->errors[] = Tools::displayError('This address is not in a valid area.');
elseif ((!Validate::isLoadedObject($address_delivery) OR $address_delivery->deleted) && $this->context->cart->id_address_delivery != 0)
elseif ((!Validate::isLoadedObject($address_delivery) || $address_delivery->deleted) && $this->context->cart->id_address_delivery != 0)
$this->errors[] = Tools::displayError('This address is invalid.');
else
{
@@ -487,7 +493,7 @@ class OrderOpcControllerCore extends ParentOrderController
Cart::addExtraCarriers($result);
return $result;
}
if (sizeof($this->errors))
if (count($this->errors))
return array(
'hasError' => true,
'errors' => $this->errors
@@ -507,15 +513,14 @@ class OrderOpcControllerCore extends ParentOrderController
$inv_all_fields = array();
$dlv_all_fields = array();
foreach (array('inv','dlv') as $adr_type)
foreach (array('inv', 'dlv') as $adr_type)
{
foreach (${$adr_type.'_adr_fields'} as $fields_line)
foreach(explode(' ',$fields_line) as $field_item)
foreach (explode(' ', $fields_line) as $field_item)
${$adr_type.'_all_fields'}[] = trim($field_item);
$this->context->smarty->assign($adr_type.'_adr_fields', ${$adr_type.'_adr_fields'});
$this->context->smarty->assign($adr_type.'_all_fields', ${$adr_type.'_all_fields'});
}
}
}
+2 -2
View File
@@ -98,7 +98,7 @@ class ParentOrderControllerCore extends FrontController
$this->errors[] = Tools::displayError('Voucher code invalid');
else
{
if ($cartRule = new CartRule(CartRule::getIdByCode($code)) AND Validate::isLoadedObject($cartRule))
if ($cartRule = new CartRule(CartRule::getIdByCode($code)) && Validate::isLoadedObject($cartRule))
{
if ($error = $cartRule->checkValidity($this->context))
$this->errors[] = $error;
@@ -116,7 +116,7 @@ class ParentOrderControllerCore extends FrontController
'discount_name' => Tools::safeOutput($code)
));
}
elseif ($id_cart_rule = (int)Tools::getValue('deleteDiscount') AND Validate::isUnsignedId($id_cart_rule))
elseif ($id_cart_rule = (int)Tools::getValue('deleteDiscount') && Validate::isUnsignedId($id_cart_rule))
{
$this->context->cart->removeCartRule($id_cart_rule);
Tools::redirect('index.php?controller=order-opc');
+1 -1
View File
@@ -234,7 +234,7 @@ class ProductControllerCore extends FrontController
$id_shop = $this->context->shop->getID(true);
$quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true);
foreach($quantity_discounts as &$quantity_discount)
foreach ($quantity_discounts as &$quantity_discount)
if ($quantity_discount['id_product_attribute'])
{
$combination = new Combination((int)$quantity_discount['id_product_attribute']);