bebeboutik/override/controllers/OrderDetailController.php
2017-08-18 11:18:06 +02:00

267 lines
11 KiB
PHP
Executable File

<?php
class OrderDetailController extends OrderDetailControllerCore {
public function setMedia() {
parent::setMedia();
global $css_files;
$css_files = array_slice($css_files, 0, 1);
if (Tools::getValue('ajax') != 'true') {
Tools::addJS(_THEME_JS_DIR_.'history.js');
}
}
public function preProcess() {
// This function is rewritten and splitted to support non-ajax requests
global $page_name;
if(!isset($this->php_self)) {
$this->php_self = strtolower(basename($_SERVER['PHP_SELF']));
}
if($this->php_self == '404.php') {
$page_name = 'page-404';
} else {
if(preg_match('#^'.__PS_BASE_URI__.'modules/([a-zA-Z0-9_-]+?)/([^?]*)(\?(.*))?$#', strtolower($_SERVER['REQUEST_URI']), $m)) {
$page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]);
} else {
$page_name = preg_replace('/\.php$/', '', $this->php_self);
}
}
self::$smarty->assign(array('page_name' => $page_name));
$displayLeft = array(
'page-404', 'address', 'addresses', 'authentication', 'best-sales',
'breadcrumb', 'category', 'category-cms-tree-branch',
'category-tree-branch', 'cms', 'contact-form', 'discount',
'errors', 'footer', 'guest-tracking', 'header', 'history',
'identity', 'index', 'maintenance', 'manufacturer',
'manufacturer-list', 'my-account', 'new-products', 'order',
'order-address', 'order-carrier', 'order-confirmation',
'order-detail', 'order-follow', 'order-opc',
'order-opc-new-account', 'order-payment', 'order-return',
'order-slip', 'order-steps', 'pagination', 'password', 'payment',
'prices-drop', 'product', 'product-compare', 'product-list',
'products-comparison', 'product-sort', 'restricted-country',
'scenes', 'search', 'shopping-cart', 'shopping-cart-product-line',
'sitemap', 'store_infos', 'stores', 'supplier', 'supplier-list',
'module-privatesales-salechange', 'module-invite-invite-program',
'module-referralprogram-referral-program', 'module-cheque-payment',
'module-bankwire-payment', 'module-invite-invite-rules',
);
if($page_name == 'index') {
global $cookie;
if($cookie->isLogged()) {
$displayLeft[] = 'index';
}
}
$displayRight = array(
'page-404', 'address', 'addresses', 'authentication', 'best-sales',
'breadcrumb', 'category', 'category-cms-tree-branch',
'category-tree-branch', 'cms', 'contact-form', 'discount',
'errors', 'footer', 'guest-tracking', 'header', 'history',
'identity', 'index', 'maintenance', 'manufacturer',
'manufacturer-list', 'my-account', 'new-products', 'order',
'order-address', 'order-carrier', 'order-confirmation',
'order-detail', 'order-follow', 'order-opc',
'order-opc-new-account', 'order-payment', 'order-return',
'order-slip', 'order-steps', 'pagination', 'password', 'payment',
'prices-drop', 'product', 'product-compare', 'product-list',
'products-comparison', 'product-sort', 'restricted-country',
'scenes', 'search', 'shopping-cart', 'shopping-cart-product-line',
'sitemap', 'store_infos', 'stores', 'supplier', 'supplier-list',
'module-privatesales-salechange', 'module-invite-invite-program',
'module-referralprogram-referral-program', 'module-cheque-payment',
'module-bankwire-payment', 'module-invite-invite-rules',
);
$countCols = count(array_keys($displayLeft + $displayRight, $page_name));
$bodyClass = 'singleCol';
if($countCols == 1) {
$bodyClass = 'doubleCol';
} elseif($countCols == 2) {
$bodyClass = 'tripleCol';
}
/**
* @Override Antadis
* Check if we can change delivery address
*/
$delivery_can_be_changed = false;
if(Tools::getValue('id_order')) {
$order = new Order((int)Tools::getValue('id_order'));
$sent_by_philea = Db::getInstance()->getValue('
SELECT COUNT(`id_order`)
FROM `'._DB_PREFIX_.'philea_sent`
WHERE `id_order`='.(int)$order->id
);
if (in_array($order->getCurrentState(), array(1,2,3,9,10,11,12,13))
&& !in_array($order->id_carrier,explode(",",Configuration::get('ANT_CARRIERS_MR')))
&& (int)$sent_by_philea == 0
) {
$delivery_can_be_changed = true;
}
}
self::$smarty->assign(array(
'displayLeft' => $displayLeft,
'displayRight' => $displayRight,
'bodyClass' => $bodyClass,
'delivery_can_be_changed' => $delivery_can_be_changed,
));
Module::hookExec('preprocess');
if(Tools::isSubmit('submitMessage')) {
$idOrder = (int)(Tools::getValue('id_order'));
$msgText = htmlentities(Tools::getValue('msgText'), ENT_COMPAT, 'UTF-8');
if(!$idOrder OR !Validate::isUnsignedId($idOrder)) {
$this->errors[] = Tools::displayError('Order is no longer valid');
}
elseif(empty($msgText)) {
$this->errors[] = Tools::displayError('Message cannot be blank');
}
elseif(!Validate::isMessage($msgText)) {
$this->errors[] = Tools::displayError('Message is invalid (HTML is not allowed)');
}
if(!sizeof($this->errors)) {
$order = new Order((int)($idOrder));
if(Validate::isLoadedObject($order) AND $order->id_customer == self::$cookie->id_customer) {
$message = new Message();
$message->id_customer = (int)(self::$cookie->id_customer);
$message->message = $msgText;
$message->id_order = (int)($idOrder);
$message->private = false;
$message->add();
if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE')) {
$to = strval(Configuration::get('PS_SHOP_EMAIL'));
} else {
$to = new Contact((int)(Configuration::get('PS_MAIL_EMAIL_MESSAGE')));
$to = strval($to->email);
}
$toName = strval(Configuration::get('PS_SHOP_NAME'));
$customer = new Customer((int)(self::$cookie->id_customer));
if(Validate::isLoadedObject($customer)) {
Mail::Send((int)(self::$cookie->id_lang), 'order_customer_comment', Mail::l('Message from a customer'),
array(
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{email}' => $customer->email,
'{id_order}' => (int)($message->id_order),
'{message}' => $message->message),
$to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname);
}
if(Tools::getValue('ajax') != 'true') {
Tools::redirect('order-detail.php?id_order='.(int)($idOrder));
}
} else {
$this->errors[] = Tools::displayError('Order not found');
}
}
}
}
public function process() {
if(!$id_order = (int)(Tools::getValue('id_order')) OR !Validate::isUnsignedId($id_order)) {
$this->errors[] = Tools::displayError('Order ID required');
} else {
$order = new Order($id_order);
if(Validate::isLoadedObject($order) AND $order->id_customer == self::$cookie->id_customer) {
$id_order_state = (int)($order->getCurrentState());
$carrier = new Carrier((int)($order->id_carrier), (int)($order->id_lang));
$addressInvoice = new Address((int)($order->id_address_invoice));
$addressDelivery = new Address((int)($order->id_address_delivery));
// $stateInvoiceAddress = new State((int)$addressInvoice->id_state);
$inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country);
$dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country);
$invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields);
$deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields);
if($order->total_discounts > 0) {
self::$smarty->assign('total_old', (float)($order->total_paid - $order->total_discounts));
}
$products = $order->getProducts();
$customizedDatas = Product::getAllCustomizedDatas((int)($order->id_cart));
Product::addCustomizationPrice($products, $customizedDatas);
$customer = new Customer($order->id_customer);
$numbers = Db::getInstance()->ExecuteS('
SELECT p.*
FROM `'._DB_PREFIX_.'lapostews` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` o ON o.`id_order_detail` = p.`id_order_detail`
WHERE o.`id_order` = ' .(int)$order->id . '
ORDER BY `date_add`
');
$numbers2 = Db::getInstance()->ExecuteS('
SELECT p.*
FROM `'._DB_PREFIX_.'mondialrelay_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` o ON o.`id_order_detail` = p.`id_order_detail`
WHERE o.`id_order` = ' .(int)$order->id . '
ORDER BY `date_add`
');
// assign delay to Products
if (Module::isInstalled('privatesales_delay')) {
if (!class_exists('SaleDelay')) {
require_once _PS_ROOT_DIR_.'/modules/privatesales_delay/saledelay.php';
}
$products = SaleDelay::associateDelay($products);
$delays = array_keys($products);
$date = new DateTime($order->date_add);
$delivery_date = SaleDelay::getDeliveryDate($delays, null, $date, true);
}
self::$smarty->assign(array(
'delivery_date' => $delivery_date,
'shop_name' => strval(Configuration::get('PS_SHOP_NAME')),
'order' => $order,
'numbers' => $numbers,
'numbers2' => $numbers2,
'return_allowed' => (int)($order->isReturnable()),
'currency' => new Currency($order->id_currency),
'order_state' => (int)($id_order_state),
'invoiceAllowed' => (int)(Configuration::get('PS_INVOICE')),
'invoice' => (OrderState::invoiceAvailable((int)($id_order_state)) && $order->invoice_number),
'order_history' => $order->getHistory((int)(self::$cookie->id_lang), false, true),
'products' => $products,
'discounts' => $order->getDiscounts(),
'carrier' => $carrier,
'address_invoice' => $addressInvoice,
'invoiceState' => (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) ? new State((int)($addressInvoice->id_state)) : false,
'address_delivery' => $addressDelivery,
'inv_adr_fields' => $inv_adr_fields,
'dlv_adr_fields' => $dlv_adr_fields,
'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues,
'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues,
'deliveryState' => (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) ? new State((int)($addressDelivery->id_state)) : false,
'is_guest' => false,
'messages' => Message::getMessagesByOrderId((int)($order->id)),
'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'),
'use_tax' => Configuration::get('PS_TAX'),
'group_use_tax' => (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC),
'customizedDatas' => $customizedDatas));
if($carrier->url && $order->shipping_number) {
self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url));
}
self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order)));
Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order));
unset($carrier);
unset($addressInvoice);
unset($addressDelivery);
} else {
$this->errors[] = Tools::displayError('Cannot find this order');
}
unset($order);
}
}
}