public function viewcustomer() { global $currentIndex, $cookie, $link; $irow = 0; $configurations = Configuration::getMultiple(array('PS_LANG_DEFAULT', 'PS_CURRENCY_DEFAULT')); $defaultLanguage = (int) $configurations['PS_LANG_DEFAULT']; $defaultCurrency = (int) $configurations['PS_CURRENCY_DEFAULT']; if (!($customer = $this->loadObject())) { return; } $customerStats = $customer->getStats(); $addresses = $customer->getAddresses($defaultLanguage); $products = $customer->getBoughtProducts(); $discounts = Discount::getCustomerDiscounts($defaultLanguage, (int) $customer->id, false, false); $orders = Order::getCustomerOrders((int) $customer->id, true); $carts = Cart::getCustomerCarts((int) $customer->id); $groups = $customer->getGroups(); $messages = CustomerThread::getCustomerMessages((int) $customer->id); $referrers = Referrer::getReferrers((int) $customer->id); if ($totalCustomer = Db::getInstance()->getValue('SELECT SUM(total_paid_real) FROM ' . _DB_PREFIX_ . 'orders WHERE id_customer = ' . $customer->id . ' AND valid = 1')) { Db::getInstance()->getValue('SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 GROUP BY id_customer HAVING SUM(total_paid_real) > ' . $totalCustomer); $countBetterCustomers = (int) Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1; } else { $countBetterCustomers = '-'; } echo ' <fieldset style="width:400px;float: left"><div style="float: right"><a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a></div> <span style="font-weight: bold; font-size: 14px;">' . $customer->firstname . ' ' . $customer->lastname . '</span> <img src="../img/admin/' . ($customer->id_gender == 2 ? 'female' : ($customer->id_gender == 1 ? 'male' : 'unknown')) . '.gif" style="margin-bottom: 5px" /><br /> <a href="mailto:' . $customer->email . '" style="text-decoration: underline; color: blue">' . $customer->email . '</a><br /><br /> ' . $this->l('ID:') . ' ' . sprintf('%06d', $customer->id) . '<br /> ' . $this->l('Registration date:') . ' ' . Tools::displayDate($customer->date_add, (int) $cookie->id_lang, true) . '<br /> ' . $this->l('Last visit:') . ' ' . ($customerStats['last_visit'] ? Tools::displayDate($customerStats['last_visit'], (int) $cookie->id_lang, true) : $this->l('never')) . '<br /> ' . ($countBetterCustomers != '-' ? $this->l('Rank: #') . ' ' . (int) $countBetterCustomers . '<br />' : '') . ' </fieldset> <fieldset style="width:300px;float:left;margin-left:50px"> <div style="float: right"> <a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a> </div> ' . $this->l('Newsletter:') . ' ' . ($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br /> ' . $this->l('Opt-in:') . ' ' . ($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br /> ' . $this->l('Age:') . ' ' . $customerStats['age'] . ' ' . (!empty($customer->birthday['age']) ? '(' . Tools::displayDate($customer->birthday, (int) $cookie->id_lang) . ')' : $this->l('unknown')) . '<br /><br /> ' . $this->l('Last update:') . ' ' . Tools::displayDate($customer->date_upd, (int) $cookie->id_lang, true) . '<br /> ' . $this->l('Status:') . ' ' . ($customer->active ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />'); if ($customer->isGuest()) { echo ' <div> ' . $this->l('This customer is registered as') . ' <b>' . $this->l('guest') . '</b>'; if (!Customer::customerExists($customer->email)) { echo ' <form method="POST" action="index.php?tab=AdminCustomers&id_customer=' . (int) $customer->id . '&token=' . Tools::getAdminTokenLite('AdminCustomers') . '"> <input type="hidden" name="id_lang" value="' . (int) (sizeof($orders) ? $orders[0]['id_lang'] : Configuration::get('PS_LANG_DEFAULT')) . '" /> <p class="center"><input class="button" type="submit" name="submitGuestToCustomer" value="' . $this->l('Transform to customer') . '" /></p> ' . $this->l('This feature generates a random password and sends an e-mail to the customer') . '</form>'; } else { echo '</div><div><b style="color:red;">' . $this->l('A registered customer account exists with the same email address') . '</b>'; } echo ' </div> '; } echo ' </fieldset> <div class="clear"> </div>'; echo '<fieldset style="height:190px"><legend><img src="../img/admin/cms.gif" /> ' . $this->l('Add a private note') . '</legend> <p>' . $this->l('This note will be displayed to all the employees but not to the customer.') . '</p> <form action="ajax.php" method="post" onsubmit="saveCustomerNote();return false;" id="customer_note"> <textarea name="note" id="noteContent" style="width:600px;height:100px" onkeydown="$(\'#submitCustomerNote\').removeAttr(\'disabled\');">' . Tools::htmlentitiesUTF8($customer->note) . '</textarea><br /> <input type="submit" id="submitCustomerNote" class="button" value="' . $this->l(' Save ') . '" style="float:left;margin-top:5px" disabled="disabled" /> <span id="note_feedback" style="float:left;margin:10px 0 0 10px"></span> </form> </fieldset> <div class="clear"> </div> <script type="text/javascript"> function saveCustomerNote() { $("#note_feedback").html("<img src=\\"../img/loader.gif\\" />").show(); var noteContent = $("#noteContent").val(); $.post("ajax.php", {submitCustomerNote:1,id_customer:' . (int) $customer->id . ',note:noteContent}, function (r) { $("#note_feedback").html("").hide(); if (r == "ok") { $("#note_feedback").html("<b style=\\"color:green\\">' . addslashes($this->l('Your note has been saved')) . '</b>").fadeIn(400); $("#submitCustomerNote").attr("disabled", "disabled"); } else if (r == "error:validation") $("#note_feedback").html("<b style=\\"color:red\\">' . addslashes($this->l('Error: your note is not valid')) . '</b>").fadeIn(400); else if (r == "error:update") $("#note_feedback").html("<b style=\\"color:red\\">' . addslashes($this->l('Error: cannot save your note')) . '</b>").fadeIn(400); $("#note_feedback").fadeOut(3000); }); } </script>'; echo '<h2>' . $this->l('Messages') . ' (' . sizeof($messages) . ')</h2>'; if (sizeof($messages)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('Status') . '</th> <th class="center">' . $this->l('Message') . '</th> <th class="center">' . $this->l('Sent on') . '</th> </tr>'; foreach ($messages as $message) { echo '<tr> <td>' . $message['status'] . '</td> <td><a href="index.php?tab=AdminCustomerThreads&id_customer_thread=' . (int) $message['id_customer_thread'] . '&viewcustomer_thread&token=' . Tools::getAdminTokenLite('AdminCustomerThreads') . '">' . substr(strip_tags(html_entity_decode($message['message'], ENT_NOQUOTES, 'UTF-8')), 0, 75) . '...</a></td> <td>' . Tools::displayDate($message['date_add'], (int) $cookie->id_lang, true) . '</td> </tr>'; } echo '</table> <div class="clear"> </div>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has never contacted you.'); } // display hook specified to this page : AdminCustomers if (($hook = Module::hookExec('adminCustomers', array('id_customer' => $customer->id))) !== false) { echo '<div>' . $hook . '</div>'; } echo '<div class="clear"> </div>'; echo '<h2>' . $this->l('Groups') . ' (' . sizeof($groups) . ')</h2>'; if ($groups and sizeof($groups)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Name') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenGroups = Tools::getAdminToken('AdminGroups' . (int) Tab::getIdFromClassName('AdminGroups') . (int) $cookie->id_employee); foreach ($groups as $group) { $objGroup = new Group($group); echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '\'"> <td class="center">' . $objGroup->id . '</td> <td>' . $objGroup->name[$defaultLanguage] . '</td> <td align="center"><a href="?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } echo '<div class="clear"> </div>'; echo '<h2>' . $this->l('Orders') . ' (' . sizeof($orders) . ')</h2>'; if ($orders and sizeof($orders)) { $totalOK = 0; $ordersOK = array(); $ordersKO = array(); $tokenOrders = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee); foreach ($orders as $order) { if ($order['valid']) { $ordersOK[] = $order; $totalOK += $order['total_paid_real']; } else { $ordersKO[] = $order; } } $orderHead = ' <table cellspacing="0" cellpadding="0" class="table float"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Products') . '</th> <th class="center">' . $this->l('Total paid') . '</th> <th class="center">' . $this->l('Payment') . '</th> <th class="center">' . $this->l('State') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $orderFoot = '</table>'; if ($countOK = sizeof($ordersOK)) { echo '<div style="float:left;margin-right:20px"><h3 style="color:green;font-weight:700">' . $this->l('Valid orders:') . ' ' . $countOK . ' ' . $this->l('for') . ' ' . Tools::displayPrice($totalOK, new Currency($defaultCurrency)) . '</h3>' . $orderHead; foreach ($ordersOK as $order) { echo '<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td class="center">' . $order['id_order'] . '</td> <td>' . Tools::displayDate($order['date_add'], (int) $cookie->id_lang) . '</td> <td align="right">' . $order['nb_products'] . '</td> <td align="right">' . Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])) . '</td> <td>' . $order['payment'] . '</td> <td>' . $order['order_state'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo $orderFoot . '</div>'; } if ($countKO = sizeof($ordersKO)) { echo '<div style="float:left;margin-right:20px"><h3 style="color:red;font-weight:700">' . $this->l('Invalid orders:') . ' ' . $countKO . '</h3>' . $orderHead; foreach ($ordersKO as $order) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td class="center">' . $order['id_order'] . '</td> <td>' . Tools::displayDate($order['date_add'], (int) $cookie->id_lang) . '</td> <td align="right">' . $order['nb_products'] . '</td> <td align="right">' . Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])) . '</td> <td>' . $order['payment'] . '</td> <td>' . $order['order_state'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo $orderFoot . '</div><div class="clear"> </div>'; } } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not placed any orders yet'); } if ($products and sizeof($products)) { echo '<div class="clear"> </div> <h2>' . $this->l('Products') . ' (' . sizeof($products) . ')</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Name') . '</th> <th class="center">' . $this->l('Quantity') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenOrders = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee); foreach ($products as $product) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $product['id_order'] . '&vieworder&token=' . $tokenOrders . '\'"> <td>' . Tools::displayDate($product['date_add'], (int) $cookie->id_lang, true) . '</td> <td>' . $product['product_name'] . '</td> <td align="right">' . $product['product_quantity'] . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $product['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } echo '<div class="clear"> </div> <h2>' . $this->l('Addresses') . ' (' . sizeof($addresses) . ')</h2>'; if (sizeof($addresses)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th>' . $this->l('Company') . '</th> <th>' . $this->l('Name') . '</th> <th>' . $this->l('Address') . '</th> <th>' . $this->l('Country') . '</th> <th>' . $this->l('Phone number(s)') . '</th> <th>' . $this->l('Actions') . '</th> </tr>'; $tokenAddresses = Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee); foreach ($addresses as $address) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '> <td>' . ($address['company'] ? $address['company'] : '--') . '</td> <td>' . $address['firstname'] . ' ' . $address['lastname'] . '</td> <td>' . $address['address1'] . ($address['address2'] ? ' ' . $address['address2'] : '') . ' ' . $address['postcode'] . ' ' . $address['city'] . '</td> <td>' . $address['country'] . '</td> <td>' . ($address['phone'] ? $address['phone'] . ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '') : ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '--')) . '</td> <td align="center"> <a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&addaddress&token=' . $tokenAddresses . '"><img src="../img/admin/edit.gif" /></a> <a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&deleteaddress&token=' . $tokenAddresses . '"><img src="../img/admin/delete.gif" /></a> </td> </tr>'; } echo ' </table>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not registered any addresses yet') . '.'; } echo '<div class="clear"> </div> <h2>' . $this->l('Discounts') . ' (' . sizeof($discounts) . ')</h2>'; if (sizeof($discounts)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th>' . $this->l('ID') . '</th> <th>' . $this->l('Code') . '</th> <th>' . $this->l('Type') . '</th> <th>' . $this->l('Value') . '</th> <th>' . $this->l('Qty available') . '</th> <th>' . $this->l('Status') . '</th> <th>' . $this->l('Actions') . '</th> </tr>'; $tokenDiscounts = Tools::getAdminToken('AdminDiscounts' . (int) Tab::getIdFromClassName('AdminDiscounts') . (int) $cookie->id_employee); foreach ($discounts as $discount) { echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '> <td align="center">' . $discount['id_discount'] . '</td> <td>' . $discount['name'] . '</td> <td>' . $discount['type'] . '</td> <td align="right">' . $discount['value'] . '</td> <td align="center">' . $discount['quantity_for_user'] . '</td> <td align="center"><img src="../img/admin/' . ($discount['active'] ? 'enabled.gif' : 'disabled.gif') . '" alt="' . $this->l('Status') . '" title="' . $this->l('Status') . '" /></td> <td align="center"> <a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&adddiscount&token=' . $tokenDiscounts . '"><img src="../img/admin/edit.gif" /></a> <a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&deletediscount&token=' . $tokenDiscounts . '"><img src="../img/admin/delete.gif" /></a> </td> </tr>'; } echo ' </table>'; } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has no discount vouchers') . '.'; } echo '<div class="clear"> </div>'; echo '<div style="float:left"> <h2>' . $this->l('Carts') . ' (' . sizeof($carts) . ')</h2>'; if ($carts and sizeof($carts)) { echo ' <table cellspacing="0" cellpadding="0" class="table"> <tr> <th class="center">' . $this->l('ID') . '</th> <th class="center">' . $this->l('Date') . '</th> <th class="center">' . $this->l('Total') . '</th> <th class="center">' . $this->l('Carrier') . '</th> <th class="center">' . $this->l('Actions') . '</th> </tr>'; $tokenCarts = Tools::getAdminToken('AdminCarts' . (int) Tab::getIdFromClassName('AdminCarts') . (int) $cookie->id_employee); foreach ($carts as $cart) { $cartI = new Cart((int) $cart['id_cart']); $summary = $cartI->getSummaryDetails(); $currency = new Currency((int) $cart['id_currency']); $carrier = new Carrier((int) $cart['id_carrier']); echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '\'"> <td class="center">' . sprintf('%06d', $cart['id_cart']) . '</td> <td>' . Tools::displayDate($cart['date_add'], (int) $cookie->id_lang, true) . '</td> <td align="right">' . Tools::displayPrice($summary['total_price'], $currency) . '</td> <td>' . $carrier->name . '</td> <td align="center"><a href="index.php?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo ' </table>'; } else { echo $this->l('No cart available') . '.'; } echo '</div>'; $interested = Db::getInstance()->ExecuteS('SELECT DISTINCT id_product FROM ' . _DB_PREFIX_ . 'cart_product cp INNER JOIN ' . _DB_PREFIX_ . 'cart c on c.id_cart = cp.id_cart WHERE c.id_customer = ' . (int) $customer->id . ' AND cp.id_product NOT IN ( SELECT product_id FROM ' . _DB_PREFIX_ . 'orders o inner join ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order WHERE o.valid = 1 AND o.id_customer = ' . (int) $customer->id . ')'); if (count($interested)) { echo '<div style="float:left;margin-left:20px"> <h2>' . $this->l('Products') . ' (' . count($interested) . ')</h2> <table cellspacing="0" cellpadding="0" class="table">'; foreach ($interested as $p) { $product = new Product((int) $p['id_product'], false, $cookie->id_lang); echo ' <tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'' . $link->getProductLink((int) $product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, (int) $cookie->id_lang)) . '\'"> <td>' . (int) $product->id . '</td> <td>' . Tools::htmlentitiesUTF8($product->name) . '</td> <td align="center"><a href="' . $link->getProductLink((int) $product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, (int) $cookie->id_lang)) . '"><img src="../img/admin/details.gif" /></a></td> </tr>'; } echo '</table></div>'; } echo '<div class="clear"> </div>'; /* Last connections */ $connections = $customer->getLastConnections(); if (sizeof($connections)) { echo '<h2>' . $this->l('Last connections') . '</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th style="width: 200px">' . $this->l('Date') . '</th> <th style="width: 100px">' . $this->l('Pages viewed') . '</th> <th style="width: 100px">' . $this->l('Total time') . '</th> <th style="width: 100px">' . $this->l('Origin') . '</th> <th style="width: 100px">' . $this->l('IP Address') . '</th> </tr>'; foreach ($connections as $connection) { echo '<tr> <td>' . Tools::displayDate($connection['date_add'], (int) $cookie->id_lang, true) . '</td> <td>' . (int) $connection['pages'] . '</td> <td>' . $connection['time'] . '</td> <td>' . ($connection['http_referer'] ? preg_replace('/^www./', '', parse_url($connection['http_referer'], PHP_URL_HOST)) : $this->l('Direct link')) . '</td> <td>' . $connection['ipaddress'] . '</td> </tr>'; } echo '</table><div class="clear"> </div>'; } if (sizeof($referrers)) { echo '<h2>' . $this->l('Referrers') . '</h2> <table cellspacing="0" cellpadding="0" class="table"> <tr> <th style="width: 200px">' . $this->l('Date') . '</th> <th style="width: 200px">' . $this->l('Name') . '</th> </tr>'; foreach ($referrers as $referrer) { echo '<tr> <td>' . Tools::displayDate($referrer['date_add'], (int) $cookie->id_lang, true) . '</td> <td>' . $referrer['name'] . '</td> </tr>'; } echo '</table><div class="clear"> </div>'; } echo '<a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to customer list') . '</a><br />'; }
public function renderView() { $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { $this->errors[] = Tools::displayError('The order cannot be found within your database.'); } $customer = new Customer($order->id_customer); $carrier = new Carrier($order->id_carrier); $products = $this->getProducts($order); $currency = new Currency((int) $order->id_currency); // Carrier module call $carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } // Retrieve addresses information $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } if ($order->id_address_invoice == $order->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) { $deliveryState = $invoiceState; } } else { $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } } $this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname); if (Shop::isFeatureActive()) { $shop = new Shop((int) $order->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $order_details = $order->getOrderDetailList(); foreach ($order_details as $order_detail) { $product = new Product($order_detail['product_id']); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) { $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']); foreach ($warehouses as $warehouse) { if (!isset($warehouse_list[$warehouse['id_warehouse']])) { $warehouse_list[$warehouse['id_warehouse']] = $warehouse; } } } } $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $order->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } // products current stock (from stock_available) foreach ($products as &$product) { $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']); $resume = OrderSlip::getProductSlipResume($product['id_order_detail']); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency); $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']); $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']); // if the current stock requires a warning if ($product['current_stock'] == 0 && $display_out_of_stock_warning) { $this->displayWarning($this->l('This product is out of stock: ') . ' ' . $product['product_name']); } if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; } else { $product['warehouse_name'] = '--'; } } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $order->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } // Smarty assign $this->tpl_view_vars = array('order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array('delivery' => $addressDelivery, 'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'invoice' => $addressInvoice, 'invoiceState' => isset($invoiceState) ? $invoiceState : null), 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), 'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), 'total_paid' => $order->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'messages' => Message::getMessagesByOrderId($order->id, true), 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'states' => OrderState::getOrderStates($this->context->language->id), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($order->id), 'currentState' => $order->getCurrentOrderState(), 'currency' => new Currency($order->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($order->id_shop), 'previousOrder' => $order->getPreviousOrderId(), 'nextOrder' => $order->getNextOrderId(), 'current_index' => self::$currentIndex, 'carrierModuleCall' => $carrier_module_call, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->tabAccess['edit'] == 1, 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $order->getInvoicesCollection(), 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')); return parent::renderView(); }
public function renderView() { /** @var Customer $customer */ if (!($customer = $this->loadObject())) { return; } $this->context->customer = $customer; $gender = new Gender($customer->id_gender, $this->context->language->id); $gender_image = $gender->getImage(); $customer_stats = $customer->getStats(); $sql = 'SELECT SUM(total_paid_real) FROM ' . _DB_PREFIX_ . 'orders WHERE id_customer = %d AND valid = 1'; if ($total_customer = Db::getInstance()->getValue(sprintf($sql, $customer->id))) { $sql = 'SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 AND id_customer != ' . (int) $customer->id . ' GROUP BY id_customer HAVING SUM(total_paid_real) > %d'; Db::getInstance()->getValue(sprintf($sql, (int) $total_customer)); $count_better_customers = (int) Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1; } else { $count_better_customers = '-'; } $orders = Order::getCustomerOrders($customer->id, true); $total_orders = count($orders); for ($i = 0; $i < $total_orders; $i++) { $orders[$i]['total_paid_real_not_formated'] = $orders[$i]['total_paid_real']; $orders[$i]['total_paid_real'] = Tools::displayPrice($orders[$i]['total_paid_real'], new Currency((int) $orders[$i]['id_currency'])); } $messages = CustomerThread::getCustomerMessages((int) $customer->id); $total_messages = count($messages); for ($i = 0; $i < $total_messages; $i++) { $messages[$i]['message'] = substr(strip_tags(html_entity_decode($messages[$i]['message'], ENT_NOQUOTES, 'UTF-8')), 0, 75); $messages[$i]['date_add'] = Tools::displayDate($messages[$i]['date_add'], null, true); if (isset(self::$meaning_status[$messages[$i]['status']])) { $messages[$i]['status'] = self::$meaning_status[$messages[$i]['status']]; } } $groups = $customer->getGroups(); $total_groups = count($groups); for ($i = 0; $i < $total_groups; $i++) { $group = new Group($groups[$i]); $groups[$i] = array(); $groups[$i]['id_group'] = $group->id; $groups[$i]['name'] = $group->name[$this->default_form_language]; } $total_ok = 0; $orders_ok = array(); $orders_ko = array(); foreach ($orders as $order) { if (!isset($order['order_state'])) { $order['order_state'] = $this->l('There is no status defined for this order.'); } if ($order['valid']) { $orders_ok[] = $order; $total_ok += $order['total_paid_real_not_formated']; } else { $orders_ko[] = $order; } } $products = $customer->getBoughtProducts(); $carts = Cart::getCustomerCarts($customer->id); $total_carts = count($carts); for ($i = 0; $i < $total_carts; $i++) { $cart = new Cart((int) $carts[$i]['id_cart']); $this->context->cart = $cart; $summary = $cart->getSummaryDetails(); $currency = new Currency((int) $carts[$i]['id_currency']); $carrier = new Carrier((int) $carts[$i]['id_carrier']); $carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']); $carts[$i]['date_add'] = Tools::displayDate($carts[$i]['date_add'], null, true); $carts[$i]['total_price'] = Tools::displayPrice($summary['total_price'], $currency); $carts[$i]['name'] = $carrier->name; } $sql = 'SELECT DISTINCT cp.id_product, c.id_cart, c.id_shop, cp.id_shop AS cp_id_shop FROM ' . _DB_PREFIX_ . 'cart_product cp JOIN ' . _DB_PREFIX_ . 'cart c ON (c.id_cart = cp.id_cart) JOIN ' . _DB_PREFIX_ . 'product p ON (cp.id_product = p.id_product) WHERE c.id_customer = ' . (int) $customer->id . ' AND NOT EXISTS ( SELECT 1 FROM ' . _DB_PREFIX_ . 'orders o JOIN ' . _DB_PREFIX_ . 'order_detail od ON (o.id_order = od.id_order) WHERE product_id = cp.id_product AND o.valid = 1 AND o.id_customer = ' . (int) $customer->id . ' )'; $interested = Db::getInstance()->executeS($sql); $total_interested = count($interested); for ($i = 0; $i < $total_interested; $i++) { $product = new Product($interested[$i]['id_product'], false, $this->default_form_language, $interested[$i]['id_shop']); if (!Validate::isLoadedObject($product)) { continue; } $interested[$i]['url'] = $this->context->link->getProductLink($product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, $this->default_form_language), null, null, $interested[$i]['cp_id_shop']); $interested[$i]['id'] = (int) $product->id; $interested[$i]['name'] = Tools::htmlentitiesUTF8($product->name); } $emails = $customer->getLastEmails(); $connections = $customer->getLastConnections(); if (!is_array($connections)) { $connections = array(); } $total_connections = count($connections); for ($i = 0; $i < $total_connections; $i++) { $connections[$i]['http_referer'] = $connections[$i]['http_referer'] ? preg_replace('/^www./', '', parse_url($connections[$i]['http_referer'], PHP_URL_HOST)) : $this->l('Direct link'); } $referrers = Referrer::getReferrers($customer->id); $total_referrers = count($referrers); for ($i = 0; $i < $total_referrers; $i++) { $referrers[$i]['date_add'] = Tools::displayDate($referrers[$i]['date_add'], null, true); } $customerLanguage = new Language($customer->id_lang); $shop = new Shop($customer->id_shop); $this->tpl_view_vars = array('customer' => $customer, 'gender' => $gender, 'gender_image' => $gender_image, 'registration_date' => Tools::displayDate($customer->date_add, null, true), 'customer_stats' => $customer_stats, 'last_visit' => Tools::displayDate($customer_stats['last_visit'], null, true), 'count_better_customers' => $count_better_customers, 'shop_is_feature_active' => Shop::isFeatureActive(), 'name_shop' => $shop->name, 'customer_birthday' => Tools::displayDate($customer->birthday), 'last_update' => Tools::displayDate($customer->date_upd, null, true), 'customer_exists' => Customer::customerExists($customer->email), 'id_lang' => $customer->id_lang, 'customerLanguage' => $customerLanguage, 'customer_note' => Tools::htmlentitiesUTF8($customer->note), 'messages' => $messages, 'groups' => $groups, 'orders' => $orders, 'orders_ok' => $orders_ok, 'orders_ko' => $orders_ko, 'total_ok' => Tools::displayPrice($total_ok, $this->context->currency->id), 'products' => $products, 'addresses' => $customer->getAddresses($this->default_form_language), 'discounts' => CartRule::getCustomerCartRules($this->default_form_language, $customer->id, false, false), 'carts' => $carts, 'interested' => $interested, 'emails' => $emails, 'connections' => $connections, 'referrers' => $referrers, 'show_toolbar' => true); return parent::renderView(); }
public function renderView() { $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { $this->errors[] = Tools::displayError('The order cannot be found within your database.'); } $customer = new Customer($order->id_customer); $carrier = new Carrier($order->id_carrier); $products = $this->getProducts($order); $order_details = AphOrderDetail::getList($order->id); foreach ($order_details as &$order_detail) { $products[$order_detail['id_order_detail']]['delivery_date'] = $order_detail['delivery_date']; $products[$order_detail['id_order_detail']]['delivery_time_from'] = $order_detail['delivery_time_from']; $products[$order_detail['id_order_detail']]['delivery_time_to'] = $order_detail['delivery_time_to']; } $currency = new Currency((int) $order->id_currency); // Carrier module call $carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } // Retrieve addresses information $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } if ($order->id_address_invoice == $order->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) { $deliveryState = $invoiceState; } } else { $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } } $this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname); if (Shop::isFeatureActive()) { $shop = new Shop((int) $order->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $order_details = $order->getOrderDetailList(); foreach ($order_details as $order_detail) { $product = new Product($order_detail['product_id']); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) { $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']); foreach ($warehouses as $warehouse) { if (!isset($warehouse_list[$warehouse['id_warehouse']])) { $warehouse_list[$warehouse['id_warehouse']] = $warehouse; } } } } $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $order->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } // products current stock (from stock_available) foreach ($products as &$product) { // Get total customized quantity for current product $customized_product_quantity = 0; if (is_array($product['customizedDatas'])) { foreach ($product['customizedDatas'] as $customizationPerAddress) { foreach ($customizationPerAddress as $customizationId => $customization) { $customized_product_quantity += (int) $customization['quantity']; } } } $product['customized_product_quantity'] = $customized_product_quantity; $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']); $resume = OrderSlip::getProductSlipResume($product['id_order_detail']); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl']; $product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency); $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']); $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']); // if the current stock requires a warning if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) { $this->displayWarning($this->l('This product is out of stock: ') . ' ' . $product['product_name']); } if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; $warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']); if (!empty($warehouse_location)) { $product['warehouse_location'] = $warehouse_location; } else { $product['warehouse_location'] = false; } } else { $product['warehouse_name'] = '--'; $product['warehouse_location'] = false; } } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $order->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } // Smarty assign $this->tpl_view_vars = array('order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array('delivery' => $addressDelivery, 'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'invoice' => $addressInvoice, 'invoiceState' => isset($invoiceState) ? $invoiceState : null), 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), 'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), 'total_paid' => $order->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'messages' => Message::getMessagesByOrderId($order->id, true), 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'states' => OrderState::getOrderStates($this->context->language->id), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($order->id), 'currentState' => $order->getCurrentOrderState(), 'currency' => new Currency($order->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($order->id_shop), 'previousOrder' => $order->getPreviousOrderId(), 'nextOrder' => $order->getNextOrderId(), 'current_index' => self::$currentIndex, 'carrierModuleCall' => $carrier_module_call, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->tabAccess['edit'] == 1, 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $order->getInvoicesCollection(), 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array('order' => $order, 'products' => $products, 'customer' => $customer))); $options_time = array(); $time_slice = Configuration::get('APH_CALENDAR_TIME_SLICE'); for ($hours = 0; $hours < 24; $hours++) { // the interval for hours is '1' for ($mins = 0; $mins < 60; $mins += $time_slice) { // the interval for mins is 'APH_CALENDAR_TIME_SLICE' $options_time[str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT)] = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT); } } $this->tpl_view_vars['options_time'] = $options_time; $employees = array(); $e = AphEmployeeProduct::getEmployeesByShop((int) Context::getContext()->shop->id); foreach ($e as $employee) { $employees[$employee['id_employee']] = $employee['fullName']; } $this->tpl_view_vars['employees'] = $employees; $helper = new HelperView($this); $this->setHelperDisplay($helper); $helper->tpl_vars = $this->getTemplateViewVars(); $helper->base_folder = $this->getTemplatePath() . 'aph_orders/helpers/'; $helper->base_tpl = 'view/view.tpl'; $view = $helper->generateView(); return $view; }
public function renderView() { $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { $this->errors[] = Tools::displayError('The order cannot be found within your database.'); } $customer = new Customer($order->id_customer); $carrier = new Carrier($order->id_carrier); $products = $this->getProducts($order); $currency = new Currency((int) $order->id_currency); // Carrier module call $carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } // Retrieve addresses information $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } if ($order->id_address_invoice == $order->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) { $deliveryState = $invoiceState; } } else { $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } } $this->toolbar_title = sprintf($this->l('Order #%1$d (%2$s) - %3$s %4$s'), $order->id, $order->reference, $customer->firstname, $customer->lastname); if (Shop::isFeatureActive()) { $shop = new Shop((int) $order->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $order_details = $order->getOrderDetailList(); foreach ($order_details as $order_detail) { $product = new Product($order_detail['product_id']); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) { $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']); foreach ($warehouses as $warehouse) { if (!isset($warehouse_list[$warehouse['id_warehouse']])) { $warehouse_list[$warehouse['id_warehouse']] = $warehouse; } } } } $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $order->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } // products current stock (from stock_available) foreach ($products as &$product) { // Get total customized quantity for current product $customized_product_quantity = 0; if (is_array($product['customizedDatas'])) { foreach ($product['customizedDatas'] as $customizationPerAddress) { foreach ($customizationPerAddress as $customizationId => $customization) { $customized_product_quantity += (int) $customization['quantity']; } } } $product['customized_product_quantity'] = $customized_product_quantity; $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']); $resume = OrderSlip::getProductSlipResume($product['id_order_detail']); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl']; $product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency); $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']); $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']); // if the current stock requires a warning if ($product['current_stock'] == 0 && $display_out_of_stock_warning) { $this->displayWarning($this->l('This product is out of stock: ') . ' ' . $product['product_name']); } if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; $warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']); if (!empty($warehouse_location)) { $product['warehouse_location'] = $warehouse_location; } else { $product['warehouse_location'] = false; } } else { $product['warehouse_name'] = '--'; $product['warehouse_location'] = false; } } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $order->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } //by webkul to get data to show hotel rooms order data on order detail page $cart_id = Cart::getCartIdByOrderId(Tools::getValue('id_order')); $cart_detail_data = array(); $cart_detail_data_obj = new HotelCartBookingData(); $cart_detail_data = $cart_detail_data_obj->getCartCurrentDataByCartId((int) $cart_id); if ($cart_detail_data) { foreach ($cart_detail_data as $key => $value) { $product_image_id = Product::getCover($value['id_product']); $link_rewrite = (new Product((int) $value['id_product'], Configuration::get('PS_LANG_DEFAULT')))->link_rewrite[Configuration::get('PS_LANG_DEFAULT')]; if ($product_image_id) { $cart_detail_data[$key]['image_link'] = $this->context->link->getImageLink($link_rewrite, $product_image_id['id_image'], 'small_default'); } else { $cart_detail_data[$key]['image_link'] = $this->context->link->getImageLink($link_rewrite, $this->context->language->iso_code . "-default", 'small_default'); } $cart_detail_data[$key]['room_type'] = (new Product((int) $value['id_product']))->name[Configuration::get('PS_LANG_DEFAULT')]; $cart_detail_data[$key]['room_num'] = (new HotelRoomInformation((int) $value['id_room']))->room_num; $cart_detail_data[$key]['date_from'] = (new DateTime($value['date_from']))->format('d-M Y'); $cart_detail_data[$key]['date_to'] = (new DateTime($value['date_to']))->format('d-M Y'); $cust_obj = new Customer($value['id_customer']); $cart_detail_data[$key]['alloted_cust_name'] = $cust_obj->firstname . ' ' . $cust_obj->lastname; $cart_detail_data[$key]['alloted_cust_email'] = $cust_obj->email; $cart_detail_data[$key]['avail_rooms_to_swap'] = (new HotelBookingDetail())->getAvailableRoomsForSwaping($value['date_from'], $value['date_to'], $value['id_product'], $value['id_hotel']); $obj_booking_dtl = new HotelBookingDetail(); $num_days = $obj_booking_dtl->getNumberOfDays($cart_detail_data[$key]['date_from'], $cart_detail_data[$key]['date_to']); //quantity of product $cart_detail_data[$key]['amt_with_qty'] = $value['amount'] * $num_days; } } //end //by webkul to send order status on order detail page $obj_bookin_detail = new HotelBookingDetail(); $htl_booking_data_order_id = $obj_bookin_detail->getBookingDataByOrderId(Tools::getValue('id_order')); if ($htl_booking_data_order_id) { foreach ($htl_booking_data_order_id as $key => $value) { $htl_booking_data_order_id[$key]['room_num'] = (new HotelRoomInformation())->getHotelRoomInfoById($value['id_room']); $htl_booking_data_order_id[$key]['order_status'] = $value['id_status']; $htl_booking_data_order_id[$key]['date_from'] = (new DateTime($value['date_from']))->format('d-M Y'); $htl_booking_data_order_id[$key]['date_to'] = (new DateTime($value['date_to']))->format('d-M Y'); } } $htl_order_status = HotelOrderStatus::getAllHotelOrderStatus(); //end // Smarty assign $this->tpl_view_vars = array('htl_booking_order_data' => $htl_booking_data_order_id, 'hotel_order_status' => $htl_order_status, 'cart_detail_data' => $cart_detail_data, 'order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array('delivery' => $addressDelivery, 'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'invoice' => $addressInvoice, 'invoiceState' => isset($invoiceState) ? $invoiceState : null), 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), 'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), 'total_paid' => $order->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'messages' => Message::getMessagesByOrderId($order->id, true), 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'states' => OrderState::getOrderStates($this->context->language->id), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($order->id), 'currentState' => $order->getCurrentOrderState(), 'currency' => new Currency($order->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($order->id_shop), 'previousOrder' => $order->getPreviousOrderId(), 'nextOrder' => $order->getNextOrderId(), 'current_index' => self::$currentIndex, 'carrierModuleCall' => $carrier_module_call, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->tabAccess['edit'] == 1, 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $order->getInvoicesCollection(), 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array('order' => $order, 'products' => $products, 'customer' => $customer))); return parent::renderView(); }
public function renderView() { $neoExchange = new NeoExchanges(Tools::getValue('id_neo_exchange')); $order = new Order(Tools::getValue('id_neo_exchange')); if (!Validate::isLoadedObject($neoExchange)) { $this->errors[] = Tools::displayError('The order cannot be found within your database.'); } $customer = new Customer($neoExchange->id_customer); //$carrier = new Carrier($neoExchange->id_carrier); $currency = new Currency((int) $neoExchange->id_currency); $buys = new NeoItemsBuyCore(Tools::getValue('id_neo_exchange')); $sales = new NeoItemsSalesCore(Tools::getValue('id_neo_exchange')); $products = $this->getProducts($buys); $products2 = $this->getProducts($sales); //$products = $this->getProducts($neoExchange); // Carrier module call /*$carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $neoExchange->id_cart); } // Retrieve addresses information $addressInvoice = new Address($neoExchange->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) $invoiceState = new State((int)$addressInvoice->id_state); if ($neoExchange->id_address_invoice == $neoExchange->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) $deliveryState = $invoiceState; } else { $addressDelivery = new Address($neoExchange->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) $deliveryState = new State((int)($addressDelivery->id_state)); }*/ $this->toolbar_title = sprintf($this->l('Intercambio #%1$d (%2$s) - %3$s %4$s'), $neoExchange->id, $neoExchange->reference, $customer->firstname, $customer->lastname); if (Shop::isFeatureActive()) { $shop = new Shop((int) $neoExchange->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->l('Shop: %s'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $neoExchange->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } $total_buy = 0; $total_sale = 0; $products_buy = count($products); $products_sale = count($products2); // products current stock (from stock_available) foreach ($products as &$product) { $total_buy += $product['price']; } foreach ($products2 as &$product) { $total_sale += $product['price']; } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $neoExchange->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } // Smarty assign $this->tpl_view_vars = array('order' => $neoExchange, 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'customerStats' => $customer->getStats(), 'products' => $products, 'products2' => $products2, 'total_buy' => $total_buy, 'total_sale' => $total_sale, 'products_buy' => $products_buy, 'products_sale' => $products_sale, 'neo_order_shipping_price' => 0, 'orders_total_paid_tax_incl' => $neoExchange->getOrdersTotalPaid(), 'total_paid' => $neoExchange->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($neoExchange->id_customer, $neoExchange->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($neoExchange->id_customer), 'orderMessages' => OrderMessage::getOrderMessages($neoExchange->id_lang), 'messages' => Message::getMessagesByOrderId($neoExchange->id, true), 'history' => $history, 'neoStatus' => NeoStatusCore::getNeoStatus(), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($neoExchange->id), 'currentState' => $neoExchange->getCurrentOrderState(), 'currency' => new Currency($neoExchange->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($neoExchange->id_shop), 'previousOrder' => $neoExchange->getPreviousOrderId(), 'nextOrder' => $neoExchange->getNextOrderId(), 'current_index' => self::$currentIndex, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->tabAccess['edit'] == 1, 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $neoExchange->getInvoicesCollection(), 'not_paid_invoices_collection' => $neoExchange->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $neoExchange->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array('order' => $neoExchange, 'products' => $products, 'customer' => $customer)), 'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array('order' => $neoExchange, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array('order' => $neoExchange, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array('order' => $neoExchange, 'products' => $products, 'customer' => $customer))); return parent::renderView(); }
public function renderView() { $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { $this->errors[] = $this->trans('The order cannot be found within your database.', array(), 'Admin.OrdersCustomers.Notification'); } $customer = new Customer($order->id_customer); $carrier = new Carrier($order->id_carrier); $products = $this->getProducts($order); $currency = new Currency((int) $order->id_currency); // Carrier module call $carrier_module_call = null; if ($carrier->is_module) { $module = Module::getInstanceByName($carrier->external_module_name); if (method_exists($module, 'displayInfoByCart')) { $carrier_module_call = call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } } // Retrieve addresses information $addressInvoice = new Address($order->id_address_invoice, $this->context->language->id); if (Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state) { $invoiceState = new State((int) $addressInvoice->id_state); } if ($order->id_address_invoice == $order->id_address_delivery) { $addressDelivery = $addressInvoice; if (isset($invoiceState)) { $deliveryState = $invoiceState; } } else { $addressDelivery = new Address($order->id_address_delivery, $this->context->language->id); if (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) { $deliveryState = new State((int) $addressDelivery->id_state); } } $this->toolbar_title = $this->trans('Order #%id% (%ref%) - %firstname% %lastname%', array('%id%' => $order->id, '%ref%' => $order->reference, '%firstname%' => $customer->firstname, '%lastname%' => $customer->lastname), 'Admin.OrdersCustomers.Feature'); if (Shop::isFeatureActive()) { $shop = new Shop((int) $order->id_shop); $this->toolbar_title .= ' - ' . sprintf($this->trans('Shop: %s', array(), 'Admin.OrdersCustomers.Feature'), $shop->name); } // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; $order_details = $order->getOrderDetailList(); foreach ($order_details as $order_detail) { $product = new Product($order_detail['product_id']); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management) { $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']); foreach ($warehouses as $warehouse) { if (!isset($warehouse_list[$warehouse['id_warehouse']])) { $warehouse_list[$warehouse['id_warehouse']] = $warehouse; } } } } $payment_methods = array(); foreach (PaymentModule::getInstalledPaymentModules() as $payment) { $module = Module::getInstanceByName($payment['name']); if (Validate::isLoadedObject($module) && $module->active) { $payment_methods[] = $module->displayName; } } // display warning if there are products out of stock $display_out_of_stock_warning = false; $current_order_state = $order->getCurrentOrderState(); if (Configuration::get('PS_STOCK_MANAGEMENT') && (!Validate::isLoadedObject($current_order_state) || $current_order_state->delivery != 1 && $current_order_state->shipped != 1)) { $display_out_of_stock_warning = true; } // products current stock (from stock_available) foreach ($products as &$product) { // Get total customized quantity for current product $customized_product_quantity = 0; if (is_array($product['customizedDatas'])) { foreach ($product['customizedDatas'] as $customizationPerAddress) { foreach ($customizationPerAddress as $customizationId => $customization) { $customized_product_quantity += (int) $customization['quantity']; } } } $product['customized_product_quantity'] = $customized_product_quantity; $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], $product['id_shop']); $resume = OrderSlip::getProductSlipResume($product['id_order_detail']); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl']; $product['amount_refundable_tax_incl'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl'], $currency); $product['refund_history'] = OrderSlip::getProductSlipDetail($product['id_order_detail']); $product['return_history'] = OrderReturn::getProductReturnDetail($product['id_order_detail']); // if the current stock requires a warning if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) { $this->displayWarning($this->trans('This product is out of stock: ', array(), 'Admin.OrdersCustomers.Notification') . ' ' . $product['product_name']); } if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; $warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'], $product['product_attribute_id'], $product['id_warehouse']); if (!empty($warehouse_location)) { $product['warehouse_location'] = $warehouse_location; } else { $product['warehouse_location'] = false; } } else { $product['warehouse_name'] = '--'; $product['warehouse_location'] = false; } } // Package management for order foreach ($products as &$product) { $pack_items = $product['cache_is_pack'] ? Pack::getItemTable($product['id_product'], $this->context->language->id, true) : array(); foreach ($pack_items as &$pack_item) { $pack_item['current_stock'] = StockAvailable::getQuantityAvailableByProduct($pack_item['id_product'], $pack_item['id_product_attribute'], $pack_item['id_shop']); // if the current stock requires a warning if ($product['current_stock'] <= 0 && $display_out_of_stock_warning) { $this->displayWarning($this->trans('This product, included in package (' . $product['product_name'] . ') is out of stock: ', array(), 'Admin.OrdersCustomers.Notification') . ' ' . $pack_item['product_name']); } $this->setProductImageInformations($pack_item); if ($pack_item['image'] != null) { $name = 'product_mini_' . (int) $pack_item['id_product'] . (isset($pack_item['id_product_attribute']) ? '_' . (int) $pack_item['id_product_attribute'] : '') . '.jpg'; // generate image cache, only for back office $pack_item['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $pack_item['image']->getExistingImgPath() . '.jpg', $name, 45, 'jpg'); if (file_exists(_PS_TMP_IMG_DIR_ . $name)) { $pack_item['image_size'] = getimagesize(_PS_TMP_IMG_DIR_ . $name); } else { $pack_item['image_size'] = false; } } } $product['pack_items'] = $pack_items; } $gender = new Gender((int) $customer->id_gender, $this->context->language->id); $history = $order->getHistory($this->context->language->id); foreach ($history as &$order_state) { $order_state['text-color'] = Tools::getBrightness($order_state['color']) < 128 ? 'white' : 'black'; } // Smarty assign $this->tpl_view_vars = array('order' => $order, 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array('delivery' => $addressDelivery, 'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'invoice' => $addressInvoice, 'invoiceState' => isset($invoiceState) ? $invoiceState : null), 'customerStats' => $customer->getStats(), 'products' => $products, 'discounts' => $order->getCartRules(), 'orders_total_paid_tax_incl' => $order->getOrdersTotalPaid(), 'total_paid' => $order->getTotalPaid(), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'messages' => Message::getMessagesByOrderId($order->id, true), 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'states' => OrderState::getOrderStates($this->context->language->id), 'warehouse_list' => $warehouse_list, 'sources' => ConnectionsSource::getOrderSources($order->id), 'currentState' => $order->getCurrentOrderState(), 'currency' => new Currency($order->id_currency), 'currencies' => Currency::getCurrenciesByIdShop($order->id_shop), 'previousOrder' => $order->getPreviousOrderId(), 'nextOrder' => $order->getNextOrderId(), 'current_index' => self::$currentIndex, 'carrierModuleCall' => $carrier_module_call, 'iso_code_lang' => $this->context->language->iso_code, 'id_lang' => $this->context->language->id, 'can_edit' => $this->access('edit'), 'current_id_lang' => $this->context->language->id, 'invoices_collection' => $order->getInvoicesCollection(), 'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(), 'payment_methods' => $payment_methods, 'invoice_management_active' => Configuration::get('PS_INVOICE', null, null, $order->id_shop), 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), 'carrier_list' => $this->getCarrierList($order), 'recalculate_shipping_cost' => (int) Configuration::get('PS_ORDER_RECALCULATE_SHIPPING'), 'HOOK_CONTENT_ORDER' => Hook::exec('displayAdminOrderContentOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_CONTENT_SHIP' => Hook::exec('displayAdminOrderContentShip', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_ORDER' => Hook::exec('displayAdminOrderTabOrder', array('order' => $order, 'products' => $products, 'customer' => $customer)), 'HOOK_TAB_SHIP' => Hook::exec('displayAdminOrderTabShip', array('order' => $order, 'products' => $products, 'customer' => $customer))); return parent::renderView(); }