Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My account features #4308

@@ -1537,9 +1537,13 @@ public function getTemplateVarCurrency()
return $curr;
}
public function getTemplateVarCustomer()
public function getTemplateVarCustomer($customer = null)
{
$cust = $this->objectSerializer->toArray($this->context->customer);
if (Validate::isLoadedObject($customer)) {
$cust = $this->objectSerializer->toArray($customer);
} else {
$cust = $this->objectSerializer->toArray($this->context->customer);
}
unset($cust['secure_key']);
unset($cust['passwd']);
@@ -51,13 +51,14 @@ public function __construct($objects, $template, $smarty, $orientation = 'P')
{
$this->pdf_renderer = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'), $orientation);
$this->template = $template;
$this->smarty = $smarty;
$this->smarty = $smarty->createData($smarty);
$this->smarty->escape_html = false;
$this->objects = $objects;
if (!($objects instanceof Iterator) && !is_array($objects)) {
$this->objects = array($objects);
}
if (count($this->objects)>1) { // when bulk mode only
$this->send_bulk_flag = true;
}
@@ -24,10 +24,12 @@
* International Registered Trademark & Property of PrestaShop SA
*/
class GuestTrackingControllerCore extends FrontController
class GuestTrackingControllerCore extends OrderDetailController
{
public $ssl = true;
public $auth = false;
public $php_self = 'guest-tracking';
private $order_collection = [];
/**
* Initialize guest tracking controller
@@ -48,57 +50,38 @@ public function init()
public function postProcess()
{
if (Tools::isSubmit('submitGuestTracking') || Tools::isSubmit('submitTransformGuestToCustomer')) {
// These lines are here for retrocompatibility with old theme
$id_order = Tools::getValue('id_order');
$order_collection = array();
if ($id_order) {
if (is_numeric($id_order)) {
$order = new Order((int)$id_order);
if (Validate::isLoadedObject($order)) {
$order_collection = Order::getByReference($order->reference);
}
} else {
$order_collection = Order::getByReference($id_order);
}
}
// Get order reference, ignore package reference (after the #, on the order reference)
$order_reference = current(explode('#', Tools::getValue('order_reference')));
// Ignore $result_number
if (!empty($order_reference)) {
$order_collection = Order::getByReference($order_reference);
$this->order_collection = Order::getByReference($order_reference);
}
$email = Tools::getValue('email');
if (empty($order_reference) && empty($id_order)) {
$this->errors[] = Tools::displayError('Please provide your order\'s reference number.');
} elseif (empty($email)) {
$this->errors[] = Tools::displayError('Please provide a valid email address.');
} elseif (!Validate::isEmail($email)) {
$this->errors[] = Tools::displayError('Please provide a valid email address.');
if (empty($order_reference)) {
$this->errors[] = $this->l('Please provide your order\'s reference number.');
} elseif (empty($email) || !Validate::isEmail($email)) {
$this->errors[] = $this->l('Please provide a valid email address.');
} elseif (!Customer::customerExists($email, false, false)) {
$this->errors[] = Tools::displayError('There is no account associated with this email address.');
$this->errors[] = $this->l('There is no account associated with this email address.');
} elseif (Customer::customerExists($email, false, true)) {
$this->errors[] = Tools::displayError('This page is for guest accounts only. Since your guest account has already been transformed into a customer account, you can no longer view your order here. Please log in to your customer account to view this order');
$this->errors[] = $this->l('This page is for guest accounts only. Since your guest account has already been transformed into a customer account, you can no longer view your order here. Please log in to your customer account to view this order');
$this->context->smarty->assign('show_login_link', true);
} elseif (!count($order_collection)) {
$this->errors[] = Tools::displayError('Invalid order reference');
} elseif (!$order_collection->getFirst()->isAssociatedAtGuest($email)) {
$this->errors[] = Tools::displayError('Invalid order reference');
} elseif (!count($this->order_collection) || $this->order_collection->count() != 1 || !$this->order_collection->getFirst()->isAssociatedAtGuest($email)) {
$this->errors[] = $this->l('Invalid order reference');
} else {
$this->assignOrderTracking($order_collection);
$this->assignOrderTracking($this->order_collection);
if (Tools::isSubmit('submitTransformGuestToCustomer')) {
$customer = new Customer((int)$order->id_customer);
$customer = new Customer((int)$this->order_collection->getFirst()->id_customer);
if (!Validate::isLoadedObject($customer)) {
$this->errors[] = Tools::displayError('Invalid customer');
$this->errors[] = $this->l('Invalid customer');
} elseif (!Tools::getValue('password')) {
$this->errors[] = Tools::displayError('Invalid password.');
$this->errors[] = $this->l('Invalid password.');
} elseif (!$customer->transformToCustomer($this->context->language->id, Tools::getValue('password'))) {
// @todo clarify error message
$this->errors[] = Tools::displayError('An error occurred while transforming a guest into a registered customer.');
$this->errors[] = $this->l('An error occurred while transforming a guest into a registered customer.');
} else {
$this->context->smarty->assign('transformSuccess', true);
$this->success[] = $this->l('Your guest account has been successfully transformed into a customer account. You can now log in as a registered shopper.');
}
}
}
@@ -111,94 +94,54 @@ public function postProcess()
*/
public function initContent()
{
parent::initContent();
FrontController::initContent();
/* Handle brute force attacks */
if (count($this->errors)) {
sleep(1);
}
$this->context->smarty->assign(array(
'action' => $this->context->link->getPageLink('guest-tracking.php', true),
'errors' => $this->errors,
));
$this->setTemplate(_PS_THEME_DIR_.'guest-tracking.tpl');
if (count($this->order_collection) > 0) {
$this->setTemplate('customer/guest-tracking.tpl');
} else {
$this->setTemplate('customer/guest-login.tpl');
}
}
/**
* Assigns template vars related to order tracking information
*
* @param PrestaShopCollection $order_collection
* @param PrestaShopCollection $this->order_collection
*
* @throws PrestaShopException
*/
protected function assignOrderTracking($order_collection)
{
$customer = new Customer((int)$order_collection->getFirst()->id_customer);
$order_collection = ($order_collection->getAll());
$order = $order_collection->getFirst();
$order_list = array();
foreach ($order_collection as $order) {
$order_list[] = $order;
if ((int)$order->isReturnable()) {
$this->info[] = $this->l('You cannot return merchandise with a guest account');
}
foreach ($order_list as &$order) {
/** @var Order $order */
$order->id_order_state = (int)$order->getCurrentState();
$order->invoice = (OrderState::invoiceAvailable((int)$order->id_order_state) && $order->invoice_number);
$order->order_history = $order->getHistory((int)$this->context->language->id, false, true);
$order->carrier = new Carrier((int)$order->id_carrier, (int)$order->id_lang);
$order->address_invoice = new Address((int)$order->id_address_invoice);
$order->address_delivery = new Address((int)$order->id_address_delivery);
$order->inv_adr_fields = AddressFormat::getOrderedAddressFields($order->address_invoice->id_country);
$order->dlv_adr_fields = AddressFormat::getOrderedAddressFields($order->address_delivery->id_country);
$order->invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($order->address_invoice, $order->inv_adr_fields);
$order->deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($order->address_delivery, $order->dlv_adr_fields);
$order->currency = new Currency($order->id_currency);
$order->discounts = $order->getCartRules();
$order->invoiceState = (Validate::isLoadedObject($order->address_invoice) && $order->address_invoice->id_state) ? new State((int)$order->address_invoice->id_state) : false;
$order->deliveryState = (Validate::isLoadedObject($order->address_delivery) && $order->address_delivery->id_state) ? new State((int)$order->address_delivery->id_state) : false;
$order->products = $order->getProducts();
$order->customizedDatas = Product::getAllCustomizedDatas((int)$order->id_cart);
Product::addCustomizationPrice($order->products, $order->customizedDatas);
$order->total_old = $order->total_discounts > 0 ? (float)$order->total_paid - (float)$order->total_discounts : false;
if ($order->carrier->url && $order->shipping_number) {
$order->followup = str_replace('@', $order->shipping_number, $order->carrier->url);
}
$order->hook_orderdetaildisplayed = Hook::exec('displayOrderDetail', array('order' => $order));
Hook::exec('actionOrderDetail', array('carrier' => $order->carrier, 'order' => $order));
$this->order_to_display['data'] = $this->getTemplateVarOrder($order);
$this->order_to_display['products'] = $this->getTemplateVarProducts($order);
$this->order_to_display['history'] = $this->getTemplateVarOrderHistory($order);
$this->order_to_display['addresses'] = $this->getTemplateVarAddresses($order);
$this->order_to_display['shipping'] = $this->getTemplateVarShipping($order);
$this->order_to_display['messages'] = $this->getTemplateVarMessages($order);
$this->order_to_display['carrier'] = $this->getTemplateVarCarrier($order);
$this->order_to_display['data']['followup'] = '';
if ($this->order_to_display['carrier']['url'] && $order->shipping_number) {
$this->order_to_display['data']['followup'] = str_replace('@', $order->shipping_number, $this->order_to_display['carrier']['url']);
}
$this->context->smarty->assign(array(
'shop_name' => Configuration::get('PS_SHOP_NAME'),
'order_collection' => $order_list,
'return_allowed' => false,
'invoiceAllowed' => (int)Configuration::get('PS_INVOICE'),
'is_guest' => true,
'group_use_tax' => (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC),
'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE,
'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD,
'use_tax' => Configuration::get('PS_TAX'),
));
}
$this->order_to_display['customer'] = $this->getTemplateVarCustomer(new Customer($order->id_customer));
public function setMedia()
{
parent::setMedia();
$this->addCSS(_THEME_CSS_DIR_.'history.css');
$this->addCSS(_THEME_CSS_DIR_.'addresses.css');
}
protected function processAddressFormat(Address $delivery, Address $invoice)
{
$inv_adr_fields = AddressFormat::getOrderedAddressFields($invoice->id_country, false, true);
$dlv_adr_fields = AddressFormat::getOrderedAddressFields($delivery->id_country, false, true);
$this->context->smarty->assign('inv_adr_fields', $inv_adr_fields);
$this->context->smarty->assign('dlv_adr_fields', $dlv_adr_fields);
$this->context->smarty->assign([
'order' => $this->order_to_display,
'hook_orderdetaildisplayed' => Hook::exec('displayOrderDetail', ['order' => $order]),
'use_tax' => Configuration::get('PS_TAX'),
]);
}
}
@@ -31,20 +31,6 @@ class HistoryControllerCore extends FrontController
public $authRedirection = 'history';
public $ssl = true;
public function setMedia()
{
parent::setMedia();
$this->addCSS(array(
_THEME_CSS_DIR_.'history.css',
_THEME_CSS_DIR_.'addresses.css'
));
$this->addJS(array(
_THEME_JS_DIR_.'history.js',
_THEME_JS_DIR_.'tools.js' // retro compat themes 1.5
));
$this->addJqueryPlugin(array('scrollTo', 'footable', 'footable-sort'));
}
/**
* Assign template vars related to page content
* @see FrontController::initContent()
@@ -53,21 +39,70 @@ public function initContent()
{
parent::initContent();
if ($orders = Order::getCustomerOrders($this->context->customer->id)) {
foreach ($orders as &$order) {
$myOrder = new Order((int)$order['id_order']);
if (Validate::isLoadedObject($myOrder)) {
$order['virtual'] = $myOrder->isVirtual(false);
}
}
if (Tools::isSubmit('slowvalidation')) {
$this->warning[] = $this->l('If you have just placed an order, it may take a few minutes for it to be validated. Please refresh this page if your order is missing.');
}
$orders = $this->getTemplateVarOrders();
if (count($orders) <= 0) {
$this->warning[] = $this->l('You have not placed any orders.');
}
$this->context->smarty->assign(array(
$this->context->smarty->assign([
'orders' => $orders,
'invoiceAllowed' => (int)Configuration::get('PS_INVOICE'),
'reorderingAllowed' => !(bool)Configuration::get('PS_DISALLOW_HISTORY_REORDERING'),
'slowValidation' => Tools::isSubmit('slowvalidation')
));
]);
$this->setTemplate('customer/history.tpl');
}
public function getTemplateVarOrders()
{
$orders = [];
$customer_orders = Order::getCustomerOrders($this->context->customer->id);
foreach ($customer_orders as $customer_order) {
$myOrder = new Order((int)$customer_order['id_order']);
if (Validate::isLoadedObject($myOrder)) {
$orders[$customer_order['id_order']] = $customer_order;
$orders[$customer_order['id_order']]['virtual'] = $myOrder->isVirtual(false);
$orders[$customer_order['id_order']]['reference'] = Order::getUniqReferenceOf($customer_order['id_order']);
$orders[$customer_order['id_order']]['order_date'] = Tools::displayDate($customer_order['date_add'], null, false);
$orders[$customer_order['id_order']]['total_price'] = Tools::displayPrice($customer_order['total_paid'], (int)$customer_order['id_currency']);
$orders[$customer_order['id_order']]['contrast'] = (Tools::getBrightness($customer_order['order_state_color']) > 128) ? 'dark' : 'bright';
$orders[$customer_order['id_order']]['url_to_invoice'] = HistoryController::getUrlToInvoice($myOrder, $this->context);
$orders[$customer_order['id_order']]['url_details'] = $this->context->link->getPageLink('order-detail', true, null, 'id_order='.(int)$customer_order['id_order']);
$orders[$customer_order['id_order']]['url_to_reorder'] = HistoryController::getUrlToReorder((int)$customer_order['id_order'], $this->context);
}
}
return $orders;
}
public static function getUrlToInvoice($order, $context)
{
$url_to_invoice = '';
if ((bool)Configuration::get('PS_INVOICE') && OrderState::invoiceAvailable($order->current_state) && count($order->getInvoicesCollection())) {
$url_to_invoice = $context->link->getPageLink('pdf-invoice', true, null, 'id_order='.$order->id);
if ($context->cookie->is_guest) {
$url_to_invoice .= '&amp;secure_key='.$order->secure_key;
}
}
return $url_to_invoice;
}
public static function getUrlToReorder($id_order, $context)
{
$url_to_reorder = '';
if (!(bool)Configuration::get('PS_DISALLOW_HISTORY_REORDERING')) {
if ((bool)Configuration::get('PS_ORDER_PROCESS_TYPE')) {
$url_to_reorder = $context->link->getPageLink('order-opc', true, null, 'submitReorder&id_order='.(int)$id_order);
} else {
$url_to_reorder = $context->link->getPageLink('order', true, null, 'submitReorder&id_order='.(int)$id_order);
}
}
$this->setTemplate(_PS_THEME_DIR_.'history.tpl');
return $url_to_reorder;
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.