//GuestTrackingController : Refacto done

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8883 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mDeflotte
2011-09-29 14:39:13 +00:00
parent b5a03180f5
commit 38bfdcd843
3 changed files with 114 additions and 88 deletions
+56 -30
View File
@@ -29,18 +29,25 @@ class GuestTrackingControllerCore extends FrontController
{ {
public $php_self = 'guest-tracking'; public $php_self = 'guest-tracking';
/**
* Initialize guest tracking controller
* @see FrontController::init()
*/
public function init() public function init()
{ {
parent::init(); parent::init();
if ($this->context->customer->isLogged()) if ($this->context->customer->isLogged())
Tools::redirect('history.php'); Tools::redirect('history.php');
} }
public function process() /**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
if(Tools::isSubmit('submitGuestTracking') || Tools::isSubmit('submitTransformGuestToCustomer'))
{ {
parent::process();
$id_order = (int)Tools::getValue('id_order'); $id_order = (int)Tools::getValue('id_order');
$email = Tools::getValue('email'); $email = Tools::getValue('email');
$order = new Order((int)$id_order); $order = new Order((int)$id_order);
@@ -55,7 +62,8 @@ class GuestTrackingControllerCore extends FrontController
$this->errors[] = Tools::displayError('There is no account associated with this e-mail address'); $this->errors[] = Tools::displayError('There is no account associated with this e-mail address');
else if (Customer::customerExists($email, false, true)) else if (Customer::customerExists($email, false, true))
{ {
$this->errors[] = Tools::displayError('Your guest account has already been transformed into a customer account. Please log-in to your customer account to view this order, this section is reserved for guest accounts'); $this->errors[] = Tools::displayError('Your guest account has already been transformed into a customer account.
Please log-in to your customer account to view this order, this section is reserved for guest accounts');
$this->context->smarty->assign('show_login_link', true); $this->context->smarty->assign('show_login_link', true);
} }
else if (!Validate::isLoadedObject($order)) else if (!Validate::isLoadedObject($order))
@@ -63,6 +71,45 @@ class GuestTrackingControllerCore extends FrontController
else if (!$order->isAssociatedAtGuest($email)) else if (!$order->isAssociatedAtGuest($email))
$this->errors[] = Tools::displayError('123'); $this->errors[] = Tools::displayError('123');
else else
{
$this->assignOrderTracking($order);
if (Tools::isSubmit('submitTransformGuestToCustomer'))
{
$customer = new Customer((int)$order->id_customer);
if (!Validate::isLoadedObject($customer))
$this->errors[] = Tools::displayError('Invalid customer');
else if (!$customer->transformToCustomer($this->context->language->id, Tools::getValue('password')))
// @todo clarify error message
$this->errors[] = Tools::displayError('An error occurred while transforming guest to customer.');
else if (!Tools::getValue('password'))
$this->errors[] = Tools::displayError('Invalid password');
else
$this->context->smarty->assign('transformSuccess', true);
}
}
}
}
/**
* Assign template vars related to page content
* @see FrontController::process()
*/
public function process()
{
parent::process();
/* Handle brute force attacks */
if (count($this->errors))
sleep(1);
$this->context->smarty->assign(array('action' => $this->context->link->getPageLink('guest-tracking.php'), 'errors' => $this->errors));
$this->setTemplate(_PS_THEME_DIR_.'guest-tracking.tpl');
}
/**
* Assign template vars related to order tracking informations
*/
protected function assignOrderTracking($order)
{ {
$customer = new Customer((int)$order->id_customer); $customer = new Customer((int)$order->id_customer);
$id_order_state = (int)($order->getCurrentState()); $id_order_state = (int)($order->getCurrentState());
@@ -89,15 +136,15 @@ class GuestTrackingControllerCore extends FrontController
'currency' => new Currency($order->id_currency), 'currency' => new Currency($order->id_currency),
'order_state' => (int)($id_order_state), 'order_state' => (int)($id_order_state),
'invoiceAllowed' => (int)(Configuration::get('PS_INVOICE')), 'invoiceAllowed' => (int)(Configuration::get('PS_INVOICE')),
'invoice' => (OrderState::invoiceAvailable((int)($id_order_state)) AND $order->invoice_number), 'invoice' => (OrderState::invoiceAvailable((int)($id_order_state)) && $order->invoice_number),
'order_history' => $order->getHistory((int)$this->context->language->id, false, true), 'order_history' => $order->getHistory((int)$this->context->language->id, false, true),
'products' => $products, 'products' => $products,
'discounts' => $order->getDiscounts(), 'discounts' => $order->getDiscounts(),
'carrier' => $carrier, 'carrier' => $carrier,
'address_invoice' => $addressInvoice, 'address_invoice' => $addressInvoice,
'invoiceState' => (Validate::isLoadedObject($addressInvoice) AND $addressInvoice->id_state) ? new State((int)($addressInvoice->id_state)) : false, 'invoiceState' => (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) ? new State((int)($addressInvoice->id_state)) : false,
'address_delivery' => $addressDelivery, 'address_delivery' => $addressDelivery,
'deliveryState' => (Validate::isLoadedObject($addressDelivery) AND $addressDelivery->id_state) ? new State((int)($addressDelivery->id_state)) : false, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) ? new State((int)($addressDelivery->id_state)) : false,
'is_guest' => true, 'is_guest' => true,
'group_use_tax' => (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC), 'group_use_tax' => (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC),
'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
@@ -106,31 +153,10 @@ class GuestTrackingControllerCore extends FrontController
'customizedDatas' => $customizedDatas, 'customizedDatas' => $customizedDatas,
'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues,
'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues)); 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues));
if ($carrier->url AND $order->shipping_number) if ($carrier->url && $order->shipping_number)
$this->context->smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); $this->context->smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url));
$this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order))); $this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order)));
Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order)); Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order));
if (Tools::isSubmit('submitTransformGuestToCustomer'))
{
$customer = new Customer((int)$order->id_customer);
if (!Validate::isLoadedObject($customer))
$this->errors[] = Tools::displayError('Invalid customer');
if (!$customer->transformToCustomer($this->context->language->id, Tools::getValue('password')))
$this->errors[] = Tools::displayError('An error occurred while transforming guest to customer.');
if (!Tools::getValue('password'))
$this->errors[] = Tools::displayError('Invalid password');
else
$this->context->smarty->assign('transformSuccess', true);
}
}
/* Handle brute force attacks */
if (sizeof($this->errors))
sleep(1);
$this->context->smarty->assign(array('action' => $this->context->link->getPageLink('guest-tracking.php'), 'errors' => $this->errors));
$this->setTemplate(_PS_THEME_DIR_.'guest-tracking.tpl');
} }
public function setMedia() public function setMedia()
+1 -1
View File
@@ -33,5 +33,5 @@ else
$controller->init(); $controller->init();
} }
$controller->processFooter(); $controller->initFooter();
Context::getContext()->smarty->display(_PS_THEME_DIR_.'footer.tpl'); Context::getContext()->smarty->display(_PS_THEME_DIR_.'footer.tpl');
+1 -1
View File
@@ -33,5 +33,5 @@ else
$controller->init(); $controller->init();
} }
$controller->processHeader(); $controller->initHeader();
Context::getContext()->smarty->display(_PS_THEME_DIR_.'header.tpl'); Context::getContext()->smarty->display(_PS_THEME_DIR_.'header.tpl');