//PasswordController+PdfInvoiceController+PdfOrderReturnController+PdfOrederSlipController+PricesDropController : Refacto done

This commit is contained in:
mDeflotte
2011-09-28 13:56:53 +00:00
parent 80b9d8deca
commit 2f6dc0cc37
5 changed files with 62 additions and 33 deletions
+26 -13
View File
@@ -31,11 +31,15 @@ class PasswordControllerCore extends FrontController
{ {
public $php_self = 'password'; public $php_self = 'password';
public function process() /**
* Start forms process
* @see FrontController::preProcess()
*/
public function preProcess()
{ {
if (Tools::isSubmit('email')) if (Tools::isSubmit('email'))
{ {
if (!($email = Tools::getValue('email')) OR !Validate::isEmail($email)) if (!($email = Tools::getValue('email')) || !Validate::isEmail($email))
$this->errors[] = Tools::displayError('Invalid e-mail address'); $this->errors[] = Tools::displayError('Invalid e-mail address');
else else
{ {
@@ -50,10 +54,11 @@ class PasswordControllerCore extends FrontController
else else
{ {
if (Mail::Send($this->context->language->id, 'password_query', Mail::l('Password query confirmation'), if (Mail::Send($this->context->language->id, 'password_query', Mail::l('Password query confirmation'),
array('{email}' => $customer->email, array(
'{lastname}' => $customer->lastname, '{email}' => $customer->email,
'{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname,
'{url}' => $this->context->link->getPageLink('password', true, NULL, 'token='.$customer->secure_key.'&id_customer='.(int)$customer->id)), '{firstname}' => $customer->firstname,
'{url}' => $this->context->link->getPageLink('password', true, null, 'token='.$customer->secure_key.'&id_customer='.(int)$customer->id)),
$customer->email, $customer->email,
$customer->firstname.' '.$customer->lastname)) $customer->firstname.' '.$customer->lastname))
$this->context->smarty->assign(array('confirmation' => 2, 'email' => $customer->email)); $this->context->smarty->assign(array('confirmation' => 2, 'email' => $customer->email));
@@ -63,7 +68,7 @@ class PasswordControllerCore extends FrontController
} }
} }
} }
elseif (($token = Tools::getValue('token')) && ($id_customer = (int)(Tools::getValue('id_customer')))) else if (($token = Tools::getValue('token')) && ($id_customer = (int)(Tools::getValue('id_customer'))))
{ {
$email = Db::getInstance()->getValue('SELECT `email` FROM '._DB_PREFIX_.'customer c WHERE c.`secure_key` = "'.pSQL($token).'" AND c.id_customer='.(int)($id_customer)); $email = Db::getInstance()->getValue('SELECT `email` FROM '._DB_PREFIX_.'customer c WHERE c.`secure_key` = "'.pSQL($token).'" AND c.id_customer='.(int)($id_customer));
if ($email) if ($email)
@@ -79,10 +84,11 @@ class PasswordControllerCore extends FrontController
if ($customer->update()) if ($customer->update())
{ {
if (Mail::Send($this->context->language->id, 'password', Mail::l('Your password'), if (Mail::Send($this->context->language->id, 'password', Mail::l('Your password'),
array('{email}' => $customer->email, array(
'{lastname}' => $customer->lastname, '{email}' => $customer->email,
'{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname,
'{passwd}' => $password), '{firstname}' => $customer->firstname,
'{passwd}' => $password),
$customer->email, $customer->email,
$customer->firstname.' '.$customer->lastname)) $customer->firstname.' '.$customer->lastname))
$this->context->smarty->assign(array('confirmation' => 1, 'email' => $customer->email)); $this->context->smarty->assign(array('confirmation' => 1, 'email' => $customer->email));
@@ -96,9 +102,16 @@ class PasswordControllerCore extends FrontController
else else
$this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted'); $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted');
} }
elseif (($token = Tools::getValue('token')) || ($id_customer = Tools::getValue('id_customer'))) else if (($token = Tools::getValue('token')) || ($id_customer = Tools::getValue('id_customer')))
$this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted'); $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted');
}
/**
* Assign template vars related to page content
* @see FrontController::process()
*/
public function process()
{
$this->setTemplate(_PS_THEME_DIR_.'password.tpl'); $this->setTemplate(_PS_THEME_DIR_.'password.tpl');
} }
} }
+11 -7
View File
@@ -27,22 +27,26 @@
class PdfInvoiceControllerCore extends FrontController class PdfInvoiceControllerCore extends FrontController
{ {
/**
* Assign template vars related to page content
* @see FrontController::process()
*/
public function process() public function process()
{ {
$this->displayHeader(false); $this->displayHeader(false);
$this->displayFooter(false); $this->displayFooter(false);
if (!$this->context->customer->isLogged() AND !Tools::getValue('secure_key')) if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key'))
Tools::redirect('index.php?controller=authentication&back=pdf-invoice'); Tools::redirect('index.php?controller=authentication&back=pdf-invoice');
if (!(int)(Configuration::get('PS_INVOICE'))) if (!(int)(Configuration::get('PS_INVOICE')))
die(Tools::displayError('Invoices are disabled in this shop.')); die(Tools::displayError('Invoices are disabled in this shop.'));
if (isset($_GET['id_order']) AND Validate::isUnsignedId($_GET['id_order'])) if (isset($_GET['id_order']) && Validate::isUnsignedId($_GET['id_order']))
$order = new Order((int)($_GET['id_order'])); $order = new Order((int)($_GET['id_order']));
if (!isset($order) OR !Validate::isLoadedObject($order)) if (!isset($order) || !Validate::isLoadedObject($order))
die(Tools::displayError('Invoice not found')); die(Tools::displayError('Invoice not found'));
elseif ((isset($this->context->customer->id) AND $order->id_customer != $this->context->customer->id) OR (Tools::isSubmit('secure_key') AND $order->secure_key != Tools::getValue('secure_key'))) else if ((isset($this->context->customer->id) && $order->id_customer != $this->context->customer->id) || (Tools::isSubmit('secure_key') && $order->secure_key != Tools::getValue('secure_key')))
die(Tools::displayError('Invoice not found')); die(Tools::displayError('Invoice not found'));
elseif (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number) else if (!OrderState::invoiceAvailable($order->getCurrentState()) && !$order->invoice_number)
die(Tools::displayError('No invoice available')); die(Tools::displayError('No invoice available'));
else else
PDF::invoice($order); PDF::invoice($order);
@@ -27,6 +27,10 @@
class PdfOrderReturnControllerCore extends FrontController class PdfOrderReturnControllerCore extends FrontController
{ {
/**
* Assign template vars related to page content
* @see FrontController::process()
*/
public function process() public function process()
{ {
$this->displayHeader(false); $this->displayHeader(false);
@@ -35,14 +39,14 @@ class PdfOrderReturnControllerCore extends FrontController
if (!$this->context->customer->isLogged()) if (!$this->context->customer->isLogged())
Tools::redirect('index.php?controller=authentication&back=order-follow'); Tools::redirect('index.php?controller=authentication&back=order-follow');
if (isset($_GET['id_order_return']) AND Validate::isUnsignedId($_GET['id_order_return'])) if (isset($_GET['id_order_return']) && Validate::isUnsignedId($_GET['id_order_return']))
$orderReturn = new OrderReturn((int)($_GET['id_order_return'])); $orderReturn = new OrderReturn((int)($_GET['id_order_return']));
if (!isset($orderReturn) OR !Validate::isLoadedObject($orderReturn)) if (!isset($orderReturn) || !Validate::isLoadedObject($orderReturn))
die(Tools::displayError('Order return not found')); die(Tools::displayError('Order return not found'));
else if ($orderReturn->id_customer != $this->context->customer->id) else if ($orderReturn->id_customer != $this->context->customer->id)
die(Tools::displayError('Order return not found')); die(Tools::displayError('Order return not found'));
else if ($orderReturn->state < 2) else if ($orderReturn->state < 2)
die(Tools::displayError('Order return not confirmed')); die(Tools::displayError('Order return not confirmed'));
else else
PDF::orderReturn($orderReturn); PDF::orderReturn($orderReturn);
} }
+11 -7
View File
@@ -27,6 +27,10 @@
class PdfOrderSlipControllerCore extends FrontController class PdfOrderSlipControllerCore extends FrontController
{ {
/**
* Assign template vars related to page content
* @see FrontController::process()
*/
public function process() public function process()
{ {
$this->displayHeader(false); $this->displayHeader(false);
@@ -35,17 +39,17 @@ class PdfOrderSlipControllerCore extends FrontController
if (!$this->context->customer->isLogged()) if (!$this->context->customer->isLogged())
Tools::redirect('index.php?controller=authentication&back=order-follow'); Tools::redirect('index.php?controller=authentication&back=order-follow');
if (isset($_GET['id_order_slip']) AND Validate::isUnsignedId($_GET['id_order_slip'])) if (isset($_GET['id_order_slip']) && Validate::isUnsignedId($_GET['id_order_slip']))
$orderSlip = new OrderSlip((int)($_GET['id_order_slip'])); $orderSlip = new OrderSlip((int)($_GET['id_order_slip']));
if (!isset($orderSlip) OR !Validate::isLoadedObject($orderSlip)) if (!isset($orderSlip) || !Validate::isLoadedObject($orderSlip))
die(Tools::displayError('Order return not found')); die(Tools::displayError('Order return not found'));
elseif ($orderSlip->id_customer != $this->context->customer->id) else if ($orderSlip->id_customer != $this->context->customer->id)
die(Tools::displayError('Order return not found')); die(Tools::displayError('Order return not found'));
$order = new Order((int)($orderSlip->id_order)); $order = new Order((int)($orderSlip->id_order));
if (!Validate::isLoadedObject($order)) if (!Validate::isLoadedObject($order))
die(Tools::displayError('Order not found')); die(Tools::displayError('Order not found'));
$order->products = OrderSlip::getOrdersSlipProducts((int)($orderSlip->id), $order); $order->products = OrderSlip::getOrdersSlipProducts((int)($orderSlip->id), $order);
$ref = NULL; $ref = null;
PDF::invoice($order, 'D', false, $ref, $orderSlip); PDF::invoice($order, 'D', false, $ref, $orderSlip);
} }
} }
+5 -1
View File
@@ -35,10 +35,14 @@ class PricesDropControllerCore extends FrontController
$this->addCSS(_THEME_CSS_DIR_.'product_list.css'); $this->addCSS(_THEME_CSS_DIR_.'product_list.css');
} }
/**
* Assign template vars related to page content
* @see FrontController::process()
*/
public function process() public function process()
{ {
$this->productSort(); $this->productSort();
$nbProducts = Product::getPricesDrop($this->context->language->id, NULL, NULL, true); $nbProducts = Product::getPricesDrop($this->context->language->id, null, null, true);
$this->pagination($nbProducts); $this->pagination($nbProducts);
$this->context->smarty->assign(array( $this->context->smarty->assign(array(