public function fillFromCustomer(Customer $customer) { $params = get_object_vars($customer); $params['id_customer'] = $customer->id; $params['birthday'] = $customer->birthday === '0000-00-00' ? null : Tools::displayDate($customer->birthday); return $this->fillWith($params); }
public function renderForm() { $this->fields_form = array('legend' => array('title' => $this->l('Return Merchandise Authorization (RMA)'), 'image' => '../img/admin/return.gif'), 'input' => array(array('type' => 'hidden', 'name' => 'id_order'), array('type' => 'hidden', 'name' => 'id_customer'), array('type' => 'text_customer', 'label' => $this->l('Customer'), 'name' => '', 'size' => '', 'required' => false), array('type' => 'text_order', 'label' => $this->l('Order'), 'name' => '', 'size' => '', 'required' => false), array('type' => 'free', 'label' => $this->l('Customer explanation'), 'name' => 'question', 'size' => '', 'required' => false), array('type' => 'select', 'label' => $this->l('Status'), 'name' => 'state', 'required' => false, 'options' => array('query' => OrderReturnState::getOrderReturnStates($this->context->language->id), 'id' => 'id_order_return_state', 'name' => 'name'), 'desc' => $this->l('Merchandise return (RMA) status.')), array('type' => 'list_products', 'label' => $this->l('Products'), 'name' => '', 'size' => '', 'required' => false, 'desc' => $this->l('List of products in return package.')), array('type' => 'pdf_order_return', 'label' => $this->l('Return slip'), 'name' => '', 'size' => '', 'required' => false, 'desc' => $this->l('The link is only available after validation and before the parcel gets delivered.'))), 'submit' => array('title' => $this->l('Save'))); $order = new Order($this->object->id_order); $quantity_displayed = array(); // Customized products */ if ($returned_customizations = OrderReturn::getReturnedCustomizedProducts((int) $this->object->id_order)) { foreach ($returned_customizations as $returned_customization) { $quantity_displayed[(int) $returned_customization['id_order_detail']] = isset($quantity_displayed[(int) $returned_customization['id_order_detail']]) ? $quantity_displayed[(int) $returned_customization['id_order_detail']] + (int) $returned_customization['product_quantity'] : (int) $returned_customization['product_quantity']; } } // Classic products $products = OrderReturn::getOrdersReturnProducts($this->object->id, $order); // Prepare customer explanation for display $this->object->question = '<span class="normal-text">' . nl2br($this->object->question) . '</span>'; $this->tpl_form_vars = array('customer' => new Customer($this->object->id_customer), 'url_customer' => 'index.php?tab=AdminCustomers&id_customer=' . (int) $this->object->id_customer . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id), 'text_order' => sprintf($this->l('Order #%1$d from %2$s'), $order->id, Tools::displayDate($order->date_upd)), 'url_order' => 'index.php?tab=AdminOrders&id_order=' . (int) $order->id . '&vieworder&token=' . Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $this->context->employee->id), 'picture_folder' => _THEME_PROD_PIC_DIR_, 'returnedCustomizations' => $returned_customizations, 'customizedDatas' => Product::getAllCustomizedDatas((int) $order->id_cart), 'products' => $products, 'quantityDisplayed' => $quantity_displayed, 'id_order_return' => $this->object->id, 'state_order_return' => $this->object->state); return parent::renderForm(); }
public function __construct($order, $smarty) { $this->order = $order; $this->smarty = $smarty; $this->title = 'Order #' . $this->order->id; // header informations $this->date = Tools::displayDate($order->date_add, null); // footer informations $this->shop = new Shop((int) $this->order->id_shop); }
/** * @param OrderInvoice $order_invoice * @param $smarty * @throws PrestaShopException */ public function __construct(OrderInvoice $order_invoice, $smarty) { $this->order_invoice = $order_invoice; $this->order = new Order((int) $this->order_invoice->id_order); $this->smarty = $smarty; // header informations $this->date = Tools::displayDate($order_invoice->date_add); $id_lang = Context::getContext()->language->id; $this->title = $order_invoice->getInvoiceNumberFormatted($id_lang); $this->shop = new Shop((int) $this->order->id_shop); }
/** * @param OrderReturn $order_return * @param $smarty * @throws PrestaShopException */ public function __construct(OrderReturn $order_return, $smarty) { $this->order_return = $order_return; $this->smarty = $smarty; $this->order = new Order($order_return->id_order); // header informations $this->date = Tools::displayDate($this->order->invoice_date); $prefix = Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id); $this->title = sprintf(HTMLTemplateOrderReturn::l('%1$s%2$06d'), $prefix, $this->order_return->id); $this->shop = new Shop((int) $this->order->id_shop); }
public function __construct(OrderInvoice $order_invoice, $smarty) { $this->order_invoice = $order_invoice; $this->order = new Order($this->order_invoice->id_order); $this->smarty = $smarty; // header informations $this->date = Tools::displayDate($this->order->invoice_date); $this->title = HTMLTemplateDeliverySlip::l('Delivery') . ' #' . Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id) . sprintf('%06d', $this->order_invoice->delivery_number); // footer informations $this->shop = new Shop((int) $this->order->id_shop); }
public function __construct(OrderReturn $order_return, $smarty) { $this->order_return = $order_return; $this->smarty = $smarty; $this->order = new Order($order_return->id_order); // header informations $this->date = Tools::displayDate($this->order->invoice_date); $this->title = sprintf(HTMLTemplateOrderReturn::l('Order Return #%06d'), $this->order_return->id); // footer informations $this->shop = new Shop((int) $this->order->id_shop); }
public function __construct(OrderInvoice $order_invoice, $smarty) { $this->order_invoice = $order_invoice; $this->order = new Order((int) $this->order_invoice->id_order); $this->smarty = $smarty; // header informations $this->date = Tools::displayDate($order_invoice->date_add); $id_lang = Context::getContext()->language->id; $this->title = HTMLTemplateInvoice::l('Invoice ') . ' #' . Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, (int) $this->order->id_shop) . sprintf('%06d', $order_invoice->number); // footer informations $this->shop = new Shop((int) $this->order->id_shop); }
public function __construct(SupplyOrder $supply_order, $smarty) { $this->supply_order = $supply_order; $this->smarty = $smarty; $this->context = Context::getContext(); $this->warehouse = new Warehouse((int) $supply_order->id_warehouse); $this->address_warehouse = new Address((int) $this->warehouse->id_address); $this->address_supplier = new Address(Address::getAddressIdBySupplierId((int) $supply_order->id_supplier)); // header informations $this->date = Tools::displayDate($supply_order->date_add); $this->title = HTMLTemplateSupplyOrderForm::l('Supply order form'); }
public function hookNewOrder($params) { if (!$this->_merchant_order or empty($this->_merchant_mails)) { return; } // Getting differents vars $id_lang = intval(Configuration::get('PS_LANG_DEFAULT')); $currency = $params['currency']; $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME')); $order = $params['order']; $customer = $params['customer']; $delivery = new Address(intval($order->id_address_delivery)); $invoice = new Address(intval($order->id_address_invoice)); $order_date_text = Tools::displayDate($order->date_add, intval($id_lang)); $carrier = new Carrier(intval($order->id_carrier)); $message = $order->getFirstMessage(); if (!$message or empty($message)) { $message = $this->l('No message'); } $itemsTable = ''; foreach ($params['cart']->getProducts() as $key => $product) { $unit_price = Product::getPriceStaticLC($product['id_product'], true, $product['id_product_attribute']); $price = Product::getPriceStaticLC($product['id_product'], true, $product['id_product_attribute'], 6, NULL, false, true, $product['quantity']); $itemsTable .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding:0.6em 0.4em;">' . $product['reference'] . '</td> <td style="padding:0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . '</strong></td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($unit_price, $currency, false, false) . '</td> <td style="padding:0.6em 0.4em; text-align:center;">' . intval($product['quantity']) . '</td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($price * $product['quantity'], $currency, false, false) . '</td> </tr>'; } foreach ($params['cart']->getDiscounts() as $discount) { $itemsTable .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding:0.6em 0.4em; text-align:right;">' . $this->l('Voucher code:') . ' ' . $discount['name'] . '</td> <td style="padding:0.6em 0.4em; text-align:right;">-' . Tools::displayPrice($discount['value_real'], $currency, false, false) . '</td> </tr>'; } if ($delivery->id_state) { $delivery_state = new State(intval($delivery->id_state)); } if ($invoice->id_state) { $invoice_state = new State(intval($invoice->id_state)); } // Filling-in vars for email $template = 'new_order'; $subject = $this->l('New order'); $templateVars = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone, '{invoice_other}' => $invoice->other, '{order_name}' => sprintf("%06d", $order->id), '{shop_name}' => Configuration::get('PS_SHOP_NAME'), '{date}' => $order_date_text, '{carrier}' => $carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name, '{payment}' => $order->payment, '{items}' => $itemsTable, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency), '{total_products}' => Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency), '{currency}' => $currency->sign, '{message}' => $message); $iso = Language::getIsoById(intval($id_lang)); if (file_exists(dirname(__FILE__) . '/mails/' . $iso . '/' . $template . '.txt') and file_exists(dirname(__FILE__) . '/mails/' . $iso . '/' . $template . '.html')) { Mail::Send($id_lang, $template, $subject, $templateVars, explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails), NULL, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], NULL, NULL, dirname(__FILE__) . '/mails/'); } }
public function __construct($supply_order, $smarty) { $this->supply_order = $supply_order; $this->order = $supply_order; $this->smarty = $smarty; $this->context = Context::getContext(); $this->warehouse = new Warehouse((int) $supply_order->id_warehouse); $this->address_warehouse = new Address((int) $this->warehouse->id_address); $this->address_supplier = new Address(Address::getAddressIdBySupplierId((int) $supply_order->id_supplier)); // header informations $this->date = Tools::displayDate($supply_order->date_add); $this->title = Tools::getValue('submitAction') == 'generateSupplyOrderFormPDF' ? HTMLTemplateErpSupplyOrderForm::l('Supply order form') : HTMLTemplateSupplyOrderForm::l('Receiving slip form'); }
public function postProcess() { $cart = $this->context->cart; $invoice = new Address((int) $cart->id_address_invoice); $customer = new Customer($cart->id_customer); if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) { Tools::redirect('index.php?controller=order&step=1'); } // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process $authorized = false; foreach (Module::getPaymentModules() as $module) { if ($module['name'] == 'debitnote') { $authorized = true; break; } } if (!$authorized) { die($this->module->l('This payment method is not available.', 'validation')); } $accountholder_name = $_POST['accountholder_name']; $account_number = $_POST['account_number']; $bank_code = $_POST['bank_code']; $bank_name = $_POST['bank_name']; $bank_bic = $_POST['bank_bic']; $bank_iban = $_POST['bank_iban']; $ip_address = $_POST['ip_address']; // Getting differents vars $context = Context::getContext(); $id_lang = (int) $context->language->id; $id_shop = (int) $context->shop->id; if (!$context) { $context = Context::getContext(); } $order = new Order($this->id_order); //$order = $params['order']; //$configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_COLOR'), $id_lang, null, $id_shop); if (!Validate::isLoadedObject($customer)) { Tools::redirect('index.php?controller=order&step=1'); } if (!Validate::isLoadedObject($invoice)) { Tools::redirect('index.php?controller=order&step=1'); } $currency = $this->context->currency; $total = (double) $cart->getOrderTotal(true, Cart::BOTH); $message = 'Kontoinhaber:' . $accountholder_name . '<br>' . ' Kto:' . $account_number . ' BLZ:' . $bank_code . ' Bank:' . $bank_name . ' BIC:' . $bank_bic . ' IBAN:' . $bank_iban; //Mail Vars für Kunden Mail debitnote.html $mailVars = array('{bankwire_owner}' => Configuration::get('BANK_WIRE_OWNER'), '{bankwire_details}' => nl2br(Configuration::get('BANK_WIRE_DETAILS')), '{bankwire_address}' => nl2br(Configuration::get('BANK_WIRE_ADDRESS')), '{email}' => $this->context->customer->email, '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), null, 0), '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address1, '{invoice_address1}' => $invoice->address2, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{BankBIC}' => $bank_bic, '{BankIBAN}' => $bank_iban, '{Debit_identifier}' => Configuration::get('DEBITNOTE_CREDITOR_IDENTIFIER'), '{shop_name}' => Configuration::get('PS_SHOP_NAME'), '{shop_address1}' => Configuration::get('PS_SHOP_ADDR1'), '{shop_address2}' => Configuration::get('PS_SHOP_ADDR2'), '{shop_plz}' => Configuration::get('PS_SHOP_CODE'), '{shop_city}' => Configuration::get('PS_SHOP_CITY')); $this->module->validateOrder((int) $cart->id, Configuration::get('PS_OS_DEBITNOTE'), $total, $this->module->displayName, $message, $mailVars, (int) $currency->id, false, $customer->secure_key); $this->module->writeDebitNoteDetails($this->module->currentOrder, $accountholder_name, $account_number, $bank_code, $bank_name, $bank_bic, $bank_iban, '123'); Tools::redirect('index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $this->module->id . '&id_order=' . $this->module->currentOrder . '&key=' . $customer->secure_key); }
private function displayOrdersTable() { $order_state = new OrderState((int) Configuration::get('MONDIAL_RELAY_ORDER_STATE'), $this->context->language->id); $orders = MondialRelay::getOrders(array(), MondialRelay::NO_FILTER, $this->mondialrelay->account_shop['MR_WEIGHT_COEFFICIENT']); // Simulate a ticket generation $MRCreateTicket = new MRCreateTickets(array('orderIdList' => NULL, 'totalOrder' => NULL, 'weightList' => NULL)); foreach ($orders as &$order) { $order['display_total_price'] = Tools::displayPrice($order['total'], new Currency($order['id_currency'])); $order['display_shipping_price'] = Tools::displayPrice($order['shipping'], new Currency($order['id_currency'])); $order['display_date'] = Tools::displayDate($order['date'], $order['id_lang']); } $this->context->smarty->assign(array('MR_token_admin_module' => Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id), 'MR_token_admin_contact' => Tools::getAdminToken('AdminContact' . (int) Tab::getIdFromClassName('AdminContact') . (int) $this->context->employee->id), 'MR_token_admin_orders' => Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $this->context->employee->id), 'MR_order_state_name' => $order_state->name, 'MR_orders' => $orders, 'MR_PS_IMG_DIR_' => _PS_IMG_DIR_, 'MR_errors_type' => $MRCreateTicket->checkPreValidation())); unset($order_state); echo $this->context->smarty->fetch(dirname(__FILE__) . '/tpl/admintab/generate_tickets.tpl'); }
public function __construct(OrderSlip $order_slip, $smarty) { $this->order_slip = $order_slip; $this->order = new Order((int) $order_slip->id_order); $products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order); $customized_datas = Product::getAllCustomizedDatas((int) $this->order->id_cart); Product::addCustomizationPrice($products, $customized_datas); $this->order->products = $products; $this->smarty = $smarty; // header informations $this->date = Tools::displayDate($this->order_slip->date_add); $this->title = HTMLTemplateOrderSlip::l('Order slip #') . Configuration::get('PS_CREDIT_SLIP_PREFIX', Context::getContext()->language->id) . sprintf('%06d', (int) $this->order_slip->id); // footer informations $this->shop = new Shop((int) $this->order->id_shop); }
public function __construct(OrderSlip $order_slip, $smarty) { $this->order_slip = $order_slip; $this->order = new Order((int) $order_slip->id_order); $products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order); $customized_datas = Product::getAllCustomizedDatas((int) $this->order->id_cart); Product::addCustomizationPrice($products, $customized_datas); $this->order->products = $products; $this->smarty = $smarty; // header informations $this->date = Tools::displayDate($this->order->invoice_date, (int) $this->order->id_lang); $this->title = HTMLTemplateOrderSlip::l('Slip #') . sprintf('%06d', (int) $this->order_slip->id); // footer informations $this->shop = new Shop((int) $this->order->id_shop); }
public function getTemplateVarCreditSlips() { $credit_slips = []; $orders_slip = OrderSlip::getOrdersSlip((int) $this->context->cookie->id_customer); foreach ($orders_slip as $order_slip) { $order = new Order($order_slip['id_order']); $credit_slips[$order_slip['id_order_slip']] = $order_slip; $credit_slips[$order_slip['id_order_slip']]['credit_slip_number'] = sprintf($this->trans('#%06d', array(), 'Shop.Theme.CustomerAccount'), $order_slip['id_order_slip']); $credit_slips[$order_slip['id_order_slip']]['order_number'] = sprintf($this->trans('#%06d', array(), 'Shop.Theme.CustomerAccount'), $order_slip['id_order']); $credit_slips[$order_slip['id_order_slip']]['order_reference'] = $order->reference; $credit_slips[$order_slip['id_order_slip']]['credit_slip_date'] = Tools::displayDate($order_slip['date_add'], null, false); $credit_slips[$order_slip['id_order_slip']]['url'] = $this->context->link->getPageLink('pdf-order-slip', true, null, 'id_order_slip=' . (int) $order_slip['id_order_slip']); $credit_slips[$order_slip['id_order_slip']]['order_url_details'] = $this->context->link->getPageLink('order-detail', true, null, 'id_order=' . (int) $order_slip['id_order']); } return $credit_slips; }
public function getTableRecentOrders() { $header = array(array('title' => $this->l('Customer Name'), 'class' => 'text-left'), array('title' => $this->l('Products'), 'class' => 'text-center'), array('title' => $this->l('Total'), 'class' => 'text-center'), array('title' => $this->l('Date'), 'class' => 'text-center'), array('title' => $this->l('Action'), 'class' => 'text-center')); $orders = Order::getOrdersWithInformations((int) Configuration::get('DASHPRODUCT_NBR_SHOW_LAST_ORDER', 10)); $body = array(); foreach ($orders as $order) { $currency = Currency::getCurrency((int) $order['id_currency']); $tr = array(); $tr[] = array('id' => 'firstname_lastname', 'value' => Tools::htmlentitiesUTF8($order['firstname']) . ' ' . Tools::htmlentitiesUTF8($order['lastname']), 'class' => 'text-left'); $tr[] = array('id' => 'state_name', 'value' => count(OrderDetail::getList((int) $order['id_order'])), 'class' => 'text-center'); $tr[] = array('id' => 'total_paid', 'value' => Tools::displayPrice((double) $order['total_paid'], $currency), 'class' => 'text-center', 'wrapper_start' => '<span class="badge">', 'wrapper_end' => '<span>'); $tr[] = array('id' => 'date_add', 'value' => Tools::displayDate($order['date_add']), 'class' => 'text-center'); $tr[] = array('id' => 'details', 'value' => $this->l('Details'), 'class' => 'text-right', 'wrapper_start' => '<a class="btn btn-default" href="index.php?tab=AdminOrders&id_order=' . (int) $order['id_order'] . '&vieworder&token=' . Tools::getAdminTokenLite('AdminOrders') . '" title="' . $this->l('Details') . '"><i class="icon-search"></i>', 'wrapper_end' => '</a>'); $body[] = $tr; } return array('header' => $header, 'body' => $body); }
/** * @param OrderSlip $order_slip * @param $smarty * @throws PrestaShopException */ public function __construct(OrderSlip $order_slip, $smarty) { $this->order_slip = $order_slip; $this->order = new Order((int) $order_slip->id_order); $this->id_cart = $this->order->id_cart; $products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order); foreach ($products as $product) { $customized_datas = Product::getAllCustomizedDatas($this->id_cart, null, true, null, (int) $product['id_customization']); Product::addProductCustomizationPrice($product, $customized_datas); } $this->order->products = $products; $this->smarty = $smarty; // header informations $this->date = Tools::displayDate($this->order_slip->date_add); $prefix = Configuration::get('PS_CREDIT_SLIP_PREFIX', Context::getContext()->language->id); $this->title = sprintf(HTMLTemplateOrderSlip::l('%1$s%2$06d'), $prefix, (int) $this->order_slip->id); $this->shop = new Shop((int) $this->order->id_shop); }
/** * @param OrderInvoice $order_invoice * @param $smarty * @throws PrestaShopException */ public function __construct(OrderInvoice $order_invoice, $smarty, $bulk_mode = false) { $this->order_invoice = $order_invoice; $this->order = new Order((int) $this->order_invoice->id_order); $this->smarty = $smarty; // If shop_address is null, then update it with current one. // But no DB save required here to avoid massive updates for bulk PDF generation case. // (DB: bug fixed in 1.6.1.1 with upgrade SQL script to avoid null shop_address in old orderInvoices) if (!isset($this->order_invoice->shop_address) || !$this->order_invoice->shop_address) { $this->order_invoice->shop_address = OrderInvoice::getCurrentFormattedShopAddress((int) $this->order->id_shop); if (!$bulk_mode) { OrderInvoice::fixAllShopAddresses(); } } // header informations $this->date = Tools::displayDate($order_invoice->date_add); $id_lang = Context::getContext()->language->id; $this->title = $order_invoice->getInvoiceNumberFormatted($id_lang); $this->shop = new Shop((int) $this->order->id_shop); }
public function getTemplateVarCartRules() { $cart_rules = []; $vouchers = CartRule::getCustomerCartRules($this->context->language->id, $this->context->customer->id, true, false); foreach ($vouchers as $key => $voucher) { $cart_rules[$key] = $voucher; $cart_rules[$key]['voucher_date'] = Tools::displayDate($voucher['date_to'], null, false); $cart_rules[$key]['voucher_minimal'] = $voucher['minimum_amount'] > 0 ? Tools::displayPrice($voucher['minimum_amount'], (int) $voucher['minimum_amount_currency']) : $this->trans('None', array(), 'Shop.Theme'); $cart_rules[$key]['voucher_cumulable'] = $voucher['cumulable'] ? $this->trans('Yes', array(), 'Shop.Theme') : $this->trans('No', array(), 'Shop.Theme'); if ($voucher['id_discount_type'] == 1) { $cart_rules[$key]['value'] = sprintf('%s%%', $voucher['value']); } elseif ($voucher['id_discount_type'] == 2) { $cart_rules[$key]['value'] = sprintf('%s ' . ($voucher['reduction_tax'] ? $this->trans('Tax included', array(), 'Shop.Theme.Checkout') : $this->trans('Tax excluded', array(), 'Shop.Theme.Checkout')), Tools::displayPrice($voucher['value'], (int) $voucher['reduction_currency'])); } elseif ($voucher['id_discount_type'] == 3) { $cart_rules[$key]['value'] = $this->trans('Free shipping', array(), 'Shop.Theme.Checkout'); } else { $cart_rules[$key]['value'] = '-'; } } return $cart_rules; }
/** * @param OrderInvoice $order_invoice * @param $smarty * @throws PrestaShopException */ public function __construct(OrderInvoice $order_invoice, $smarty, $bulk_mode = false) { $this->order_invoice = $order_invoice; $this->order = new Order($this->order_invoice->id_order); $this->smarty = $smarty; // If shop_address is null, then update it with current one. // But no DB save required here to avoid massive updates for bulk PDF generation case. // (DB: bug fixed in 1.6.1.1 with upgrade SQL script to avoid null shop_address in old orderInvoices) if (!isset($this->order_invoice->shop_address) || !$this->order_invoice->shop_address) { $this->order_invoice->shop_address = OrderInvoice::getCurrentFormattedShopAddress((int) $this->order->id_shop); if (!$bulk_mode) { OrderInvoice::fixAllShopAddresses(); } } // header informations $this->date = Tools::displayDate($order_invoice->date_add); $prefix = Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id); $this->title = sprintf(HTMLTemplateDeliverySlip::l('%1$s%2$06d'), $prefix, $this->order_invoice->delivery_number); // footer informations $this->shop = new Shop((int) $this->order->id_shop); }
private function displayOrdersTable() { $order_state = new OrderState((int) Configuration::get('MONDIAL_RELAY_ORDER_STATE'), $this->context->language->id); $orders = MondialRelay::getOrders(array(), MondialRelay::NO_FILTER, $this->mondialrelay->account_shop['MR_WEIGHT_COEFFICIENT']); // Simulate a ticket generation $MRCreateTicket = new MRCreateTickets(array('orderIdList' => null, 'totalOrder' => null, 'weightList' => null), $this->mondialrelay); if (is_array($orders) && count($orders)) { foreach ($orders as &$order) { $order['display_total_price'] = Tools::displayPrice($order['total'], new Currency($order['id_currency'])); $order['display_shipping_price'] = Tools::displayPrice($order['shipping'], new Currency($order['id_currency'])); if (version_compare(_PS_VERSION_, '1.5.5', '<')) { $order['display_date'] = Tools::displayDate($order['date'], $this->context->language->id); } else { $order['display_date'] = Tools::displayDate($order['date']); } $order['weight'] = !empty($order['mr_weight']) && $order['mr_weight'] > 0 ? $order['mr_weight'] : $order['order_weight']; } } $controller = _PS_VERSION_ < '1.5' ? 'AdminContact' : 'AdminStores'; $this->context->smarty->assign(array('MR_token_admin_module' => Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id), 'MR_token_admin_contact' => array('controller_name' => $controller, 'token' => Tools::getAdminToken($controller . (int) Tab::getIdFromClassName($controller) . (int) $this->context->employee->id)), 'MR_token_admin_orders' => Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $this->context->employee->id), 'MR_order_state_name' => $order_state->name, 'MR_orders' => $orders, 'MR_PS_IMG_DIR_' => _PS_IMG_DIR_, 'MR_errors_type' => $MRCreateTicket->checkPreValidation())); unset($order_state); echo $this->mondialrelay->fetchTemplate('/views/templates/admin/', 'generate_tickets'); }
public function hookAdminStatsModules($params) { global $cookie, $currentIndex; $id_category = (int) Tools::getValue('id_category'); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); if (Tools::getValue('export')) { if (!Tools::getValue('exportType')) { $this->csvExport(array('layers' => 2, 'type' => 'line', 'option' => '42')); } } $this->_html = '<fieldset class="width3"><legend><img src="../modules/' . $this->name . '/logo.gif" /> ' . $this->displayName . '</legend>'; if ($id_product = (int) Tools::getValue('id_product')) { if (Tools::getValue('export')) { if (Tools::getValue('exportType') == 1) { $this->csvExport(array('layers' => 2, 'type' => 'line', 'option' => '1-' . $id_product)); } elseif (Tools::getValue('exportType') == 2) { $this->csvExport(array('type' => 'pie', 'option' => '3-' . $id_product)); } } $product = new Product($id_product, false, (int) $cookie->id_lang); $totalBought = $this->getTotalBought($product->id); $totalSales = $this->getTotalSales($product->id); $totalViewed = $this->getTotalViewed($product->id); $this->_html .= '<h3>' . $product->name . ' - ' . $this->l('Details') . '</h3> <p>' . $this->l('Total bought:') . ' ' . $totalBought . '</p> <p>' . $this->l('Sales (-Tx):') . ' ' . Tools::displayprice($totalSales, $currency) . '</p> <p>' . $this->l('Total viewed:') . ' ' . $totalViewed . '</p> <p>' . $this->l('Conversion rate:') . ' ' . number_format($totalViewed ? $totalBought / $totalViewed : 0, 2) . '</p> <center>' . ModuleGraph::engine(array('layers' => 2, 'type' => 'line', 'option' => '1-' . $id_product)) . '</center> <br /> <p><a href="' . $_SERVER['REQUEST_URI'] . '&export=1&exportType=1"><img src="../img/admin/asterisk.gif" />' . $this->l('CSV Export') . '</a></p>'; if ($hasAttribute = $product->hasAttributes() and $totalBought) { $this->_html .= '<h3 class="space">' . $this->l('Attribute sales distribution') . '</h3><center>' . ModuleGraph::engine(array('type' => 'pie', 'option' => '3-' . $id_product)) . '</center><br /> <p><a href="' . $_SERVER['REQUEST_URI'] . '&export=1&exportType=2"><img src="../img/admin/asterisk.gif" />' . $this->l('CSV Export') . '</a></p><br />'; } if ($totalBought) { $sales = $this->getSales($id_product, $cookie->id_lang); $this->_html .= '<br class="clear" /> <h3>' . $this->l('Sales') . '</h3> <div style="overflow-y: scroll; height: ' . min(400, (count($sales) + 1) * 32) . 'px;"> <table class="table" border="0" cellspacing="0" cellspacing="0"> <thead> <tr> <th>' . $this->l('Date') . '</th> <th>' . $this->l('Order') . '</th> <th>' . $this->l('Customer') . '</th> ' . ($hasAttribute ? '<th>' . $this->l('Attribute') . '</th>' : '') . ' <th>' . $this->l('Qty') . '</th> <th>' . $this->l('Price') . '</th> </tr> </thead><tbody>'; $tokenOrder = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee); $tokenCustomer = Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $cookie->id_employee); foreach ($sales as $sale) { $this->_html .= ' <tr> <td>' . Tools::displayDate($sale['date_add'], (int) $cookie->id_lang, false) . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $sale['id_order'] . '&vieworder&token=' . $tokenOrder . '">' . (int) $sale['id_order'] . '</a></td> <td align="center"><a href="?tab=AdminCustomers&id_customer=' . $sale['id_customer'] . '&viewcustomer&token=' . $tokenCustomer . '">' . (int) $sale['id_customer'] . '</a></td> ' . ($hasAttribute ? '<td>' . $sale['product_name'] . '</td>' : '') . ' <td>' . (int) $sale['product_quantity'] . '</td> <td>' . Tools::displayprice($sale['total'], $currency) . '</td> </tr>'; } $this->_html .= '</tbody></table></div>'; $crossSelling = $this->getCrossSales($id_product, $cookie->id_lang); if (count($crossSelling)) { $this->_html .= '<br class="clear" /> <h3>' . $this->l('Cross Selling') . '</h3> <div style="overflow-y: scroll; height: 200px;"> <table class="table" border="0" cellspacing="0" cellspacing="0"> <thead> <tr> <th>' . $this->l('Product name') . '</th> <th>' . $this->l('Quantity sold') . '</th> <th>' . $this->l('Average price') . '</th> </tr> </thead><tbody>'; $tokenProducts = Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee); foreach ($crossSelling as $selling) { $this->_html .= ' <tr> <td ><a href="?tab=AdminCatalog&id_product=' . (int) $selling['id_product'] . '&addproduct&token=' . $tokenProducts . '">' . $selling['pname'] . '</a></td> <td align="center">' . (int) $selling['pqty'] . '</td> <td align="right">' . Tools::displayprice($selling['pprice'], $currency) . '</td> </tr>'; } $this->_html .= '</tbody></table></div>'; } } } else { $categories = Category::getCategories((int) $cookie->id_lang, true, false); $this->_html .= ' <label>' . $this->l('Choose a category') . '</label> <div class="margin-form"> <form action="" method="post" id="categoriesForm"> <select name="id_category" onchange="$(\'#categoriesForm\').submit();"> <option value="0">' . $this->l('All') . '</option>'; foreach ($categories as $category) { $this->_html .= '<option value="' . $category['id_category'] . '"' . ($id_category == $category['id_category'] ? ' selected="selected"' : '') . '>' . $category['name'] . '</option>'; } $this->_html .= ' </select> </form> </div> <div class="clear space"></div> ' . $this->l('Click on a product to access its statistics.') . ' <div class="clear space"></div> <h2>' . $this->l('Products available') . '</h2> <div style="overflow-y: scroll; height: 600px;"> <table class="table" border="0" cellspacing="0" cellspacing="0"> <thead> <tr> <th>' . $this->l('Ref.') . '</th> <th>' . $this->l('Name') . '</th> <th>' . $this->l('Stock') . '</th> </tr> </thead><tbody>'; foreach ($this->getProducts($cookie->id_lang) as $product) { $this->_html .= '<tr><td>' . $product['reference'] . '</td><td><a href="' . $currentIndex . '&token=' . Tools::getValue('token') . '&module=' . $this->name . '&id_product=' . $product['id_product'] . '">' . $product['name'] . '</a></td><td>' . $product['quantity'] . '</td></tr>'; } $this->_html .= '</tbody></table><br /></div><br /> <a href="' . $_SERVER['REQUEST_URI'] . '&export=1"><img src="../img/admin/asterisk.gif" />' . $this->l('CSV Export') . '</a><br />'; } $this->_html .= '</fieldset><br /> <fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> ' . $this->l('Guide') . '</legend> <h2>' . $this->l('Number of purchases compared to number of viewings') . '</h2> <p> ' . $this->l('After choosing a category and selecting a product, informational graphs will appear. Then, you will be able to analyze them.') . ' <ul> <li class="bullet">' . $this->l('If you notice that a product is successful and often purchased, but viewed infrequently, you should put it more prominently on your webshop front-office.') . '</li> <li class="bullet">' . $this->l('On the other hand, if a product has many viewings but is not often purchased, we advise you to check or modify this product\'s information, description and photography again.') . ' </li> </ul> </p> </fieldset>'; return $this->_html; }
/** * Hook display in tab AdminCustomers on BO * Data table with all sponsors informations for a customer */ public function hookAdminCustomers($params) { include_once dirname(__FILE__) . '/ReferralProgramModule.php'; $customer = new Customer((int) $params['id_customer']); if (!Validate::isLoadedObject($customer)) { die($this->l('Incorrect Customer object.')); } $friends = ReferralProgramModule::getSponsorFriend((int) $customer->id); if ($id_referralprogram = ReferralProgramModule::isSponsorised((int) $customer->id, true)) { $referralprogram = new ReferralProgramModule((int) $id_referralprogram); $sponsor = new Customer((int) $referralprogram->id_sponsor); } $html = ' <div class="clear"> </div> <h2>' . $this->l('Referral program') . ' (' . count($friends) . ')</h2> <h3>' . (isset($sponsor) ? $this->l('Customer\'s sponsor:') . ' <a href="index.php?tab=AdminCustomers&id_customer=' . (int) $sponsor->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id) . '">' . $sponsor->firstname . ' ' . $sponsor->lastname . '</a>' : $this->l('No one has sponsored this customer.')) . '</h3>'; if ($friends and sizeof($friends)) { $html .= '<h3>' . sizeof($friends) . ' ' . (sizeof($friends) > 1 ? $this->l('Sponsored customers:') : $this->l('Sponsored customer:')) . '</h3>'; $html .= ' <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('Email') . '</th> <th class="center">' . $this->l('Registration date') . '</th> <th class="center">' . $this->l('Customers sponsored by this friend') . '</th> <th class="center">' . $this->l('Placed orders') . '</th> <th class="center">' . $this->l('Customer account created') . '</th> </tr>'; foreach ($friends as $key => $friend) { $orders = Order::getCustomerOrders($friend['id_customer']); $html .= ' <tr ' . ($key++ % 2 ? 'class="alt_row"' : '') . ' ' . ((int) $friend['id_customer'] ? 'style="cursor: pointer" onclick="document.location = \'?tab=AdminCustomers&id_customer=' . $friend['id_customer'] . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id) . '\'"' : '') . '> <td class="center">' . ((int) $friend['id_customer'] ? $friend['id_customer'] : '--') . '</td> <td>' . $friend['firstname'] . ' ' . $friend['lastname'] . '</td> <td>' . $friend['email'] . '</td> <td>' . Tools::displayDate($friend['date_add'], $this->context->language->id, true) . '</td> <td align="right">' . sizeof(ReferralProgramModule::getSponsorFriend($friend['id_customer'])) . '</td> <td align="right">' . ($orders ? sizeof($orders) : 0) . '</td> <td align="center">' . ((int) $friend['id_customer'] ? '<img src="' . _PS_ADMIN_IMG_ . 'enabled.gif" />' : '<img src="' . _PS_ADMIN_IMG_ . 'disabled.gif" />') . '</td> </tr>'; } $html .= ' </table>'; } else { $html .= sprintf($this->l('%1$s %2$s has not sponsored any friends yet.'), $customer->firstname, $customer->lastname); } return $html . '<br/><br/>'; }
/** * Assign template vars related to attribute groups and colors */ protected function assignAttributesGroups() { $colors = array(); $groups = array(); // @todo (RM) should only get groups and not all declination ? $attributes_groups = $this->product->getAttributesGroups($this->context->language->id); if (is_array($attributes_groups) && $attributes_groups) { $combination_images = $this->product->getCombinationImages($this->context->language->id); $combination_prices_set = array(); foreach ($attributes_groups as $k => $row) { // Color management if (isset($row['attribute_color']) && $row['attribute_color'] || file_exists(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) { $colors[$row['id_attribute']]['value'] = $row['attribute_color']; $colors[$row['id_attribute']]['name'] = $row['attribute_name']; if (!isset($colors[$row['id_attribute']]['attributes_quantity'])) { $colors[$row['id_attribute']]['attributes_quantity'] = 0; } $colors[$row['id_attribute']]['attributes_quantity'] += (int) $row['quantity']; } if (!isset($groups[$row['id_attribute_group']])) { $groups[$row['id_attribute_group']] = array('name' => $row['public_group_name'], 'group_type' => $row['group_type'], 'default' => -1); } $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) { $groups[$row['id_attribute_group']]['default'] = (int) $row['id_attribute']; } if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) { $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0; } $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int) $row['quantity']; if ($row['available_date'] != '0000-00-00 00:00:00' && $row['available_date'] != '0000-00-00') { $available_date = Tools::displayDate($row['available_date'], $this->context->language->id); } else { $available_date = $row['available_date']; } $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = (int) $row['id_attribute']; $combinations[$row['id_product_attribute']]['price'] = (double) $row['price']; // Call getPriceStatic in order to set $combination_specific_price if (!isset($combination_prices_set[(int) $row['id_product_attribute']])) { Product::getPriceStatic((int) $this->product->id, false, $row['id_product_attribute'], 6, null, false, true, 1, false, null, null, null, $combination_specific_price); $combination_prices_set[(int) $row['id_product_attribute']] = true; $combinations[$row['id_product_attribute']]['specific_price'] = $combination_specific_price; } $combinations[$row['id_product_attribute']]['ecotax'] = (double) $row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (double) $row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int) $row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; $combinations[$row['id_product_attribute']]['available_date'] = $available_date; if (isset($combination_images[$row['id_product_attribute']][0]['id_image'])) { $combinations[$row['id_product_attribute']]['id_image'] = $combination_images[$row['id_product_attribute']][0]['id_image']; } else { $combinations[$row['id_product_attribute']]['id_image'] = -1; } } // wash attributes list (if some attributes are unavailables and if allowed to wash it) if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) { foreach ($groups as &$group) { foreach ($group['attributes_quantity'] as $key => &$quantity) { if (!$quantity) { unset($group['attributes'][$key]); } } } foreach ($colors as $key => $color) { if (!$color['attributes_quantity']) { unset($colors[$key]); } } } foreach ($combinations as $id_product_attribute => $comb) { $attribute_list = ''; foreach ($comb['attributes'] as $id_attribute) { $attribute_list .= '\'' . (int) $id_attribute . '\','; } $attribute_list = rtrim($attribute_list, ','); $combinations[$id_product_attribute]['list'] = $attribute_list; } $this->context->smarty->assign(array('groups' => $groups, 'combinations' => $combinations, 'colors' => count($colors) ? $colors : false, 'combinationImages' => $combination_images)); } }
public function displayListContent($token = NULL) { /* Display results in a table * * align : determine value alignment * prefix : displayed before value * suffix : displayed after value * image : object image * icon : icon determined by values * active : allow to toggle status */ global $currentIndex, $cookie; $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $id_category = 1; // default categ $irow = 0; if ($this->_list and isset($this->fieldsDisplay['position'])) { $positions = array_map(create_function('$elem', 'return (int)($elem[\'position\']);'), $this->_list); sort($positions); } if ($this->_list) { $isCms = false; if (preg_match('/cms/Ui', $this->identifier)) { $isCms = true; } $keyToGet = 'id_' . ($isCms ? 'cms_' : '') . 'category' . (in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : ''); foreach ($this->_list as $tr) { $id = $tr[$this->identifier]; echo '<tr' . (array_key_exists($this->identifier, $this->identifiersDnd) ? ' id="tr_' . (($id_category = (int) Tools::getValue('id_' . ($isCms ? 'cms_' : '') . 'category', '1')) ? $id_category : '') . '_' . $id . '_' . $tr['position'] . '"' : '') . ($irow++ % 2 ? ' class="alt_row"' : '') . ' ' . ((isset($tr['color']) and $this->colorOnBackground) ? 'style="background-color: ' . $tr['color'] . '"' : '') . '> <td class="center">'; if ($this->delete and (!isset($this->_listSkipDelete) or !in_array($id, $this->_listSkipDelete))) { echo '<input type="checkbox" name="' . $this->table . 'Box[]" value="' . $id . '" class="noborder" />'; } echo '</td>'; foreach ($this->fieldsDisplay as $key => $params) { $tmp = explode('!', $key); $key = isset($tmp[1]) ? $tmp[1] : $tmp[0]; echo ' <td ' . (isset($params['position']) ? ' id="td_' . (isset($id_category) and $id_category ? $id_category : 0) . '_' . $id . '"' : '') . ' class="' . ((!isset($this->noLink) or !$this->noLink) ? 'pointer' : '') . ((isset($params['position']) and $this->_orderBy == 'position') ? ' dragHandle' : '') . (isset($params['align']) ? ' ' . $params['align'] : '') . '" '; if (!isset($params['position']) and (!isset($this->noLink) or !$this->noLink)) { echo ' onclick="document.location = \'' . $currentIndex . '&' . $this->identifier . '=' . $id . ($this->view ? '&view' : '&update') . $this->table . '&token=' . ($token != NULL ? $token : $this->token) . '\'">' . (isset($params['prefix']) ? $params['prefix'] : ''); } else { echo '>'; } if (isset($params['active']) and isset($tr[$key])) { $this->_displayEnableLink($token, $id, $tr[$key], $params['active'], Tools::getValue('id_category'), Tools::getValue('id_product')); } elseif (isset($params['activeVisu']) and isset($tr[$key])) { echo '<img src="../img/admin/' . ($tr[$key] ? 'enabled.gif' : 'disabled.gif') . '" alt="' . ($tr[$key] ? $this->l('Enabled') : $this->l('Disabled')) . '" title="' . ($tr[$key] ? $this->l('Enabled') : $this->l('Disabled')) . '" />'; } elseif (isset($params['position'])) { if ($this->_orderBy == 'position' and $this->_orderWay != 'DESC') { echo '<a' . (!($tr[$key] != $positions[sizeof($positions) - 1]) ? ' style="display: none;"' : '') . ' href="' . $currentIndex . '&' . $keyToGet . '=' . (int) $id_category . '&' . $this->identifiersDnd[$this->identifier] . '=' . $id . ' &way=1&position=' . (int) ($tr['position'] + 1) . '&token=' . ($token != NULL ? $token : $this->token) . '"> <img src="../img/admin/' . ($this->_orderWay == 'ASC' ? 'down' : 'up') . '.gif" alt="' . $this->l('Down') . '" title="' . $this->l('Down') . '" /></a>'; echo '<a' . (!($tr[$key] != $positions[0]) ? ' style="display: none;"' : '') . ' href="' . $currentIndex . '&' . $keyToGet . '=' . (int) $id_category . '&' . $this->identifiersDnd[$this->identifier] . '=' . $id . ' &way=0&position=' . (int) ($tr['position'] - 1) . '&token=' . ($token != NULL ? $token : $this->token) . '"> <img src="../img/admin/' . ($this->_orderWay == 'ASC' ? 'up' : 'down') . '.gif" alt="' . $this->l('Up') . '" title="' . $this->l('Up') . '" /></a>'; } else { echo (int) ($tr[$key] + 1); } } elseif (isset($params['image'])) { // item_id is the product id in a product image context, else it is the image id. $item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id; // If it's a product image if (isset($tr['id_image'])) { $image = new Image((int) $tr['id_image']); $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $image->getExistingImgPath() . '.' . $this->imageType; } else { $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $item_id . (isset($tr['id_image']) ? '-' . (int) $tr['id_image'] : '') . '.' . $this->imageType; } echo cacheImage($path_to_image, $this->table . '_mini_' . $item_id . '.' . $this->imageType, 45, $this->imageType); } elseif (isset($params['icon']) and (isset($params['icon'][$tr[$key]]) or isset($params['icon']['default']))) { echo '<img src="../img/admin/' . (isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'] . '" alt="' . $tr[$key]) . '" title="' . $tr[$key] . '" />'; } elseif (isset($params['price'])) { echo Tools::displayPrice($tr[$key], isset($params['currency']) ? Currency::getCurrencyInstance((int) $tr['id_currency']) : $currency, false); } elseif (isset($params['float'])) { echo rtrim(rtrim($tr[$key], '0'), '.'); } elseif (isset($params['type']) and $params['type'] == 'date') { echo Tools::displayDate($tr[$key], (int) $cookie->id_lang); } elseif (isset($params['type']) and $params['type'] == 'datetime') { echo Tools::displayDate($tr[$key], (int) $cookie->id_lang, true); } elseif (isset($tr[$key])) { $echo = $key == 'price' ? round($tr[$key], 2) : isset($params['maxlength']) ? Tools::substr($tr[$key], 0, $params['maxlength']) . '...' : $tr[$key]; echo isset($params['callback']) ? call_user_func_array(array($this->className, $params['callback']), array($echo, $tr)) : $echo; } else { echo '--'; } echo (isset($params['suffix']) ? $params['suffix'] : '') . '</td>'; } if ($this->edit or $this->delete or $this->view and $this->view !== 'noActionColumn') { echo '<td class="center" style="white-space: nowrap;">'; if ($this->view) { $this->_displayViewLink($token, $id); } if ($this->edit) { $this->_displayEditLink($token, $id); } if ($this->delete and (!isset($this->_listSkipDelete) or !in_array($id, $this->_listSkipDelete))) { $this->_displayDeleteLink($token, $id); } if ($this->duplicate) { $this->_displayDuplicate($token, $id); } if ($this->allegro) { $this->_displayAllegroLink($id); } echo '</td>'; } echo '</tr>'; } } }
protected function displayMessage($message, $email = false, $id_employee = null) { $tpl = $this->createTemplate('message.tpl'); $contacts = Contact::getContacts($this->context->language->id); foreach ($contacts as $contact) { $contact_array[$contact['id_contact']] = array('id_contact' => $contact['id_contact'], 'name' => $contact['name']); } $contacts = $contact_array; if (!$email) { if (!empty($message['id_product']) && empty($message['employee_name'])) { $id_order_product = Order::getIdOrderProduct((int) $message['id_customer'], (int) $message['id_product']); } } $message['date_add'] = Tools::displayDate($message['date_add'], null, true); $message['user_agent'] = strip_tags($message['user_agent']); $message['message'] = preg_replace('/(https?:\\/\\/[a-z0-9#%&_=\\(\\)\\.\\? \\+\\-@\\/]{6,1000})([\\s\\n<])/Uui', '<a href="\\1">\\1</a>\\2', html_entity_decode($message['message'], ENT_QUOTES, 'UTF-8')); $is_valid_order_id = true; $order = new Order((int) $message['id_order']); if (!Validate::isLoadedObject($order)) { $is_valid_order_id = false; } $tpl->assign(array('thread_url' => Tools::getAdminUrl(basename(_PS_ADMIN_DIR_) . '/' . $this->context->link->getAdminLink('AdminCustomerThreads') . '&id_customer_thread=' . (int) $message['id_customer_thread'] . '&viewcustomer_thread=1'), 'link' => Context::getContext()->link, 'current' => self::$currentIndex, 'token' => $this->token, 'message' => $message, 'id_order_product' => isset($id_order_product) ? $id_order_product : null, 'email' => $email, 'id_employee' => $id_employee, 'PS_SHOP_NAME' => Configuration::get('PS_SHOP_NAME'), 'file_name' => file_exists(_PS_UPLOAD_DIR_ . $message['file_name']), 'contacts' => $contacts, 'is_valid_order_id' => $is_valid_order_id)); return $tpl->fetch(); }
/** * Display date regarding to language preferences * * @param array $params Date, format... * @param object $smarty Smarty object for language preferences * * @return string Date */ public static function dateFormat($params, &$smarty) { return Tools::displayDate($params['date'], null, isset($params['full']) ? $params['full'] : false); }
public function hookAdminStatsModules() { $id_category = (int) Tools::getValue('id_category'); $currency = Context::getContext()->currency; if (Tools::getValue('export')) { if (!Tools::getValue('exportType')) { $this->csvExport(array('layers' => 2, 'type' => 'line', 'option' => '42')); } } $this->html = ' <div class="panel-heading"> ' . $this->displayName . ' </div> <h4>' . $this->l('Guide') . '</h4> <div class="alert alert-warning"> <h4>' . $this->l('Number of purchases compared to number of views') . '</h4> <p> ' . $this->l('After choosing a category and selecting a product, informational graphs will appear.') . ' <ul> <li class="bullet">' . $this->l('If you notice that a product is often purchased but viewed infrequently, you should display it more prominently in your Front Office.') . '</li> <li class="bullet">' . $this->l('On the other hand, if a product has many views but is not often purchased, we advise you to check or modify this product\'s information, description and photography again, see if you can find something better.') . ' </li> </ul> </p> </div>'; if ($id_product = (int) Tools::getValue('id_product')) { if (Tools::getValue('export')) { if (Tools::getValue('exportType') == 1) { $this->csvExport(array('layers' => 2, 'type' => 'line', 'option' => '1-' . $id_product)); } elseif (Tools::getValue('exportType') == 2) { $this->csvExport(array('type' => 'pie', 'option' => '3-' . $id_product)); } } $product = new Product($id_product, false, $this->context->language->id); $total_bought = $this->getTotalBought($product->id); $total_sales = $this->getTotalSales($product->id); $total_viewed = $this->getTotalViewed($product->id); $this->html .= '<h4>' . $product->name . ' - ' . $this->l('Details') . '</h4> <div class="row row-margin-bottom"> <div class="col-lg-12"> <div class="col-lg-8"> ' . $this->engine(array('layers' => 2, 'type' => 'line', 'option' => '1-' . $id_product)) . ' </div> <div class="col-lg-4"> <ul class="list-unstyled"> <li>' . $this->l('Total bought') . ' ' . $total_bought . '</li> <li>' . $this->l('Sales (tax excluded)') . ' ' . Tools::displayprice($total_sales, $currency) . '</li> <li>' . $this->l('Total viewed') . ' ' . $total_viewed . '</li> <li>' . $this->l('Conversion rate') . ' ' . number_format($total_viewed ? $total_bought / $total_viewed : 0, 2) . '</li> </ul> <a class="btn btn-default export-csv" href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&export=1&exportType=1"> <i class="icon-cloud-upload"></i> ' . $this->l('CSV Export') . ' </a> </div> </div> </div>'; if ($has_attribute = $product->hasAttributes() && $total_bought) { $this->html .= '<h3 class="space">' . $this->l('Attribute sales distribution') . '</h3><center>' . $this->engine(array('type' => 'pie', 'option' => '3-' . $id_product)) . '</center><br /> <a href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&export=1&exportType=2"><img src="../img/admin/asterisk.gif" />' . $this->l('CSV Export') . '</a>'; } if ($total_bought) { $sales = $this->getSales($id_product); $this->html .= ' <h4>' . $this->l('Sales') . '</h4> <div style="overflow-y: scroll; height: ' . min(400, (count($sales) + 1) * 32) . 'px;"> <table class="table"> <thead> <tr> <th> <span class="title_box active">' . $this->l('Date') . '</span> </th> <th> <span class="title_box active">' . $this->l('Order') . '</span> </th> <th> <span class="title_box active">' . $this->l('Customer') . '</span> </th> ' . ($has_attribute ? '<th><span class="title_box active">' . $this->l('Attribute') . '</span></th>' : '') . ' <th> <span class="title_box active">' . $this->l('Quantity') . '</span> </th> <th> <span class="title_box active">' . $this->l('Price') . '</span> </th> </tr> </thead> <tbody>'; $token_order = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $this->context->employee->id); $token_customer = Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id); foreach ($sales as $sale) { $this->html .= ' <tr> <td>' . Tools::displayDate($sale['date_add'], null, false) . '</td> <td align="center"><a href="?tab=AdminOrders&id_order=' . $sale['id_order'] . '&vieworder&token=' . $token_order . '">' . (int) $sale['id_order'] . '</a></td> <td align="center"><a href="?tab=AdminCustomers&id_customer=' . $sale['id_customer'] . '&viewcustomer&token=' . $token_customer . '">' . (int) $sale['id_customer'] . '</a></td> ' . ($has_attribute ? '<td>' . $sale['product_name'] . '</td>' : '') . ' <td>' . (int) $sale['product_quantity'] . '</td> <td>' . Tools::displayprice($sale['total'], $currency) . '</td> </tr>'; } $this->html .= ' </tbody> </table> </div>'; $cross_selling = $this->getCrossSales($id_product, $this->context->language->id); if (count($cross_selling)) { $this->html .= ' <h4>' . $this->l('Cross selling') . '</h4> <div style="overflow-y: scroll; height: 200px;"> <h4>' . $this->l('Cross selling') . '</h4> <table class="table"> <thead> <tr> <th> <span class="title_box active">' . $this->l('Product name') . '</span> </th> <th> <span class="title_box active">' . $this->l('Quantity sold') . '</span> </th> <th> <span class="title_box active">' . $this->l('Average price') . '</span> </th> </tr> </thead> <tbody>'; $token_products = Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) $this->context->employee->id); foreach ($cross_selling as $selling) { $this->html .= ' <tr> <td ><a href="?tab=AdminProducts&id_product=' . (int) $selling['id_product'] . '&addproduct&token=' . $token_products . '">' . $selling['pname'] . '</a></td> <td align="center">' . (int) $selling['pqty'] . '</td> <td align="right">' . Tools::displayprice($selling['pprice'], $currency) . '</td> </tr>'; } $this->html .= ' </tbody> </table> </div>'; } } } else { $categories = Category::getCategories((int) $this->context->language->id, true, false); $this->html .= ' <form action="" method="post" id="categoriesForm" class="form-horizontal"> <div class="row row-margin-bottom"> <label class="control-label col-lg-3" for="id_category"> <span title="" data-toggle="tooltip" class="label-tooltip" data-original-title="' . $this->l('Click on a product to access its statistics!') . '"> ' . $this->l('Choose a category') . ' </span> </label> <div class="col-lg-3"> <select name="id_category" onchange="$(\'#categoriesForm\').submit();"> <option value="0">' . $this->l('All') . '</option>'; foreach ($categories as $category) { $this->html .= '<option value="' . $category['id_category'] . '"' . ($id_category == $category['id_category'] ? ' selected="selected"' : '') . '>' . $category['name'] . '</option>'; } $this->html .= ' </select> </div> </div> </form> <h4>' . $this->l('Products available') . '</h4> <table class="table" border="0" cellspacing="0" cellspacing="0"> <thead> <tr> <th> <span class="title_box active">' . $this->l('Reference') . '</span> </th> <th> <span class="title_box active">' . $this->l('Name') . '</span> </th> <th> <span class="title_box active">' . $this->l('Available quantity for sale') . '</span> </th> </tr> </thead> <tbody>'; foreach ($this->getProducts($this->context->language->id) as $product) { $this->html .= ' <tr> <td>' . $product['reference'] . '</td> <td> <a href="' . AdminController::$currentIndex . '&token=' . Tools::safeOutput(Tools::getValue('token')) . '&module=' . $this->name . '&id_product=' . $product['id_product'] . '">' . $product['name'] . '</a> </td> <td>' . $product['quantity'] . '</td> </tr>'; } $this->html .= ' </tbody> </table> <a class="btn btn-default export-csv" href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&export=1"> <i class="icon-cloud-upload"></i> ' . $this->l('CSV Export') . ' </a>'; } return $this->html; }
public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null) { if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Function called', 1, null, 'Cart', (int) $id_cart, true); } if (!isset($this->context)) { $this->context = Context::getContext(); } $this->context->cart = new Cart($id_cart); $this->context->customer = new Customer($this->context->cart->id_customer); // The tax cart is loaded before the customer so re-cache the tax calculation method $this->context->cart->setTaxCalculationMethod(); $this->context->language = new Language($this->context->cart->id_lang); $this->context->shop = $shop ? $shop : new Shop($this->context->cart->id_shop); ShopUrl::resetMainDomainCache(); $id_currency = $currency_special ? (int) $currency_special : (int) $this->context->cart->id_currency; $this->context->currency = new Currency($id_currency, null, $this->context->shop->id); if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { $context_country = $this->context->country; } $order_status = new OrderState((int) $id_order_state, (int) $this->context->language->id); if (!Validate::isLoadedObject($order_status)) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order Status cannot be loaded', 3, null, 'Cart', (int) $id_cart, true); throw new PrestaShopException('Can\'t load Order status'); } if (!$this->active) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Module is not active', 3, null, 'Cart', (int) $id_cart, true); die(Tools::displayError()); } // Does order already exists ? if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists() == false) { if ($secure_key !== false && $secure_key != $this->context->cart->secure_key) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Secure key does not match', 3, null, 'Cart', (int) $id_cart, true); die(Tools::displayError()); } // For each package, generate an order $delivery_option_list = $this->context->cart->getDeliveryOptionList(); $package_list = $this->context->cart->getPackageList(); $cart_delivery_option = $this->context->cart->getDeliveryOption(); // If some delivery options are not defined, or not valid, use the first valid option foreach ($delivery_option_list as $id_address => $package) { if (!isset($cart_delivery_option[$id_address]) || !array_key_exists($cart_delivery_option[$id_address], $package)) { foreach ($package as $key => $val) { $cart_delivery_option[$id_address] = $key; break; } } } $order_list = array(); $order_detail_list = array(); do { $reference = Order::generateReference(); } while (Order::getByReference($reference)->count()); $this->currentOrderReference = $reference; $order_creation_failed = false; $cart_total_paid = (double) Tools::ps_round((double) $this->context->cart->getOrderTotal(true, Cart::BOTH), 2); foreach ($cart_delivery_option as $id_address => $key_carriers) { foreach ($delivery_option_list[$id_address][$key_carriers]['carrier_list'] as $id_carrier => $data) { foreach ($data['package_list'] as $id_package) { // Rewrite the id_warehouse $package_list[$id_address][$id_package]['id_warehouse'] = (int) $this->context->cart->getPackageIdWarehouse($package_list[$id_address][$id_package], (int) $id_carrier); $package_list[$id_address][$id_package]['id_carrier'] = $id_carrier; } } } // Make sure CartRule caches are empty CartRule::cleanCache(); $cart_rules = $this->context->cart->getCartRules(); foreach ($cart_rules as $cart_rule) { if (($rule = new CartRule((int) $cart_rule['obj']->id)) && Validate::isLoadedObject($rule)) { if ($error = $rule->checkValidity($this->context, true, true)) { $this->context->cart->removeCartRule((int) $rule->id); if (isset($this->context->cookie) && isset($this->context->cookie->id_customer) && $this->context->cookie->id_customer && !empty($rule->code)) { if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('index.php?controller=order-opc&submitAddDiscount=1&discount_name=' . urlencode($rule->code)); } Tools::redirect('index.php?controller=order&submitAddDiscount=1&discount_name=' . urlencode($rule->code)); } else { $rule_name = isset($rule->name[(int) $this->context->cart->id_lang]) ? $rule->name[(int) $this->context->cart->id_lang] : $rule->code; $error = Tools::displayError(sprintf('CartRule ID %1s (%2s) used in this cart is not valid and has been withdrawn from cart', (int) $rule->id, $rule_name)); PrestaShopLogger::addLog($error, 3, '0000002', 'Cart', (int) $this->context->cart->id); } } } } foreach ($package_list as $id_address => $packageByAddress) { foreach ($packageByAddress as $id_package => $package) { $order = new Order(); $order->product_list = $package['product_list']; if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { $address = new Address($id_address); $this->context->country = new Country($address->id_country, $this->context->cart->id_lang); if (!$this->context->country->active) { throw new PrestaShopException('The delivery address country is not active.'); } } $carrier = null; if (!$this->context->cart->isVirtualCart() && isset($package['id_carrier'])) { $carrier = new Carrier($package['id_carrier'], $this->context->cart->id_lang); $order->id_carrier = (int) $carrier->id; $id_carrier = (int) $carrier->id; } else { $order->id_carrier = 0; $id_carrier = 0; } $order->id_customer = (int) $this->context->cart->id_customer; $order->id_address_invoice = (int) $this->context->cart->id_address_invoice; $order->id_address_delivery = (int) $id_address; $order->id_currency = $this->context->currency->id; $order->id_lang = (int) $this->context->cart->id_lang; $order->id_cart = (int) $this->context->cart->id; $order->reference = $reference; $order->id_shop = (int) $this->context->shop->id; $order->id_shop_group = (int) $this->context->shop->id_shop_group; $order->secure_key = $secure_key ? pSQL($secure_key) : pSQL($this->context->customer->secure_key); $order->payment = $payment_method; if (isset($this->name)) { $order->module = $this->name; } $order->recyclable = $this->context->cart->recyclable; $order->gift = (int) $this->context->cart->gift; $order->gift_message = $this->context->cart->gift_message; $order->mobile_theme = $this->context->cart->mobile_theme; $order->conversion_rate = $this->context->currency->conversion_rate; $amount_paid = !$dont_touch_amount ? Tools::ps_round((double) $amount_paid, 2) : $amount_paid; $order->total_paid_real = 0; $order->total_products = (double) $this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_products_wt = (double) $this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_discounts_tax_excl = (double) abs($this->context->cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier)); $order->total_discounts_tax_incl = (double) abs($this->context->cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier)); $order->total_discounts = $order->total_discounts_tax_incl; $order->total_shipping_tax_excl = (double) $this->context->cart->getPackageShippingCost((int) $id_carrier, false, null, $order->product_list); $order->total_shipping_tax_incl = (double) $this->context->cart->getPackageShippingCost((int) $id_carrier, true, null, $order->product_list); $order->total_shipping = $order->total_shipping_tax_incl; if (!is_null($carrier) && Validate::isLoadedObject($carrier)) { $order->carrier_tax_rate = $carrier->getTaxesRate(new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); } $order->total_wrapping_tax_excl = (double) abs($this->context->cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier)); $order->total_wrapping_tax_incl = (double) abs($this->context->cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier)); $order->total_wrapping = $order->total_wrapping_tax_incl; $order->total_paid_tax_excl = (double) Tools::ps_round((double) $this->context->cart->getOrderTotal(false, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); $order->total_paid_tax_incl = (double) Tools::ps_round((double) $this->context->cart->getOrderTotal(true, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); $order->total_paid = $order->total_paid_tax_incl; $order->round_mode = Configuration::get('PS_PRICE_ROUND_MODE'); $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Creating order $result = $order->add(); if (!$result) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order cannot be created', 3, null, 'Cart', (int) $id_cart, true); throw new PrestaShopException('Can\'t save Order'); } // Amount paid by customer is not the right one -> Status = payment error // We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php // if ($order->total_paid != $order->total_paid_real) // We use number_format in order to compare two string if ($order_status->logable && number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_)) { $id_order_state = Configuration::get('PS_OS_ERROR'); } $order_list[] = $order; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - OrderDetail is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Insert new Order detail list using cart for the current order $order_detail = new OrderDetail(null, null, $this->context); $order_detail->createList($order, $this->context->cart, $id_order_state, $order->product_list, 0, true, $package_list[$id_address][$id_package]['id_warehouse']); $order_detail_list[] = $order_detail; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - OrderCarrier is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Adding an entry in order_carrier table if (!is_null($carrier)) { $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int) $order->id; $order_carrier->id_carrier = (int) $id_carrier; $order_carrier->weight = (double) $order->getTotalWeight(); $order_carrier->shipping_cost_tax_excl = (double) $order->total_shipping_tax_excl; $order_carrier->shipping_cost_tax_incl = (double) $order->total_shipping_tax_incl; $order_carrier->add(); } } } // The country can only change if the address used for the calculation is the delivery address, and if multi-shipping is activated if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { $this->context->country = $context_country; } if (!$this->context->country->active) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Country is not active', 3, null, 'Cart', (int) $id_cart, true); throw new PrestaShopException('The order address country is not active.'); } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Payment is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Register Payment only if the order status validate the order if ($order_status->logable) { // $order is the last order loop in the foreach // The method addOrderPayment of the class Order make a create a paymentOrder // linked to the order reference and not to the order id if (isset($extra_vars['transaction_id'])) { $transaction_id = $extra_vars['transaction_id']; } else { $transaction_id = null; } if (!$order->addOrderPayment($amount_paid, null, $transaction_id)) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Cannot save Order Payment', 3, null, 'Cart', (int) $id_cart, true); throw new PrestaShopException('Can\'t save Order Payment'); } } // Next ! $only_one_gift = false; $cart_rule_used = array(); $products = $this->context->cart->getProducts(); // Make sure CarRule caches are empty CartRule::cleanCache(); foreach ($order_detail_list as $key => $order_detail) { $order = $order_list[$key]; if (!$order_creation_failed && isset($order->id)) { if (!$secure_key) { $message .= '<br />' . Tools::displayError('Warning: the secure key is empty, check your payment account before validation'); } // Optional message to attach to this order if (isset($message) & !empty($message)) { $msg = new Message(); $message = strip_tags($message, '<br>'); if (Validate::isCleanHtml($message)) { if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Message is about to be added', 1, null, 'Cart', (int) $id_cart, true); } $msg->message = $message; $msg->id_order = (int) $order->id; $msg->private = 1; $msg->add(); } } // Insert new Order detail list using cart for the current order //$orderDetail = new OrderDetail(null, null, $this->context); //$orderDetail->createList($order, $this->context->cart, $id_order_state); // Construct order detail table for the email $products_list = ''; $virtual_product = true; $ppropertiessmartprice_hook1 = null; $product_var_tpl_list = array(); foreach ($order->product_list as $product) { PP::smartyPPAssign(array('cart' => $product, 'currency' => $this->context->currency)); $price = Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : null, 6, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $price_wt = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : null, 2, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ppropertiessmartprice_hook2 = ''; $product_var_tpl = array('reference' => $product['reference'], 'name' => $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : '') . PP::smartyDisplayProductName(array('name' => '')) . $ppropertiessmartprice_hook2, 'unit_price' => PP::smartyDisplayPrice(array('price' => Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt)), 'price' => PP::smartyDisplayPrice(array('price' => Product::getTaxCalculationMethod() == PS_TAX_EXC ? $product['total'] : $product['total_wt'], 'quantity' => (int) $product['cart_quantity'], 'm' => 'total')), 'quantity' => PP::smartyDisplayQty(array('quantity' => (int) $product['cart_quantity'])), 'customization' => array()); $customized_datas = Product::getAllCustomizedDatas((int) $order->id_cart); $productHasCustomizedDatas = Product::hasCustomizedDatas($product, $customized_datas); if ($productHasCustomizedDatas && isset($customized_datas[$product['id_product']][$product['id_product_attribute']])) { $product_var_tpl['customization'] = array(); foreach ($customized_datas[$product['id_product']][$product['id_product_attribute']][$order->id_address_delivery] as $customization) { if ($product['id_cart_product'] == $customization['id_cart_product']) { $customization_text = ''; if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD])) { foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] as $text) { $customization_text .= $text['name'] . ': ' . $text['value'] . '<br />'; } } if (isset($customization['datas'][Product::CUSTOMIZE_FILE])) { $customization_text .= sprintf(Tools::displayError('%d image(s)'), count($customization['datas'][Product::CUSTOMIZE_FILE])) . '<br />'; } $customization_quantity = (int) $product['customization_quantity']; $product_var_tpl['customization'][] = array('customization_text' => $customization_text, 'customization_quantity' => PP::smartyDisplayQty(array('quantity' => $customization_quantity)), 'quantity' => PP::smartyDisplayPrice(array('price' => Product::getTaxCalculationMethod() == PS_TAX_EXC ? $product['total_customization'] : $product['total_customization_wt'], 'm' => 'total'))); } } } $product_var_tpl_list[] = $product_var_tpl; // Check if is not a virutal product for the displaying of shipping if (!$product['is_virtual']) { $virtual_product &= false; } } // end foreach ($products) PP::smartyPPAssign(); $product_list_txt = ''; $product_list_html = ''; if (count($product_var_tpl_list) > 0) { $product_list_txt = $this->getEmailTemplateContent('order_conf_product_list.txt', Mail::TYPE_TEXT, $product_var_tpl_list); $product_list_html = $this->getEmailTemplateContent('order_conf_product_list.tpl', Mail::TYPE_HTML, $product_var_tpl_list); } $cart_rules_list = array(); $total_reduction_value_ti = 0; $total_reduction_value_tex = 0; foreach ($cart_rules as $cart_rule) { $package = array('id_carrier' => $order->id_carrier, 'id_address' => $order->id_address_delivery, 'products' => $order->product_list); $values = array('tax_incl' => $cart_rule['obj']->getContextualValue(true, $this->context, CartRule::FILTER_ACTION_ALL_NOCAP, $package), 'tax_excl' => $cart_rule['obj']->getContextualValue(false, $this->context, CartRule::FILTER_ACTION_ALL_NOCAP, $package)); // If the reduction is not applicable to this order, then continue with the next one if (!$values['tax_excl']) { continue; } // IF // This is not multi-shipping // The value of the voucher is greater than the total of the order // Partial use is allowed // This is an "amount" reduction, not a reduction in % or a gift // THEN // The voucher is cloned with a new value corresponding to the remainder if (count($order_list) == 1 && $values['tax_incl'] > $order->total_products_wt - $total_reduction_value_ti && $cart_rule['obj']->partial_use == 1 && $cart_rule['obj']->reduction_amount > 0) { // Create a new voucher from the original $voucher = new CartRule($cart_rule['obj']->id); // We need to instantiate the CartRule without lang parameter to allow saving it unset($voucher->id); // Set a new voucher code $voucher->code = empty($voucher->code) ? Tools::substr(md5($order->id . '-' . $order->id_customer . '-' . $cart_rule['obj']->id), 0, 16) : $voucher->code . '-2'; if (preg_match('/\\-([0-9]{1,2})\\-([0-9]{1,2})$/', $voucher->code, $matches) && $matches[1] == $matches[2]) { $voucher->code = preg_replace('/' . $matches[0] . '$/', '-' . (int) ($matches[1] + 1), $voucher->code); } // Set the new voucher value if ($voucher->reduction_tax) { $voucher->reduction_amount = $total_reduction_value_ti + $values['tax_incl'] - $order->total_products_wt; // Add total shipping amout only if reduction amount > total shipping if ($voucher->free_shipping == 1 && $voucher->reduction_amount >= $order->total_shipping_tax_incl) { $voucher->reduction_amount -= $order->total_shipping_tax_incl; } } else { $voucher->reduction_amount = $total_reduction_value_tex + $values['tax_excl'] - $order->total_products; // Add total shipping amout only if reduction amount > total shipping if ($voucher->free_shipping == 1 && $voucher->reduction_amount >= $order->total_shipping_tax_excl) { $voucher->reduction_amount -= $order->total_shipping_tax_excl; } } if ($voucher->reduction_amount <= 0) { continue; } $voucher->id_customer = $order->id_customer; $voucher->quantity = 1; $voucher->quantity_per_user = 1; $voucher->free_shipping = 0; if ($voucher->add()) { // If the voucher has conditions, they are now copied to the new voucher CartRule::copyConditions($cart_rule['obj']->id, $voucher->id); $params = array('{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false), '{voucher_num}' => $voucher->code, '{firstname}' => $this->context->customer->firstname, '{lastname}' => $this->context->customer->lastname, '{id_order}' => $order->reference, '{order_name}' => $order->getUniqReference()); Mail::Send((int) $order->id_lang, 'voucher', sprintf(Mail::l('New voucher for your order %s', (int) $order->id_lang), $order->reference), $params, $this->context->customer->email, $this->context->customer->firstname . ' ' . $this->context->customer->lastname, null, null, null, null, _PS_MAIL_DIR_, false, (int) $order->id_shop); } $values['tax_incl'] = $order->total_products_wt - $total_reduction_value_ti; $values['tax_excl'] = $order->total_products - $total_reduction_value_tex; } $total_reduction_value_ti += $values['tax_incl']; $total_reduction_value_tex += $values['tax_excl']; $order->addCartRule($cart_rule['obj']->id, $cart_rule['obj']->name, $values, 0, $cart_rule['obj']->free_shipping); if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && !in_array($cart_rule['obj']->id, $cart_rule_used)) { $cart_rule_used[] = $cart_rule['obj']->id; // Create a new instance of Cart Rule without id_lang, in order to update its quantity $cart_rule_to_update = new CartRule($cart_rule['obj']->id); $cart_rule_to_update->quantity = max(0, $cart_rule_to_update->quantity - 1); $cart_rule_to_update->update(); } $cart_rules_list[] = array('voucher_name' => $cart_rule['obj']->name, 'voucher_reduction' => ($values['tax_incl'] != 0.0 ? '-' : '') . Tools::displayPrice($values['tax_incl'], $this->context->currency, false)); } $cart_rules_list_txt = ''; $cart_rules_list_html = ''; if (count($cart_rules_list) > 0) { $cart_rules_list_txt = $this->getEmailTemplateContent('order_conf_cart_rules.txt', Mail::TYPE_TEXT, $cart_rules_list); $cart_rules_list_html = $this->getEmailTemplateContent('order_conf_cart_rules.tpl', Mail::TYPE_HTML, $cart_rules_list); } // Specify order id for message $old_message = Message::getMessageByCartId((int) $this->context->cart->id); if ($old_message) { $update_message = new Message((int) $old_message['id_message']); $update_message->id_order = (int) $order->id; $update_message->update(); // Add this message in the customer thread $customer_thread = new CustomerThread(); $customer_thread->id_contact = 0; $customer_thread->id_customer = (int) $order->id_customer; $customer_thread->id_shop = (int) $this->context->shop->id; $customer_thread->id_order = (int) $order->id; $customer_thread->id_lang = (int) $this->context->language->id; $customer_thread->email = $this->context->customer->email; $customer_thread->status = 'open'; $customer_thread->token = Tools::passwdGen(12); $customer_thread->add(); $customer_message = new CustomerMessage(); $customer_message->id_customer_thread = $customer_thread->id; $customer_message->id_employee = 0; $customer_message->message = $update_message->message; $customer_message->private = 0; if (!$customer_message->add()) { $this->errors[] = Tools::displayError('An error occurred while saving message'); } } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Hook validateOrder is about to be called', 1, null, 'Cart', (int) $id_cart, true); } // Hook validate order Hook::exec('actionValidateOrder', array('cart' => $this->context->cart, 'order' => $order, 'customer' => $this->context->customer, 'currency' => $this->context->currency, 'orderStatus' => $order_status)); foreach ($this->context->cart->getProducts() as $product) { if ($order_status->logable) { ProductSale::addProductSale((int) $product['id_product'], (int) $product['cart_quantity']); } } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order Status is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Set the order status $new_history = new OrderHistory(); $new_history->id_order = (int) $order->id; $new_history->changeIdOrderState((int) $id_order_state, $order, true); $new_history->addWithemail(true, $extra_vars); // Switch to back order if needed if (Configuration::get('PS_STOCK_MANAGEMENT') && $order_detail->getStockState()) { $history = new OrderHistory(); $history->id_order = (int) $order->id; $history->changeIdOrderState(Configuration::get($order->valid ? 'PS_OS_OUTOFSTOCK_PAID' : 'PS_OS_OUTOFSTOCK_UNPAID'), $order, true); $history->addWithemail(); } unset($order_detail); // Order is reloaded because the status just changed $order = new Order($order->id); // Send an e-mail to customer (one order = one email) if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $this->context->customer->id) { $invoice = new Address($order->id_address_invoice); $delivery = new Address($order->id_address_delivery); $delivery_state = $delivery->id_state ? new State($delivery->id_state) : false; $invoice_state = $invoice->id_state ? new State($invoice->id_state) : false; $data = array('{firstname}' => $this->context->customer->firstname, '{lastname}' => $this->context->customer->lastname, '{email}' => $this->context->customer->email, '{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => $this->_getFormatedAddress($delivery, '<br />', array('firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="font-weight:bold;">%s</span>')), '{invoice_block_html}' => $this->_getFormatedAddress($invoice, '<br />', array('firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="font-weight:bold;">%s</span>')), '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_vat_number}' => $invoice->vat_number, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile, '{invoice_other}' => $invoice->other, '{order_name}' => $order->getUniqReference(), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), null, 1), '{carrier}' => $virtual_product || !isset($carrier->name) ? Tools::displayError('No carrier') : $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{products}' => $product_list_html, '{products_txt}' => $product_list_txt, '{discounts}' => $cart_rules_list_html, '{discounts_txt}' => $cart_rules_list_txt, '{total_paid}' => Tools::displayPrice($order->total_paid, $this->context->currency, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $this->context->currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $this->context->currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $this->context->currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $this->context->currency, false), '{total_tax_paid}' => Tools::displayPrice($order->total_products_wt - $order->total_products + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $this->context->currency, false)); if (is_array($extra_vars)) { $data = array_merge($data, $extra_vars); } // Join PDF invoice if ((int) Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number) { $pdf = new PDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE, $this->context->smarty); $file_attachement = array(); $file_attachement['content'] = $pdf->render(false); $file_attachement['name'] = Configuration::get('PS_INVOICE_PREFIX', (int) $order->id_lang, null, $order->id_shop) . sprintf('%06d', $order->invoice_number) . '.pdf'; $file_attachement['mime'] = 'application/pdf'; } else { $file_attachement = null; } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Mail is about to be sent', 1, null, 'Cart', (int) $id_cart, true); } if (Validate::isEmail($this->context->customer->email)) { Mail::Send((int) $order->id_lang, 'order_conf', Mail::l('Order confirmation', (int) $order->id_lang), $data, $this->context->customer->email, $this->context->customer->firstname . ' ' . $this->context->customer->lastname, null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int) $order->id_shop); } } // updates stock in shops if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $product_list = $order->getProducts(); foreach ($product_list as $product) { // if the available quantities depends on the physical stock if (StockAvailable::dependsOnStock($product['product_id'])) { // synchronizes StockAvailable::synchronize($product['product_id'], $order->id_shop); } } } } else { $error = Tools::displayError('Order creation failed'); PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', (int) $order->id_cart); die($error); } } // End foreach $order_detail_list // Update Order Details Tax in case cart rules have free shipping foreach ($order->getOrderDetailList() as $detail) { $order_detail = new OrderDetail($detail['id_order_detail']); $order_detail->updateTaxAmount($order); } // Use the last order as currentOrder if (isset($order) && $order->id) { $this->currentOrder = (int) $order->id; } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - End of validateOrder', 1, null, 'Cart', (int) $id_cart, true); } return true; } else { $error = Tools::displayError('Cart cannot be loaded or an order has already been placed using this cart'); PrestaShopLogger::addLog($error, 4, '0000001', 'Cart', (int) $this->context->cart->id); die($error); } }