// 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
+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'});
}
}
}