function displayOrderStep($params) { global $smarty, $cart, $errors; $smarty->assign('errors', $errors); if (file_exists(_PS_SHIP_IMG_DIR_ . intval($cart->id_carrier) . '.jpg')) { $smarty->assign('carrierPicture', 1); } $cart->save(); // Hack to get loyalty and other modules happy $summary = $cart->getSummaryDetails(); $customizedDatas = Product::getAllCustomizedDatas(intval($cart->id)); Product::addCustomizationPrice($summary['products'], $customizedDatas); if ($free_ship = intval(Configuration::get('PS_SHIPPING_FREE_PRICE'))) { $discounts = $cart->getDiscounts(); $total_free_ship = $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']); foreach ($discounts as $discount) { if ($discount['id_discount_type'] == 3) { $total_free_ship = 0; break; } } $smarty->assign('free_ship', $total_free_ship); } $smarty->assign($summary); $token = Tools::getToken(false); $smarty->assign(array('token_cart' => $token, 'voucherAllowed' => Configuration::get('PS_VOUCHERS'), 'HOOK_SHOPPING_CART' => Module::hookExec('shoppingCart', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Module::hookExec('shoppingCartExtra', $summary), 'shippingCost' => $cart->getOrderTotalLC(true, 5), 'shippingCostTaxExc' => $cart->getOrderTotalLC(false, 5), 'customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'lastProductAdded' => $cart->getLastProduct())); Tools::safePostVars(); include_once dirname(__FILE__) . '/../../header.php'; echo $this->display(__FILE__, 'ordersummary.tpl'); }
public function renderView() { if (!($cart = $this->loadObject(true))) { return; } $customer = new Customer($cart->id_customer); $this->context->cart = $cart; $this->context->customer = $customer; $products = $cart->getProducts(); $customized_datas = Product::getAllCustomizedDatas((int) $cart->id); Product::addCustomizationPrice($products, $customized_datas); $summary = $cart->getSummaryDetails(); $currency = new Currency($cart->id_currency); /* Display order information */ $id_order = (int) Order::getOrderByCartId($cart->id); $order = new Order($id_order); if ($order->getTaxCalculationMethod() == PS_TAX_EXC) { $total_products = $summary['total_products']; $total_discounts = $summary['total_discounts_tax_exc']; $total_wrapping = $summary['total_wrapping_tax_exc']; $total_price = $summary['total_price_without_tax']; $total_shipping = $summary['total_shipping_tax_exc']; } else { $total_products = $summary['total_products_wt']; $total_discounts = $summary['total_discounts']; $total_wrapping = $summary['total_wrapping']; $total_price = $summary['total_price']; $total_shipping = $summary['total_shipping']; } foreach ($products as $k => &$product) { if ($order->getTaxCalculationMethod() == PS_TAX_EXC) { $product['product_price'] = $product['price']; $product['product_total'] = $product['total']; } else { $product['product_price'] = $product['price_wt']; $product['product_total'] = $product['total_wt']; } $image = array(); if (isset($product['id_product_attribute']) && (int) $product['id_product_attribute']) { $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $product['id_product_attribute']); } if (!isset($image['id_image'])) { $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $product['id_product'] . ' AND cover = 1'); } $product_obj = new Product($product['id_product']); $product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int) $order->id_shop); $image_product = new Image($image['id_image']); $product['image'] = isset($image['id_image']) ? ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $image_product->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['id_product'] . (isset($product['id_product_attribute']) ? '_' . (int) $product['id_product_attribute'] : '') . '.jpg', 45, 'jpg') : '--'; } $this->tpl_view_vars = array('products' => $products, 'discounts' => $cart->getCartRules(), 'order' => $order, 'cart' => $cart, 'currency' => $currency, 'customer' => $customer, 'customer_stats' => $customer->getStats(), 'total_products' => $total_products, 'total_discounts' => $total_discounts, 'total_wrapping' => $total_wrapping, 'total_price' => $total_price, 'total_shipping' => $total_shipping, 'customized_datas' => $customized_datas); return parent::renderView(); }
protected function _assignSummaryInformations() { $summary = $this->context->cart->getSummaryDetails(); $customizedDatas = Product::getAllCustomizedDatas($this->context->cart->id); // override customization tax rate with real tax (tax rules) if ($customizedDatas) { foreach ($summary['products'] as &$productUpdate) { $productId = (int) isset($productUpdate['id_product']) ? $productUpdate['id_product'] : $productUpdate['product_id']; $productAttributeId = (int) isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id']; if (isset($customizedDatas[$productId][$productAttributeId])) { $productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } } Product::addCustomizationPrice($summary['products'], $customizedDatas); } $cart_product_context = Context::getContext()->cloneContext(); foreach ($summary['products'] as $key => &$product) { $product['quantity'] = $product['cart_quantity']; // for compatibility with 1.2 themes if ($cart_product_context->shop->id != $product['id_shop']) { $cart_product_context->shop = new Shop((int) $product['id_shop']); } $product['price_without_specific_price'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], _PS_PRICE_COMPUTE_PRECISION_, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context); /** * ABU edit: variable is_discount set à 1 à tord, calcul foireux de presta * @bugfix: https://github.com/PrestaShop/PrestaShop/commit/379e28b341730ea95c0b2d6567817305ea841b23 * @perso: soustraction de l'ecotax au price_without_specific_price @else */ if (Product::getTaxCalculationMethod()) { // $product['is_discounted'] = $product['price_without_specific_price'] != Tools::ps_round($product['price'], _PS_PRICE_COMPUTE_PRECISION_); $product['is_discounted'] = Tools::ps_round($product['price_without_specific_price'], _PS_PRICE_COMPUTE_PRECISION_) != Tools::ps_round($product['price'], _PS_PRICE_COMPUTE_PRECISION_); } else { // $product['is_discounted'] = $product['price_without_specific_price'] != Tools::ps_round($product['price_wt'], _PS_PRICE_COMPUTE_PRECISION_); $product['is_discounted'] = Tools::ps_round($product['price_without_specific_price'] - $product['ecotax'], _PS_PRICE_COMPUTE_PRECISION_) != Tools::ps_round($product['price_wt'], _PS_PRICE_COMPUTE_PRECISION_); } } // Get available cart rules and unset the cart rules already in the cart $available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart); $cart_cart_rules = $this->context->cart->getCartRules(); foreach ($available_cart_rules as $key => $available_cart_rule) { if (!$available_cart_rule['highlight'] || strpos($available_cart_rule['code'], CartRule::BO_ORDER_CODE_PREFIX) === 0) { unset($available_cart_rules[$key]); continue; } foreach ($cart_cart_rules as $cart_cart_rule) { if ($available_cart_rule['id_cart_rule'] == $cart_cart_rule['id_cart_rule']) { unset($available_cart_rules[$key]); continue 2; } } } $show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && Configuration::get('PS_SHIP_WHEN_AVAILABLE'); $this->context->smarty->assign($summary); $this->context->smarty->assign(array('token_cart' => Tools::getToken(false), 'isLogged' => $this->isLogged, 'isVirtualCart' => $this->context->cart->isVirtualCart(), 'productNumber' => $this->context->cart->nbProducts(), 'voucherAllowed' => CartRule::isFeatureActive(), 'shippingCost' => $this->context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING), 'shippingCostTaxExc' => $this->context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING), 'customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'lastProductAdded' => $this->context->cart->getLastProduct(), 'displayVouchers' => $available_cart_rules, 'show_option_allow_separate_package' => $show_option_allow_separate_package, 'smallSize' => Image::getSize(ImageType::getFormatedName('small')))); $this->context->smarty->assign(array('HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary))); }
public function process() { parent::process(); if ($id_order = Tools::getValue('id_order') and $email = Tools::getValue('email')) { $order = new Order((int) $id_order); if (!Validate::isLoadedObject($order)) { $this->errors[] = Tools::displayError('Invalid order'); } elseif (!$order->isAssociatedAtGuest($email)) { $this->errors[] = Tools::displayError('Invalid order'); } else { $customer = new Customer((int) $order->id_customer); $id_order_state = (int) $order->getCurrentState(); $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang); $addressInvoice = new Address((int) $order->id_address_invoice); $addressDelivery = new Address((int) $order->id_address_delivery); $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country); $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country); $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields); $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields); if ($order->total_discounts > 0) { self::$smarty->assign('total_old', (double) ($order->total_paid - $order->total_discounts)); } $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); $this->processAddressFormat($addressDelivery, $addressInvoice); self::$smarty->assign(array('shop_name' => Configuration::get('PS_SHOP_NAME'), 'order' => $order, 'return_allowed' => false, 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable((int) $id_order_state) and $order->invoice_number, 'order_history' => $order->getHistory((int) self::$cookie->id_lang, false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) ? new State((int) $addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) ? new State((int) $addressDelivery->id_state) : false, 'is_guest' => true, 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'use_tax' => Configuration::get('PS_TAX'), 'customizedDatas' => $customizedDatas, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues)); if ($carrier->url and $order->shipping_number) { self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); } self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order))); Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order)); if (Tools::isSubmit('submitTransformGuestToCustomer')) { $customer = new Customer((int) $order->id_customer); if (!Validate::isLoadedObject($customer)) { $this->errors[] = Tools::displayError('Invalid customer'); } if (!$customer->transformToCustomer(self::$cookie->id_lang, Tools::getValue('password'))) { $this->errors[] = Tools::displayError('An error occurred while transforming guest to customer.'); } if (!Tools::getValue('password')) { $this->errors[] = Tools::displayError('Invalid password'); } else { self::$smarty->assign('transformSuccess', true); } } } if (sizeof($this->errors)) { /* Handle brute force attacks */ sleep(1); } } self::$smarty->assign(array('action' => 'guest-tracking.php', 'errors' => $this->errors)); }
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 preProcess() { parent::preProcess(); if (Tools::isSubmit('submitMessage')) { $idOrder = (int) Tools::getValue('id_order'); $msgText = htmlentities(Tools::getValue('msgText'), ENT_COMPAT, 'UTF-8'); if (!$idOrder or !Validate::isUnsignedId($idOrder)) { $this->errors[] = Tools::displayError('Order is no longer valid'); } elseif (empty($msgText)) { $this->errors[] = Tools::displayError('Message cannot be blank'); } elseif (!Validate::isMessage($msgText)) { $this->errors[] = Tools::displayError('Message is invalid (HTML is not allowed)'); } if (!sizeof($this->errors)) { $order = new Order((int) $idOrder); if (Validate::isLoadedObject($order) and $order->id_customer == self::$cookie->id_customer) { $message = new Message(); $message->id_customer = (int) self::$cookie->id_customer; $message->message = $msgText; $message->id_order = (int) $idOrder; $message->private = false; $message->add(); if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE')) { $to = strval(Configuration::get('PS_SHOP_EMAIL')); } else { $to = new Contact((int) Configuration::get('PS_MAIL_EMAIL_MESSAGE')); $to = strval($to->email); } $toName = strval(Configuration::get('PS_SHOP_NAME')); $customer = new Customer((int) self::$cookie->id_customer); if (Validate::isLoadedObject($customer)) { Mail::Send((int) self::$cookie->id_lang, 'order_customer_comment', Mail::l('Message from a customer', (int) self::$cookie->id_lang), array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{email}' => $customer->email, '{id_order}' => (int) $message->id_order, '{order_name}' => sprintf("#%06d", (int) $message->id_order), '{message}' => $message->message), $to, $toName, $customer->email, $customer->firstname . ' ' . $customer->lastname); } if (Tools::getValue('ajax') != 'true') { Tools::redirect('order-detail.php?id_order=' . (int) $idOrder); } } else { $this->errors[] = Tools::displayError('Order not found'); } } } if (!($id_order = (int) Tools::getValue('id_order')) or !Validate::isUnsignedId($id_order)) { $this->errors[] = Tools::displayError('Order ID required'); } else { $order = new Order($id_order); if (Validate::isLoadedObject($order) and $order->id_customer == self::$cookie->id_customer) { $id_order_state = (int) $order->getCurrentState(); $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang); $addressInvoice = new Address((int) $order->id_address_invoice); $addressDelivery = new Address((int) $order->id_address_delivery); // $stateInvoiceAddress = new State((int)$addressInvoice->id_state); $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country); $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country); $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields); $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields); if ($order->total_discounts > 0) { self::$smarty->assign('total_old', (double) ($order->total_paid - $order->total_discounts)); } $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); $customer = new Customer($order->id_customer); self::$smarty->assign(array('shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int) $order->isReturnable(), 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable((int) $id_order_state) and $order->invoice_number, 'order_history' => $order->getHistory((int) self::$cookie->id_lang, false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) ? new State((int) $addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) ? new State((int) $addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => Message::getMessagesByOrderId((int) $order->id), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'customizedDatas' => $customizedDatas)); if ($carrier->url and $order->shipping_number) { self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); } self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order))); Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order)); unset($carrier); unset($addressInvoice); unset($addressDelivery); } else { $this->errors[] = Tools::displayError('Cannot find this order'); } unset($order); } }
/** * Get order products * * @return array Products with price, quantity (with taxe and without) */ public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) { $products = $this->getProductsDetail(); } $order = new Order($this->id_order); $customized_datas = Product::getAllCustomizedDatas($order->id_cart); $resultArray = array(); foreach ($products as $row) { // Change qty if selected if ($selectedQty) { $row['product_quantity'] = 0; foreach ($selectedProducts as $key => $id_product) { if ($row['id_order_detail'] == $id_product) { $row['product_quantity'] = (int) $selectedQty[$key]; } } if (!$row['product_quantity']) { continue; } } $this->setProductImageInformations($row); $this->setProductCurrentStock($row); $this->setProductCustomizedDatas($row, $customized_datas); // Add information for virtual product if ($row['download_hash'] && !empty($row['download_hash'])) { $row['filename'] = ProductDownload::getFilenameFromIdProduct((int) $row['product_id']); // Get the display filename $row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']); } $row['id_address_delivery'] = $order->id_address_delivery; /* Translit product name */ //$row['translit_name'] = $this->translit($row['product_name'])."222"; if ($row['translit_name'] == "Война и мир") { $row['translit_name'] = "это война и мир"; } else { $row['translit_name'] = "это что-то другое"; } /* Stock product */ $resultArray[(int) $row['id_order_detail']] = $row; } if ($customized_datas) { Product::addCustomizationPrice($resultArray, $customized_datas); } return $resultArray; }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if (!($id_order = (int) Tools::getValue('id_order')) || !Validate::isUnsignedId($id_order)) { $this->errors[] = Tools::displayError('Order ID required'); } else { $order = new Order($id_order); if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) { $id_order_state = (int) $order->getCurrentState(); $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang); $addressInvoice = new Address((int) $order->id_address_invoice); $addressDelivery = new Address((int) $order->id_address_delivery); $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country); $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country); $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields); $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields); if ($order->total_discounts > 0) { $this->context->smarty->assign('total_old', (double) $order->total_paid - $order->total_discounts); } $products = $order->getProducts(); /* DEPRECATED: customizedDatas @since 1.5 */ $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); OrderReturn::addReturnedQuantity($products, $order->id); $order_status = new OrderState((int) $id_order_state, (int) $order->id_lang); $customer = new Customer($order->id_customer); //by webkul to show order details properly on order history page if (Module::isInstalled('hotelreservationsystem')) { require_once _PS_MODULE_DIR_ . 'hotelreservationsystem/define.php'; $obj_cart_bk_data = new HotelCartBookingData(); $obj_htl_bk_dtl = new HotelBookingDetail(); $obj_rm_type = new HotelRoomType(); if (!empty($products)) { foreach ($products as $type_key => $type_value) { $product = new Product($type_value['product_id'], false, $this->context->language->id); $cover_image_arr = $product->getCover($type_value['product_id']); if (!empty($cover_image_arr)) { $cover_img = $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $cover_image_arr['id_image'], 'small_default'); } else { $cover_img = $this->context->link->getImageLink($product->link_rewrite, $this->context->language->iso_code . "-default", 'small_default'); } $unit_price = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1); if (isset($customer->id)) { $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($order->id_cart, (new Cart($order->id_cart))->id_guest, $type_value['product_id'], $customer->id); } else { $cart_bk_data = $obj_cart_bk_data->getOnlyCartBookingData($order->id_cart, $customer->id_guest, $type_value['product_id']); } $rm_dtl = $obj_rm_type->getRoomTypeInfoByIdProduct($type_value['product_id']); $cart_htl_data[$type_key]['id_product'] = $type_value['product_id']; $cart_htl_data[$type_key]['cover_img'] = $cover_img; $cart_htl_data[$type_key]['name'] = $product->name; $cart_htl_data[$type_key]['unit_price'] = $unit_price; $cart_htl_data[$type_key]['adult'] = $rm_dtl['adult']; $cart_htl_data[$type_key]['children'] = $rm_dtl['children']; foreach ($cart_bk_data as $data_k => $data_v) { $date_join = strtotime($data_v['date_from']) . strtotime($data_v['date_to']); if (isset($cart_htl_data[$type_key]['date_diff'][$date_join])) { $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] += 1; $num_days = $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days']; $vart_quant = (int) $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] * $num_days; $amount = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1); $amount *= $vart_quant; $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount; } else { $num_days = $obj_htl_bk_dtl->getNumberOfDays($data_v['date_from'], $data_v['date_to']); $cart_htl_data[$type_key]['date_diff'][$date_join]['num_rm'] = 1; $cart_htl_data[$type_key]['date_diff'][$date_join]['data_form'] = $data_v['date_from']; $cart_htl_data[$type_key]['date_diff'][$date_join]['data_to'] = $data_v['date_to']; $cart_htl_data[$type_key]['date_diff'][$date_join]['num_days'] = $num_days; $amount = Product::getPriceStatic($type_value['product_id'], true, null, 6, null, false, true, 1); $amount *= $num_days; $cart_htl_data[$type_key]['date_diff'][$date_join]['amount'] = $amount; } } } $this->context->smarty->assign('cart_htl_data', $cart_htl_data); } } //end $this->context->smarty->assign(array('shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int) $order->isReturnable(), 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable($id_order_state) && count($order->getInvoicesCollection()), 'logable' => (bool) $order_status->logable, 'order_history' => $order->getHistory($this->context->language->id, false, true), 'products' => $products, 'discounts' => $order->getCartRules(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state ? new State($addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state ? new State($addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => CustomerMessage::getMessagesByOrderId((int) $order->id, false), 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'customizedDatas' => $customizedDatas, 'reorderingAllowed' => !(bool) Configuration::get('PS_DISALLOW_HISTORY_REORDERING'))); if ($carrier->url && $order->shipping_number) { $this->context->smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); } $this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Hook::exec('displayOrderDetail', array('order' => $order))); Hook::exec('actionOrderDetail', array('carrier' => $carrier, 'order' => $order)); unset($carrier, $addressInvoice, $addressDelivery); } else { $this->errors[] = Tools::displayError('This order cannot be found.'); } unset($order); } $this->setTemplate(_PS_THEME_DIR_ . 'order-detail.tpl'); }
public function hookActionValidateOrder($params) { if (!$this->merchant_order || empty($this->merchant_mails)) { return; } // Getting differents vars $context = Context::getContext(); $id_lang = (int) $context->language->id; $id_shop = (int) $context->shop->id; $currency = $params['currency']; $order = $params['order']; $customer = $params['customer']; $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); $delivery = new Address((int) $order->id_address_delivery); $invoice = new Address((int) $order->id_address_invoice); $order_date_text = Tools::displayDate($order->date_add); $carrier = new Carrier((int) $order->id_carrier); $message = $this->getAllMessages($order->id); if (!$message || empty($message)) { $message = $this->l('No message'); } $items_table = ''; $products = $params['order']->getProducts(); $customized_datas = Product::getAllCustomizedDatas((int) $params['cart']->id); Product::addCustomizationPrice($products, $customized_datas); foreach ($products as $key => $product) { $unit_price = Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC ? $product['product_price'] : $product['product_price_wt']; $customization_text = ''; if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']])) { foreach ($customized_datas[$product['product_id']][$product['product_attribute_id']][$order->id_address_delivery] as $customization) { 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 .= count($customization['datas'][Product::CUSTOMIZE_FILE]) . ' ' . $this->l('image(s)') . '<br />'; } $customization_text .= '---<br />'; } if (method_exists('Tools', 'rtrimString')) { $customization_text = Tools::rtrimString($customization_text, '---<br />'); } else { $customization_text = preg_replace('/---<br \\/>$/', '', $customization_text); } } $items_table .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding:0.6em 0.4em;">' . $product['product_reference'] . '</td> <td style="padding:0.6em 0.4em;"> <strong>' . $product['product_name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . (!empty($customization_text) ? '<br />' . $customization_text : '') . '</strong> </td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($unit_price, $currency, false) . '</td> <td style="padding:0.6em 0.4em; text-align:center;">' . (int) $product['product_quantity'] . '</td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($unit_price * $product['product_quantity'], $currency, false) . '</td> </tr>'; } foreach ($params['order']->getCartRules() as $discount) { $items_table .= '<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'], $currency, false) . '</td> </tr>'; } if ($delivery->id_state) { $delivery_state = new State((int) $delivery->id_state); } if ($invoice->id_state) { $invoice_state = new State((int) $invoice->id_state); } if (Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC) { $total_products = $order->getTotalProductsWithoutTaxes(); } else { $total_products = $order->getTotalProductsWithTaxes(); } // Filling-in vars for email $template_vars = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => MailAlert::getFormatedAddress($delivery, '<br />', array('firstname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>')), '{invoice_block_html}' => MailAlert::getFormatedAddress($invoice, '<br />', array('firstname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; 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_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->reference, '{shop_name}' => $configuration['PS_SHOP_NAME'], '{date}' => $order_date_text, '{carrier}' => $carrier->name == '0' ? $configuration['PS_SHOP_NAME'] : $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{items}' => $items_table, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency), '{total_products}' => Tools::displayPrice($total_products, $currency), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency), '{total_tax_paid}' => Tools::displayPrice($order->total_products_wt - $order->total_products + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency), '{currency}' => $currency->sign, '{message}' => $message); // Shop iso $iso = Language::getIsoById((int) Configuration::get('PS_LANG_DEFAULT')); // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails); foreach ($merchant_mails as $merchant_mail) { // Default language $mail_id_lang = $id_lang; $mail_iso = $iso; // Use the merchant lang if he exists as an employee $results = Db::getInstance()->executeS(' SELECT `id_lang` FROM `' . _DB_PREFIX_ . 'employee` WHERE `email` = \'' . pSQL($merchant_mail) . '\' '); if ($results) { $user_iso = Language::getIsoById((int) $results[0]['id_lang']); if ($user_iso) { $mail_id_lang = (int) $results[0]['id_lang']; $mail_iso = $user_iso; } } $dir_mail = false; if (file_exists(dirname(__FILE__) . '/mails/' . $mail_iso . '/new_order.txt') && file_exists(dirname(__FILE__) . '/mails/' . $mail_iso . '/new_order.html')) { $dir_mail = dirname(__FILE__) . '/mails/'; } if (file_exists(_PS_MAIL_DIR_ . $mail_iso . '/new_order.txt') && file_exists(_PS_MAIL_DIR_ . $mail_iso . '/new_order.html')) { $dir_mail = _PS_MAIL_DIR_; } if ($dir_mail) { Mail::Send($mail_id_lang, 'new_order', sprintf(Mail::l('New order : #%d - %s', $mail_id_lang), $order->id, $order->reference), $template_vars, $merchant_mail, null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, $dir_mail, null, $id_shop); } } }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if (!($id_order = (int) Tools::getValue('id_order')) || !Validate::isUnsignedId($id_order)) { $this->errors[] = Tools::displayError('Order ID required'); } else { $order = new Order($id_order); if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) { $id_order_state = (int) $order->getCurrentState(); $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang); $addressInvoice = new Address((int) $order->id_address_invoice); $addressDelivery = new Address((int) $order->id_address_delivery); $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country); $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country); $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields); $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields); if ($order->total_discounts > 0) { $this->context->smarty->assign('total_old', (double) ($order->total_paid - $order->total_discounts)); } $products = $order->getProducts(); /* DEPRECATED: customizedDatas @since 1.5 */ $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); OrderReturn::addReturnedQuantity($products, $order->id); $customer = new Customer($order->id_customer); $this->context->smarty->assign(array('shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int) $order->isReturnable(), 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable($id_order_state) && count($order->getInvoicesCollection()), 'order_history' => $order->getHistory($this->context->language->id, false, true), 'products' => $products, 'discounts' => $order->getCartRules(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state ? new State($addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state ? new State($addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => CustomerMessage::getMessagesByOrderId((int) $order->id, false), 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'customizedDatas' => $customizedDatas)); if ($carrier->url && $order->shipping_number) { $this->context->smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); } $this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Hook::exec('displayOrderDetail', array('order' => $order))); Hook::exec('actionOrderDetail', array('carrier' => $carrier, 'order' => $order)); unset($carrier, $addressInvoice, $addressDelivery); } else { $this->errors[] = Tools::displayError('This order cannot be found.'); } unset($order); } $this->setTemplate(_PS_THEME_DIR_ . 'order-detail.tpl'); }
/** * Display ajax content (this function is called instead of classic display, in ajax mode) */ public function displayAjax() { if ($this->errors) { $this->ajaxDie(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors))); } if ($this->ajax_refresh) { $this->ajaxDie(Tools::jsonEncode(array('refresh' => true))); } // write cookie if can't on destruct $this->context->cookie->write(); if (Tools::getIsset('summary')) { $result = array(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { $groups = Validate::isLoadedObject($this->context->customer) ? $this->context->customer->getGroups() : array(1); if ($this->context->cart->id_address_delivery) { $deliveryAddress = new Address($this->context->cart->id_address_delivery); } $id_country = isset($deliveryAddress) && $deliveryAddress->id ? (int) $deliveryAddress->id_country : (int) Tools::getCountry(); Cart::addExtraCarriers($result); } $result['summary'] = $this->context->cart->getSummaryDetails(null, true); $result['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true); $result['HOOK_SHOPPING_CART'] = Hook::exec('displayShoppingCartFooter', $result['summary']); $result['HOOK_SHOPPING_CART_EXTRA'] = Hook::exec('displayShoppingCart', $result['summary']); foreach ($result['summary']['products'] as $key => &$product) { $product['quantity_without_customization'] = $product['quantity']; if ($result['customizedDatas'] && isset($result['customizedDatas'][(int) $product['id_product']][(int) $product['id_product_attribute']])) { foreach ($result['customizedDatas'][(int) $product['id_product']][(int) $product['id_product_attribute']] as $addresses) { foreach ($addresses as $customization) { $product['quantity_without_customization'] -= (int) $customization['quantity']; } } } } if ($result['customizedDatas']) { Product::addCustomizationPrice($result['summary']['products'], $result['customizedDatas']); } $json = ''; Hook::exec('actionCartListOverride', array('summary' => $result, 'json' => &$json)); $this->ajaxDie(Tools::jsonEncode(array_merge($result, (array) Tools::jsonDecode($json, true)))); } elseif (file_exists(_PS_MODULE_DIR_ . '/blockcart/blockcart-ajax.php')) { require_once _PS_MODULE_DIR_ . '/blockcart/blockcart-ajax.php'; } }
public function hookNewOrder($params) { if (!$this->_merchant_order or empty($this->_merchant_mails)) { return; } // Getting differents vars $id_lang = (int) 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((int) $order->id_address_delivery); $invoice = new Address((int) $order->id_address_invoice); $order_date_text = Tools::displayDate($order->date_add, (int) $id_lang); $carrier = new Carrier((int) $order->id_carrier); $message = $order->getFirstMessage(); if (!$message or empty($message)) { $message = $this->l('No message'); } $itemsTable = ''; $customizedDatas = Product::getAllCustomizedDatas(intval($params['cart']->id)); Product::addCustomizationPrice($products, $customizedDatas); foreach ($params['order']->getProducts() as $key => $product) { $unit_price = $product['product_price_wt']; $price = $product['total_price']; $customizationText = ''; if (isset($customizedDatas[$product['product_id']][$product['product_attribute_id']])) { foreach ($customizedDatas[$product['product_id']][$product['product_attribute_id']] as $customization) { if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) { foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text) { $customizationText .= $text['name'] . ':' . ' ' . $text['value'] . '<br />'; } } if (isset($customization['datas'][_CUSTOMIZE_FILE_])) { $customizationText .= sizeof($customization['datas'][_CUSTOMIZE_FILE_]) . ' ' . Tools::displayError('image(s)') . '<br />'; } $customizationText .= '---<br />'; } $customizationText = rtrim($customizationText, '---<br />'); } $itemsTable .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding:0.6em 0.4em;">' . $product['product_reference'] . '</td> <td style="padding:0.6em 0.4em;"><strong>' . $product['product_name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . (!empty($customizationText) ? '<br />' . $customizationText : '') . '</strong></td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($unit_price, $currency, false) . '</td> <td style="padding:0.6em 0.4em; text-align:center;">' . (int) $product['product_quantity'] . '</td> <td style="padding:0.6em 0.4em; text-align:right;">' . Tools::displayPrice($unit_price * $product['product_quantity'], $currency, false) . '</td> </tr>'; } foreach ($params['order']->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'], $currency, false) . '</td> </tr>'; } if ($delivery->id_state) { $delivery_state = new State((int) $delivery->id_state); } if ($invoice->id_state) { $invoice_state = new State((int) $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}' => Tools::substr($order->payment, 0, 32), '{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((int) $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/'); } }
protected function _assignSummaryInformations() { global $currency; if (file_exists(_PS_SHIP_IMG_DIR_ . (int) self::$cart->id_carrier . '.jpg')) { self::$smarty->assign('carrierPicture', 1); } $summary = self::$cart->getSummaryDetails(); $customizedDatas = Product::getAllCustomizedDatas((int) self::$cart->id); Product::addCustomizationPrice($summary['products'], $customizedDatas); if ($free_ship = Tools::convertPrice((double) Configuration::get('PS_SHIPPING_FREE_PRICE'), new Currency((int) self::$cart->id_currency))) { $discounts = self::$cart->getDiscounts(); $total_free_ship = $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']); foreach ($discounts as $discount) { if ($discount['id_discount_type'] == 3) { $total_free_ship = 0; break; } } self::$smarty->assign('free_ship', $total_free_ship); } // for compatibility with 1.2 themes foreach ($summary['products'] as $key => $product) { $summary['products'][$key]['quantity'] = $product['cart_quantity']; } self::$smarty->assign($summary); self::$smarty->assign(array('token_cart' => Tools::getToken(false), 'isVirtualCart' => self::$cart->isVirtualCart(), 'productNumber' => self::$cart->nbProducts(), 'voucherAllowed' => Configuration::get('PS_VOUCHERS'), 'shippingCost' => self::$cart->getOrderTotal(true, Cart::ONLY_SHIPPING), 'shippingCostTaxExc' => self::$cart->getOrderTotal(false, Cart::ONLY_SHIPPING), 'customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'lastProductAdded' => self::$cart->getLastProduct(), 'displayVouchers' => Discount::getVouchersToCartDisplay((int) self::$cookie->id_lang, isset(self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0), 'currencySign' => $currency->sign, 'currencyRate' => $currency->conversion_rate, 'currencyFormat' => $currency->format, 'currencyBlank' => $currency->blank)); self::$smarty->assign(array('HOOK_SHOPPING_CART' => Module::hookExec('shoppingCart', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Module::hookExec('shoppingCartExtra', $summary))); }
/** * Product table with price, quantities... */ public function ProdTab($delivery = false) { global $ecotax; if (!$delivery) { $w = array(100, 15, 30, 15, 30); } else { $w = array(120, 30, 10); } self::ProdTabHeader($delivery); if (isset(self::$order->products) and sizeof(self::$order->products)) { $products = self::$order->products; } else { $products = self::$order->getProducts(); } $ecotax = 0; $customizedDatas = Product::getAllCustomizedDatas(intval(self::$order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); $counter = 0; $lines = 25; $lineSize = 0; $line = 0; $isInPreparation = self::$order->isInPreparation(); foreach ($products as $product) { if (!$delivery or intval($product['product_quantity']) - intval($product['product_quantity_refunded']) > 0) { if ($counter >= $lines) { $this->AddPage(); $this->Ln(); self::ProdTabHeader($delivery); $lineSize = 0; $counter = 0; $lines = 40; $line++; } $counter = $counter + $lineSize / 5; $i = -1; $ecotax += $product['ecotax'] * intval($product['product_quantity']); // Unit vars $unit_without_tax = $product['product_price']; $unit_with_tax = $product['product_price_wt']; if (self::$_priceDisplayMethod == PS_TAX_EXC) { $unit_price =& $unit_without_tax; } else { $unit_price =& $unit_with_tax; } $productQuantity = $delivery ? intval($product['product_quantity']) - intval($product['product_quantity_refunded']) : intval($product['product_quantity']); if ($productQuantity <= 0) { continue; } // Total prices $total_with_tax = $unit_with_tax * $productQuantity; $total_without_tax = $unit_without_tax * $productQuantity; // Spec if (self::$_priceDisplayMethod == PS_TAX_EXC) { $final_price =& $total_without_tax; } else { $final_price =& $total_with_tax; } // End Spec if (isset($customizedDatas[$product['product_id']][$product['product_attribute_id']])) { $productQuantity = intval($product['product_quantity']) - intval($product['customizationQuantityTotal']); if ($delivery) { $this->SetX(25); } $before = $this->GetY(); $this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']) . ' - ' . self::l('Customized'), 'B'); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX() + $w[0] + ($delivery ? 15 : 0), $this->GetY() - $lineSize); $this->Cell($w[++$i], $lineSize, $product['product_reference'], 'B'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($unit_price, self::$currency, true, false)), 'B', 0, 'R'); } $this->Cell($w[++$i], $lineSize, intval($product['customizationQuantityTotal']), 'B', 0, 'C'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($unit_price * intval($product['customizationQuantityTotal']), self::$currency, true, false)), 'B', 0, 'R'); } $this->Ln(); $i = -1; $total_with_tax = $unit_with_tax * $productQuantity; $total_without_tax = $unit_without_tax * $productQuantity; } if ($delivery) { $this->SetX(25); } if ($productQuantity) { $before = $this->GetY(); $this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'B'); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX() + $w[0] + ($delivery ? 15 : 0), $this->GetY() - $lineSize); $this->Cell($w[++$i], $lineSize, $product['product_reference'] ? $product['product_reference'] : '--', 'B'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($unit_price, self::$currency, true, false)), 'B', 0, 'R'); } $this->Cell($w[++$i], $lineSize, $productQuantity, 'B', 0, 'C'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($final_price, self::$currency, true, false)), 'B', 0, 'R'); } $this->Ln(); } } } if (!sizeof(self::$order->getDiscounts()) and !$delivery) { $this->Cell(array_sum($w), 0, ''); } }
/** * Validate an order in database * Function called from a payment module * * @param integer $id_cart Value * @param integer $id_order_state Value * @param float $amountPaid Amount really paid by customer (in the default currency) * @param string $paymentMethod Payment method (eg. 'Credit cart') * @param string $message Message to attach to order */ function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false) { global $cart; $cart = new Cart(intval($id_cart)); // Does order already exists ? if (Validate::isLoadedObject($cart) and $cart->OrderExists() === 0) { // Copying data from cart $order = new Order(); $order->id_carrier = intval($cart->id_carrier); $order->id_customer = intval($cart->id_customer); $order->id_address_invoice = intval($cart->id_address_invoice); $order->id_address_delivery = intval($cart->id_address_delivery); $vat_address = new Address(intval($order->id_address_delivery)); $id_zone = Address::getZoneById(intval($vat_address->id)); $order->id_currency = $currency_special ? intval($currency_special) : intval($cart->id_currency); $order->id_lang = intval($cart->id_lang); $order->id_cart = intval($cart->id); $customer = new Customer(intval($order->id_customer)); $order->secure_key = pSQL($customer->secure_key); $order->payment = Tools::substr($paymentMethod, 0, 32); if (isset($this->name)) { $order->module = $this->name; } $order->recyclable = $cart->recyclable; $order->gift = intval($cart->gift); $order->gift_message = $cart->gift_message; $currency = new Currency($order->id_currency); $amountPaid = !$dont_touch_amount ? Tools::ps_round(floatval($amountPaid), 2) : $amountPaid; $order->total_paid_real = $amountPaid; $order->total_products = floatval($cart->getOrderTotal(false, 1)); $order->total_products_wt = floatval($cart->getOrderTotal(true, 1)); $order->total_discounts = floatval(abs($cart->getOrderTotal(true, 2))); $order->total_shipping = floatval($cart->getOrderShippingCost()); $order->total_wrapping = floatval(abs($cart->getOrderTotal(true, 6))); $order->total_paid = floatval(Tools::ps_round(floatval($cart->getOrderTotal(true, 3)), 2)); $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; // Amount paid by customer is not the right one -> Status = payment error if ($order->total_paid != $order->total_paid_real) { $id_order_state = _PS_OS_ERROR_; } // Creating order if ($cart->OrderExists() === 0) { $result = $order->add(); } else { die(Tools::displayError('An order has already been placed using this cart')); } // Next ! if ($result and isset($order->id)) { // Optional message to attach to this order if (isset($message) and !empty($message)) { $msg = new Message(); $message = strip_tags($message, '<br>'); if (!Validate::isCleanHtml($message)) { $message = $this->l('Payment message is not valid, please check your module!'); } $msg->message = $message; $msg->id_order = intval($order->id); $msg->private = 1; $msg->add(); } // Insert products from cart into order_detail table $products = $cart->getProducts(); $productsList = ''; $db = Db::getInstance(); $query = 'INSERT INTO `' . _DB_PREFIX_ . 'order_detail` (`id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`, `reduction_percent`, `reduction_amount`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `discount_quantity_applied`, `download_deadline`, `download_hash`) VALUES '; $customizedDatas = Product::getAllCustomizedDatas(intval($order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); foreach ($products as $key => $product) { $outOfStock = false; $productQuantity = intval(Product::getQuantity(intval($product['id_product']), $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL)); $quantityInStock = $productQuantity - intval($product['cart_quantity']) < 0 ? $productQuantity : intval($product['cart_quantity']); if ($id_order_state != _PS_OS_CANCELED_ and $id_order_state != _PS_OS_ERROR_) { if (($updateResult = Product::updateQuantity($product)) === false or $updateResult === -1) { $outOfStock = true; } if (!$outOfStock) { $product['stock_quantity'] -= $product['cart_quantity']; } Hook::updateQuantity($product, $order); } $price = Product::getPriceStatic(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 6, NULL, false, true, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery)); $price_wt = Product::getPriceStatic(intval($product['id_product']), true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 2, NULL, false, true, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery)); // Add some informations for virtual products $deadline = '0000-00-00 00:00:00'; $download_hash = NULL; if ($id_product_download = ProductDownload::getIdFromIdProduct(intval($product['id_product']))) { $productDownload = new ProductDownload(intval($id_product_download)); $deadline = $productDownload->getDeadLine(); $download_hash = $productDownload->getHash(); } // Exclude VAT if (Tax::excludeTaxeOption()) { $product['tax'] = 0; $product['rate'] = 0; $tax = 0; } else { $tax = Tax::getApplicableTax(intval($product['id_tax']), floatval($product['rate']), intval($order->id_address_delivery)); } $currentDate = date('Y-m-d H:m:i'); if ($product['reduction_from'] != $product['reduction_to'] and ($currentDate > $product['reduction_to'] or $currentDate < $product['reduction_from'])) { $reduction_percent = 0.0; $reduction_amount = 0.0; } else { $reduction_percent = floatval($product['reduction_percent']); $reduction_amount = Tools::ps_round(floatval($product['reduction_price']) / (1 + floatval($tax) / 100), 6); } // Quantity discount $reduc = 0.0; if ($product['cart_quantity'] > 1 and $qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $product['cart_quantity'])) { $reduc = QuantityDiscount::getValue($price_wt, $qtyD->id_discount_type, $qtyD->value, new Currency(intval($order->id_currency))); } $query .= '(' . intval($order->id) . ', ' . intval($product['id_product']) . ', ' . (isset($product['id_product_attribute']) ? intval($product['id_product_attribute']) : 'NULL') . ', \'' . pSQL($product['name'] . ((isset($product['attributes']) and $product['attributes'] != NULL) ? ' - ' . $product['attributes'] : '')) . '\', ' . intval($product['cart_quantity']) . ', ' . $quantityInStock . ', ' . floatval(Product::getPriceStatic(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, Product::getTaxCalculationMethod(intval($order->id_customer)) == PS_TAX_EXC ? 2 : 6, NULL, false, false, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery))) . ', ' . floatval($reduction_percent) . ', ' . floatval($reduction_amount) . ', ' . floatval($reduc) . ', ' . (empty($product['ean13']) ? 'NULL' : '\'' . pSQL($product['ean13']) . '\'') . ', ' . (empty($product['reference']) ? 'NULL' : '\'' . pSQL($product['reference']) . '\'') . ', ' . (empty($product['supplier_reference']) ? 'NULL' : '\'' . pSQL($product['supplier_reference']) . '\'') . ', ' . floatval($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']) . ', \'' . (!$tax ? '' : pSQL($product['tax'])) . '\', ' . floatval($tax) . ', ' . floatval($product['ecotax']) . ', ' . (int) QuantityDiscount::getDiscountFromQuantity(intval($product['id_product']), intval($product['cart_quantity'])) . ', \'' . pSQL($deadline) . '\', \'' . pSQL($download_hash) . '\'),'; $priceWithTax = number_format($price * (($tax + 100) / 100), 2, '.', ''); $customizationQuantity = 0; if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) { $customizationText = ''; foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] as $customization) { if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) { foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text) { $customizationText .= $text['name'] . $this->l(':') . ' ' . $text['value'] . ', '; } } } $customizationText = rtrim($customizationText, ', '); $customizationQuantity = intval($product['customizationQuantityTotal']); $productsList .= '<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'] : '') . ' - ' . $this->l('Customized') . (!empty($customizationText) ? ' - ' . $customizationText : '') . '</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false, false) . '</td> <td style="padding: 0.6em 0.4em; text-align: center;">' . $customizationQuantity . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false, false) . '</td> </tr>'; } if (!$customizationQuantity or intval($product['cart_quantity']) > $customizationQuantity) { $productsList .= '<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(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false, false) . '</td> <td style="padding: 0.6em 0.4em; text-align: center;">' . (intval($product['cart_quantity']) - $customizationQuantity) . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice((intval($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false, false) . '</td> </tr>'; } } // end foreach ($products) $query = rtrim($query, ','); $result = $db->Execute($query); // Insert discounts from cart into order_discount table $discounts = $cart->getDiscounts(); $discountsList = ''; foreach ($discounts as $discount) { $objDiscount = new Discount(intval($discount['id_discount'])); $value = $objDiscount->getValue(sizeof($discounts), $cart->getOrderTotal(true, 1), $order->total_shipping, $cart->id); $order->addDiscount($objDiscount->id, $objDiscount->name, $value); if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_) { $objDiscount->quantity = $objDiscount->quantity - 1; } $objDiscount->update(); $discountsList .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding: 0.6em 0.4em; text-align: right;">' . $this->l('Voucher code:') . ' ' . $objDiscount->name . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">-' . Tools::displayPrice($value, $currency, false, false) . '</td> </tr>'; } // Specify order id for message $oldMessage = Message::getMessageByCartId(intval($cart->id)); if ($oldMessage) { $message = new Message(intval($oldMessage['id_message'])); $message->id_order = intval($order->id); $message->update(); } // Hook new order $orderStatus = new OrderState(intval($id_order_state)); if (Validate::isLoadedObject($orderStatus)) { Hook::newOrder($cart, $order, $customer, $currency, $orderStatus); foreach ($cart->getProducts() as $product) { if ($orderStatus->logable) { ProductSale::addProductSale(intval($product['id_product']), intval($product['cart_quantity'])); } } } if (isset($outOfStock) and $outOfStock) { $history = new OrderHistory(); $history->id_order = intval($order->id); $history->changeIdOrderState(_PS_OS_OUTOFSTOCK_, intval($order->id)); $history->addWithemail(); } // Set order state in order history ONLY even if the "out of stock" status has not been yet reached // So you migth have two order states $new_history = new OrderHistory(); $new_history->id_order = intval($order->id); $new_history->changeIdOrderState(intval($id_order_state), intval($order->id)); $new_history->addWithemail(true, $extraVars); // Send an e-mail to customer if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_ and $customer->id) { $invoice = new Address(intval($order->id_address_invoice)); $delivery = new Address(intval($order->id_address_delivery)); $carrier = new Carrier(intval($order->id_carrier)); $delivery_state = $delivery->id_state ? new State(intval($delivery->id_state)) : false; $invoice_state = $invoice->id_state ? new State(intval($invoice->id_state)) : false; $data = 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", intval($order->id)), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), intval($order->id_lang), 1), '{carrier}' => strval($carrier->name) != '0' ? $carrier->name : Configuration::get('PS_SHOP_NAME'), '{payment}' => $order->payment, '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false, false)); if (is_array($extraVars)) { $data = array_merge($data, $extraVars); } // Join PDF invoice if (intval(Configuration::get('PS_INVOICE')) and Validate::isLoadedObject($orderStatus) and $orderStatus->invoice and $order->invoice_number) { $fileAttachment['content'] = PDF::invoice($order, 'S'); $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', intval($order->id_lang)) . sprintf('%06d', $order->invoice_number) . '.pdf'; $fileAttachment['mime'] = 'application/pdf'; } else { $fileAttachment = NULL; } if ($orderStatus->send_email and Validate::isEmail($customer->email)) { Mail::Send(intval($order->id_lang), 'order_conf', 'Order confirmation', $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, NULL, NULL, $fileAttachment); } $this->currentOrder = intval($order->id); return true; } $this->currentOrder = intval($order->id); return true; } else { die(Tools::displayError('Order creation failed')); } } else { die(Tools::displayError('An order has already been placed using this cart')); } }
public function process() { parent::process(); self::$smarty->assign(array('is_guest' => self::$cookie->is_guest, 'HOOK_ORDER_CONFIRMATION' => Hook::orderConfirmation((int) $this->id_order), 'HOOK_PAYMENT_RETURN' => Hook::paymentReturn((int) $this->id_order, (int) $this->id_module))); if (self::$cookie->is_guest) { self::$smarty->assign(array('id_order' => $this->id_order, 'id_order_formatted' => sprintf('#%06d', $this->id_order))); /* If guest we clear the cookie for security reason */ self::$cookie->logout(); } else { self::$smarty->assign(array('id_order' => $this->id_order, 'id_order_formatted' => sprintf('#%06d', $this->id_order))); } //assign order details here $order = new Order($this->id_order); if (Validate::isLoadedObject($order) and $order->id_customer == self::$cookie->id_customer) { $id_order_state = (int) $order->getCurrentState(); $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang); $addressInvoice = new Address((int) $order->id_address_invoice); $addressDelivery = new Address((int) $order->id_address_delivery); // $stateInvoiceAddress = new State((int)$addressInvoice->id_state); $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country); $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country); $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields); $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields); if ($order->total_discounts > 0) { self::$smarty->assign('total_old', (double) ($order->total_paid - $order->total_discounts)); } self::$smarty->assign('order_total', Tools::ps_round($order->total_paid)); self::$smarty->assign('order_total_usd', Tools::ps_round(Tools::convertPrice($order->total_paid, self::$cookie->id_currency, false))); $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); $customer = new Customer($order->id_customer); $order->customization_fee = Cart::getCustomizationCostStatic((int) $order->id_cart); $totalQuantity = 0; foreach ($products as $productRow) { $totalQuantity += $productRow['product_quantity']; } if (strpos($order->payment, 'COD') === false) { self::$smarty->assign('paymentMethod', 'ONLINE'); } else { self::$smarty->assign('paymentMethod', 'COD'); } $shippingdate = new DateTime($order->expected_shipping_date); self::$smarty->assign(array('shipping_date' => $shippingdate->format("F j, Y"), 'shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int) $order->isReturnable(), 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable((int) $id_order_state) and $order->invoice_number, 'order_history' => $order->getHistory((int) self::$cookie->id_lang, false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) ? new State((int) $addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) ? new State((int) $addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => Message::getMessagesByOrderId((int) $order->id), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'customizedDatas' => $customizedDatas, 'totalQuantity' => $totalQuantity)); if ($carrier->url and $order->shipping_number) { self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); } self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order))); Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order)); //FB Share //$products = $order->getProducts(); $orderProducts = array(); $productMaxVal = 0; $productMaxId = null; foreach ($products as $product) { array_push($orderProducts, $product['product_id']); if ($product['product_price'] > $productMaxVal) { $productMaxId = $product['product_id']; $productMaxVal = $product['product_price']; } } $productObj = new Product($productMaxId, true, 1); self::$smarty->assign('fbShareProductObject', $productObj->getLink()); self::$smarty->assign('fbShareProductObjectId', $productMaxId); self::$smarty->assign('orderProducts', implode(",", $orderProducts)); self::$cookie->shareProductCode = md5(time() . $productMaxId); self::$cookie->write(); unset($carrier); unset($addressInvoice); unset($addressDelivery); } }
protected function getFormatedSummaryDetail() { $result = array('summary' => $this->context->cart->getSummaryDetails(), 'customizedDatas' => Product::getAllCustomizedDatas($this->context->cart->id, null, true)); $cart_product_context = Context::getContext()->cloneContext(); foreach ($result['summary']['products'] as $key => &$product) { $product['quantity_without_customization'] = $product['quantity']; $product['quantity'] = $product['cart_quantity']; // for compatibility with 1.2 themes if ($cart_product_context->shop->id != $product['id_shop']) { $cart_product_context->shop = new Shop((int) $product['id_shop']); } $product['price_without_specific_price'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], 2, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context); if (Product::getTaxCalculationMethod()) { $product['is_discounted'] = $product['price_without_specific_price'] != $product['price']; } else { $product['is_discounted'] = $product['price_without_specific_price'] != $product['price_wt']; } $product['price_without_quantity_discount'] = $product['price_without_specific_price']; if ($result['customizedDatas']) { if (isset($result['customizedDatas'][(int) $product['id_product']])) { foreach ($result['customizedDatas'][(int) $product['id_product']][(int) $product['id_product_attribute']] as $addresses) { foreach ($addresses as $customization) { $product['quantity_without_customization'] -= (int) $customization['quantity']; } } } } } if ($result['customizedDatas']) { Product::addCustomizationPrice($result['summary']['products'], $result['customizedDatas']); } return $result; }
public function viewDetails() { global $currentIndex, $cookie; if (!($cart = $this->loadObject(true))) { return; } $customer = new Customer($cart->id_customer); $customerStats = $customer->getStats(); $products = $cart->getProducts(); $customizedDatas = Product::getAllCustomizedDatas((int) $cart->id); Product::addCustomizationPrice($products, $customizedDatas); $summary = $cart->getSummaryDetails(); $discounts = $cart->getDiscounts(); $currency = new Currency($cart->id_currency); $currentLanguage = new Language((int) $cookie->id_lang); // display cart header echo '<h2>' . ($customer->id ? $customer->firstname . ' ' . $customer->lastname : $this->l('Guest')) . ' - ' . $this->l('Cart #') . sprintf('%06d', $cart->id) . ' ' . $this->l('from') . ' ' . $cart->date_upd . '</h2>'; /* Display customer information */ echo ' <br /> <div style="float: left;"> <fieldset style="width: 400px"> <legend><img src="../img/admin/tab-customers.gif" /> ' . $this->l('Customer information') . '</legend> <span style="font-weight: bold; font-size: 14px;">'; if ($customer->id) { echo ' <a href="?tab=AdminCustomers&id_customer=' . $customer->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $cookie->id_employee) . '"> ' . $customer->firstname . ' ' . $customer->lastname . '</a></span> (' . $this->l('#') . $customer->id . ')<br /> (<a href="mailto:' . $customer->email . '">' . $customer->email . '</a>)<br /><br /> ' . $this->l('Account registered:') . ' ' . Tools::displayDate($customer->date_add, (int) $cookie->id_lang, true) . '<br /> ' . $this->l('Valid orders placed:') . ' <b>' . $customerStats['nb_orders'] . '</b><br /> ' . $this->l('Total paid since registration:') . ' <b>' . Tools::displayPrice($customerStats['total_orders'], $currency, false) . '</b><br />'; } else { echo $this->l('Guest not registered') . '</span>'; } echo '</fieldset>'; echo ' </div> <div style="float: left; margin-left: 40px">'; /* Display order information */ $id_order = (int) Order::getOrderByCartId($cart->id); $order = new Order($id_order); if ($order->getTaxCalculationMethod() == PS_TAX_EXC) { $total_products = $summary['total_products']; $total_discount = $summary['total_discounts_tax_exc']; $total_wrapping = $summary['total_wrapping_tax_exc']; $total_price = $summary['total_price_without_tax']; $total_shipping = $summary['total_shipping_tax_exc']; } else { $total_products = $summary['total_products_wt']; $total_discount = $summary['total_discounts']; $total_wrapping = $summary['total_wrapping']; $total_price = $summary['total_price']; $total_shipping = $summary['total_shipping']; } echo ' <fieldset style="width: 400px"> <legend><img src="../img/admin/cart.gif" /> ' . $this->l('Order information') . '</legend> <span style="font-weight: bold; font-size: 14px;">'; if ($order->id) { echo ' <a href="?tab=AdminOrders&id_order=' . (int) $order->id . '&vieworder&token=' . Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee) . '"> ' . $this->l('Order #') . sprintf('%06d', $order->id) . '</a></span> <br /><br /> ' . $this->l('Made on:') . ' ' . Tools::displayDate($order->date_add, (int) $cookie->id_lang, true) . '<br /><br /><br /><br />'; } else { echo $this->l('No order created from this cart') . '</span>'; } echo '</fieldset>'; echo ' </div>'; // List of products echo ' <br style="clear:both;" /> <fieldset style="margin-top:25px; width: 715px; "> <legend><img src="../img/admin/cart.gif" alt="' . $this->l('Products') . '" />' . $this->l('Cart summary') . '</legend> <div style="float:left;"> <table style="width: 700px;" cellspacing="0" cellpadding="0" class="table" id="orderProducts"> <tr> <th align="center" style="width: 60px"> </th> <th>' . $this->l('Product') . '</th> <th style="width: 80px; text-align: center">' . $this->l('UP') . '</th> <th style="width: 20px; text-align: center">' . $this->l('Qty') . '</th> <th style="width: 30px; text-align: center">' . $this->l('Stock') . '</th> <th style="width: 90px; text-align: right; font-weight:bold;">' . $this->l('Total') . '</th> </tr>'; $tokenCatalog = Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee); foreach ($products as $k => $product) { if ($order->getTaxCalculationMethod() == PS_TAX_EXC) { $product_price = $product['price']; $product_total = $product['total']; } else { $product_price = $product['price_wt']; $product_total = $product['total_wt']; } $image = array(); if (isset($product['id_product_attribute']) and (int) $product['id_product_attribute']) { $image = Db::getInstance()->getRow(' SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $product['id_product_attribute']); } if (!isset($image['id_image'])) { $image = Db::getInstance()->getRow(' SELECT id_image FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $product['id_product'] . ' AND cover = 1'); } $stock = Db::getInstance()->getRow(' SELECT ' . ($product['id_product_attribute'] ? 'pa' : 'p') . '.quantity FROM ' . _DB_PREFIX_ . 'product p ' . ($product['id_product_attribute'] ? 'LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa ON p.id_product = pa.id_product' : '') . ' WHERE p.id_product = ' . (int) $product['id_product'] . ' ' . ($product['id_product_attribute'] ? 'AND pa.id_product_attribute = ' . (int) $product['id_product_attribute'] : '')); /* Customization display */ $this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $stock); if ($product['cart_quantity'] > $product['customizationQuantityTotal']) { $imageProduct = new Image($image['id_image']); echo ' <tr> <td align="center">' . (isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_ . 'p/' . $imageProduct->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['id_product'] . (isset($product['id_product_attribute']) ? '_' . (int) $product['id_product_attribute'] : '') . '.jpg', 45, 'jpg') : '--') . '</td> <td><a href="index.php?tab=AdminCatalog&id_product=' . $product['id_product'] . '&updateproduct&token=' . $tokenCatalog . '"> <span class="productName">' . $product['name'] . '</span><br /> ' . ($product['reference'] ? $this->l('Ref:') . ' ' . $product['reference'] : '') . (($product['reference'] and $product['supplier_reference']) ? ' / ' . $product['supplier_reference'] : '') . '</a></td> <td align="center">' . Tools::displayPrice($product_price, $currency, false) . '</td> <td align="center" class="productQuantity">' . ((int) $product['cart_quantity'] - $product['customizationQuantityTotal']) . '</td> <td align="center" class="productQuantity">' . (int) $stock['quantity'] . '</td> <td align="right">' . Tools::displayPrice($product_total, $currency, false) . '</td> </tr>'; } } echo ' <tr class="cart_total_product"> <td colspan="5">' . $this->l('Total products:') . '</td> <td class="price bold right">' . Tools::displayPrice($total_products, $currency, false) . '</td> </tr>'; if ($summary['total_discounts'] != 0) { echo ' <tr class="cart_total_voucher"> <td colspan="5">' . $this->l('Total vouchers:') . '</td> <td class="price-discount bold right">' . Tools::displayPrice($total_discount, $currency, false) . '</td> </tr>'; } if ($summary['total_wrapping'] > 0) { echo ' <tr class="cart_total_voucher"> <td colspan="5">' . $this->l('Total gift-wrapping:') . '</td> <td class="price-discount bold right">' . Tools::displayPrice($total_wrapping, $currency, false) . '</td> </tr>'; } if ($cart->getOrderTotal(true, Cart::ONLY_SHIPPING) > 0) { echo ' <tr class="cart_total_delivery"> <td colspan="5">' . $this->l('Total shipping:') . '</td> <td class="price bold right">' . Tools::displayPrice($total_shipping, $currency, false) . '</td> </tr>'; } echo ' <tr class="cart_total_price"> <td colspan="5" class="bold">' . $this->l('Total:') . '</td> <td class="price bold right">' . Tools::displayPrice($total_price, $currency, false) . '</td> </tr> </table>'; if (sizeof($discounts)) { echo ' <table cellspacing="0" cellpadding="0" class="table" style="width:280px; margin:15px 0px 0px 420px;"> <tr> <th><img src="../img/admin/coupon.gif" alt="' . $this->l('Discounts') . '" />' . $this->l('Discount name') . '</th> <th align="center" style="width: 100px">' . $this->l('Value') . '</th> </tr>'; foreach ($discounts as $discount) { echo ' <tr> <td><a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&updatediscount&token=' . Tools::getAdminToken('AdminDiscounts' . (int) Tab::getIdFromClassName('AdminDiscounts') . (int) $cookie->id_employee) . '">' . $discount['name'] . '</a></td> <td align="center">- ' . Tools::displayPrice($discount['value_real'], $currency, false) . '</td> </tr>'; } echo ' </table>'; } echo '<div style="float:left; margin-top:15px;">' . $this->l('According to the group of this customer, prices are printed:') . ' <b>' . ($order->getTaxCalculationMethod() == PS_TAX_EXC ? $this->l('tax excluded.') : $this->l('tax included.')) . '</b> </div></div>'; // Cancel product echo ' </fieldset> <div class="clear" style="height:20px;"> </div>'; }
/** * Display ajax content (this function is called instead of classic display, in ajax mode) */ public function displayAjax() { if ($this->errors) { die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors))); } if ($this->ajax_refresh) { die(Tools::jsonEncode(array('refresh' => true))); } if (Tools::getIsset('summary')) { $result = array(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { $groups = Validate::isLoadedObject($this->context->customer) ? $this->context->customer->getGroups() : array(1); if ($this->context->cart->id_address_delivery) { $deliveryAddress = new Address($this->context->cart->id_address_delivery); } $id_country = isset($deliveryAddress) && $deliveryAddress->id ? $deliveryAddress->id_country : Configuration::get('PS_COUNTRY_DEFAULT'); Cart::addExtraCarriers($result); } $result['summary'] = $this->context->cart->getSummaryDetails(null, true); $result['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true); $result['HOOK_SHOPPING_CART'] = Hook::exec('displayShoppingCartFooter', $result['summary']); $result['HOOK_SHOPPING_CART_EXTRA'] = Hook::exec('displayShoppingCart', $result['summary']); foreach ($result['summary']['products'] as $key => &$product) { $product['quantity_without_customization'] = $product['quantity']; if ($result['customizedDatas']) { foreach ($result['customizedDatas'][(int) $product['id_product']][(int) $product['id_product_attribute']] as $addresses) { foreach ($addresses as $customization) { $product['quantity_without_customization'] -= (int) $customization['quantity']; } } } $product['price_without_quantity_discount'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], 6, null, false, false); } if ($result['customizedDatas']) { Product::addCustomizationPrice($result['summary']['products'], $result['customizedDatas']); } die(Tools::jsonEncode($result)); } elseif (file_exists(_PS_MODULE_DIR_ . '/blockcart/blockcart-ajax.php')) { require_once _PS_MODULE_DIR_ . '/blockcart/blockcart-ajax.php'; } }
public function renderView() { /** @var Cart $cart */ if (!($cart = $this->loadObject(true))) { return; } $customer = new Customer($cart->id_customer); $currency = new Currency($cart->id_currency); $this->context->cart = $cart; $this->context->currency = $currency; $this->context->customer = $customer; $this->toolbar_title = sprintf($this->l('Cart #%06d'), $this->context->cart->id); $products = $cart->getProducts(); $customized_datas = Product::getAllCustomizedDatas((int) $cart->id); Product::addCustomizationPrice($products, $customized_datas); $summary = $cart->getSummaryDetails(); /* Display order information */ $id_order = (int) Order::getOrderByCartId($cart->id); $order = new Order($id_order); if (Validate::isLoadedObject($order)) { $tax_calculation_method = $order->getTaxCalculationMethod(); $id_shop = (int) $order->id_shop; } else { $id_shop = (int) $cart->id_shop; $tax_calculation_method = Group::getPriceDisplayMethod(Group::getCurrent()->id); } if ($tax_calculation_method == PS_TAX_EXC) { $total_products = $summary['total_products']; $total_discounts = $summary['total_discounts_tax_exc']; $total_wrapping = $summary['total_wrapping_tax_exc']; $total_price = $summary['total_price_without_tax']; $total_shipping = $summary['total_shipping_tax_exc']; } else { $total_products = $summary['total_products_wt']; $total_discounts = $summary['total_discounts']; $total_wrapping = $summary['total_wrapping']; $total_price = $summary['total_price']; $total_shipping = $summary['total_shipping']; } foreach ($products as $k => &$product) { if ($tax_calculation_method == PS_TAX_EXC) { $product['product_price'] = $product['price']; $product['product_total'] = $product['total']; } else { $product['product_price'] = $product['price_wt']; $product['product_total'] = $product['total_wt']; } $image = array(); if (isset($product['id_product_attribute']) && (int) $product['id_product_attribute']) { $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $product['id_product_attribute']); } if (!isset($image['id_image'])) { $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $product['id_product'] . ' AND cover = 1'); } $product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int) $id_shop); $image_product = new Image($image['id_image']); $product['image'] = isset($image['id_image']) ? ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $image_product->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['id_product'] . (isset($product['id_product_attribute']) ? '_' . (int) $product['id_product_attribute'] : '') . '.jpg', 45, 'jpg') : '--'; } $helper = new HelperKpi(); $helper->id = 'box-kpi-cart'; $helper->icon = 'icon-shopping-cart'; $helper->color = 'color1'; $helper->title = $this->l('Total Cart', null, null, false); $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id); $helper->value = Tools::displayPrice($total_price, $currency); $kpi = $helper->generate(); $this->tpl_view_vars = array('kpi' => $kpi, 'products' => $products, 'discounts' => $cart->getCartRules(), 'order' => $order, 'cart' => $cart, 'currency' => $currency, 'customer' => $customer, 'customer_stats' => $customer->getStats(), 'total_products' => $total_products, 'total_discounts' => $total_discounts, 'total_wrapping' => $total_wrapping, 'total_price' => $total_price, 'total_shipping' => $total_shipping, 'customized_datas' => $customized_datas, 'tax_calculation_method' => $tax_calculation_method); return parent::renderView(); }
/** * Get order products * * @return array Products with price, quantity (with taxe and without) */ public function getProducts($products = false, $selected_products = false, $selected_qty = false) { if (!$products) { $products = $this->getProductsDetail(); } $order = new Order($this->id_order); $customized_datas = Product::getAllCustomizedDatas($order->id_cart); $result_array = array(); foreach ($products as $row) { // Change qty if selected if ($selected_qty) { $row['product_quantity'] = 0; foreach ($selected_products as $key => $id_product) { if ($row['id_order_detail'] == $id_product) { $row['product_quantity'] = (int) $selected_qty[$key]; } } if (!$row['product_quantity']) { continue; } } $this->setProductImageInformations($row); $this->setProductCurrentStock($row); $this->setProductCustomizedDatas($row, $customized_datas); // Add information for virtual product if ($row['download_hash'] && !empty($row['download_hash'])) { $row['filename'] = ProductDownload::getFilenameFromIdProduct((int) $row['product_id']); // Get the display filename $row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']); } $row['id_address_delivery'] = $order->id_address_delivery; /* Ecotax */ $round_mode = $order->round_mode; $row['ecotax_tax_excl'] = $row['ecotax']; // alias for coherence $row['ecotax_tax_incl'] = $row['ecotax'] * (100 + $row['ecotax_tax_rate']) / 100; $row['ecotax_tax'] = $row['ecotax_tax_incl'] - $row['ecotax_tax_excl']; if ($round_mode == Order::ROUND_ITEM) { $row['ecotax_tax_incl'] = Tools::ps_round($row['ecotax_tax_incl'], _PS_PRICE_COMPUTE_PRECISION_, $round_mode); } $row['total_ecotax_tax_excl'] = $row['ecotax_tax_excl'] * $row['product_quantity']; $row['total_ecotax_tax_incl'] = $row['ecotax_tax_incl'] * $row['product_quantity']; $row['total_ecotax_tax'] = $row['total_ecotax_tax_incl'] - $row['total_ecotax_tax_excl']; foreach (array('ecotax_tax_excl', 'ecotax_tax_incl', 'ecotax_tax', 'total_ecotax_tax_excl', 'total_ecotax_tax_incl', 'total_ecotax_tax') as $ecotax_field) { $row[$ecotax_field] = Tools::ps_round($row[$ecotax_field], _PS_PRICE_COMPUTE_PRECISION_, $round_mode); } // Aliases $row['unit_price_tax_excl_including_ecotax'] = $row['unit_price_tax_excl']; $row['unit_price_tax_incl_including_ecotax'] = $row['unit_price_tax_incl']; $row['total_price_tax_excl_including_ecotax'] = $row['total_price_tax_excl']; $row['total_price_tax_incl_including_ecotax'] = $row['total_price_tax_incl']; /* Stock product */ $result_array[(int) $row['id_order_detail']] = $row; } if ($customized_datas) { Product::addCustomizationPrice($result_array, $customized_datas); } return $result_array; }
public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) { $products = $this->getProductsDetail(); } $customized_datas = Product::getAllCustomizedDatas($this->id_cart); $resultArray = array(); foreach ($products as $row) { // Change qty if selected if ($selectedQty) { $row['product_quantity'] = 0; foreach ($selectedProducts as $key => $id_product) { if ($row['id_order_detail'] == $id_product) { $row['product_quantity'] = (int) $selectedQty[$key]; } } if (!$row['product_quantity']) { continue; } } //$this->setProductImageInformations($row); //$this->setProductCurrentStock($row); // Backward compatibility 1.4 -> 1.5 //$this->setProductPrices($row); //$this->setProductCustomizedDatas($row, $customized_datas); // Add information for virtual product /*if ($row['download_hash'] && !empty($row['download_hash'])) { $row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']); // Get the display filename $row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']); }*/ $row['id_address_delivery'] = $this->id_address_delivery; /* Stock product */ $resultArray[(int) $row['id_neo_item_sale']] = $row; } if ($customized_datas) { Product::addCustomizationPrice($resultArray, $customized_datas); } return $resultArray; }
} if (!($id_order = intval(Tools::getValue('id_order'))) or !Validate::isUnsignedId($id_order)) { $errors[] = Tools::displayError('order ID is required'); } else { $order = new Order($id_order); if (Validate::isLoadedObject($order) and $order->id_customer == $cookie->id_customer) { $id_order_state = intval($order->getCurrentState()); $carrier = new Carrier(intval($order->id_carrier), intval($order->id_lang)); $addressInvoice = new Address(intval($order->id_address_invoice)); $addressDelivery = new Address(intval($order->id_address_delivery)); if ($order->total_discounts > 0) { $smarty->assign('total_old', floatval($order->total_paid - $order->total_discounts)); } $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas(intval($order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); $smarty->assign(array('shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => intval($order->isReturnable()), 'currency' => new Currency($order->id_currency), 'order_state' => intval($id_order_state), 'invoiceAllowed' => intval(Configuration::get('PS_INVOICE')), 'invoice' => OrderState::invoiceAvailable(intval($id_order_state)) or $order->invoice_number, 'order_history' => $order->getHistory(intval($cookie->id_lang), false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) ? new State(intval($addressInvoice->id_state)) : false, 'address_delivery' => $addressDelivery, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) ? new State(intval($addressDelivery->id_state)) : false, 'messages' => Message::getMessagesByOrderId(intval($order->id)), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'customizedDatas' => $customizedDatas)); if ($carrier->url and $order->shipping_number) { $smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); } } else { $errors[] = Tools::displayError('cannot find this order'); } } $smarty->assign('errors', $errors); if (Tools::getValue('ajax') == 'true') { $smarty->display(_PS_THEME_DIR_ . 'order-detail.tpl'); } else { include dirname(__FILE__) . '/header.php'; $smarty->display(_PS_THEME_DIR_ . 'order-detail.tpl'); include dirname(__FILE__) . '/footer.php';
protected function _assignSummaryInformations() { $summary = $this->context->cart->getSummaryDetails(); $customizedDatas = Product::getAllCustomizedDatas($this->context->cart->id); // override customization tax rate with real tax (tax rules) if ($customizedDatas) { foreach ($summary['products'] as &$productUpdate) { $productId = (int) (isset($productUpdate['id_product']) ? $productUpdate['id_product'] : $productUpdate['product_id']); $productAttributeId = (int) (isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id']); if (isset($customizedDatas[$productId][$productAttributeId])) { $productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } } Product::addCustomizationPrice($summary['products'], $customizedDatas); } $cart_product_context = Context::getContext()->cloneContext(); foreach ($summary['products'] as $key => &$product) { $product['quantity'] = $product['cart_quantity']; // for compatibility with 1.2 themes if ($cart_product_context->shop->id != $product['id_shop']) { $cart_product_context->shop = new Shop((int) $product['id_shop']); } $product['price_without_specific_price'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], 2, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context); if (Product::getTaxCalculationMethod()) { $product['is_discounted'] = $product['price_without_specific_price'] != $product['price']; } else { $product['is_discounted'] = $product['price_without_specific_price'] != $product['price_wt']; } } // Get available cart rules and unset the cart rules already in the cart $available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart); $cart_cart_rules = $this->context->cart->getCartRules(); foreach ($available_cart_rules as $key => $available_cart_rule) { if (!$available_cart_rule['highlight'] || strpos($available_cart_rule['code'], 'BO_ORDER_') === 0) { unset($available_cart_rules[$key]); continue; } foreach ($cart_cart_rules as $cart_cart_rule) { if ($available_cart_rule['id_cart_rule'] == $cart_cart_rule['id_cart_rule']) { unset($available_cart_rules[$key]); continue 2; } } } $show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && Configuration::get('PS_SHIP_WHEN_AVAILABLE'); $this->context->smarty->assign($summary); $this->context->smarty->assign(array('token_cart' => Tools::getToken(false), 'isLogged' => $this->isLogged, 'isVirtualCart' => $this->context->cart->isVirtualCart(), 'productNumber' => $this->context->cart->nbProducts(), 'voucherAllowed' => CartRule::isFeatureActive(), 'shippingCost' => $this->context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING), 'shippingCostTaxExc' => $this->context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING), 'customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'lastProductAdded' => $this->context->cart->getLastProduct(), 'displayVouchers' => $available_cart_rules, 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'show_option_allow_separate_package' => $show_option_allow_separate_package, 'smallSize' => Image::getSize(ImageType::getFormatedName('small')))); $this->context->smarty->assign(array('HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary))); }
protected function getFormatedSummaryDetail() { $result = array('summary' => $this->context->cart->getSummaryDetails(), 'customizedDatas' => Product::getAllCustomizedDatas($this->context->cart->id, null, true)); foreach ($result['summary']['products'] as $key => &$product) { $product['quantity_without_customization'] = $product['quantity']; if ($result['customizedDatas']) { if (isset($result['customizedDatas'][(int) $product['id_product']][(int) $product['id_product_attribute']])) { foreach ($result['customizedDatas'][(int) $product['id_product']][(int) $product['id_product_attribute']] as $addresses) { foreach ($addresses as $customization) { $product['quantity_without_customization'] -= (int) $customization['quantity']; } } } } } if ($result['customizedDatas']) { Product::addCustomizationPrice($result['summary']['products'], $result['customizedDatas']); } return $result; }
public function displayAjax() { if ($this->errors) { $this->ajaxDie(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors))); } if ($this->ajax_refresh) { $this->ajaxDie(Tools::jsonEncode(array('refresh' => true))); } $this->context->cookie->write(); if (Tools::getIsset('summary')) { $result = array(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { $groups = Validate::isLoadedObject($this->context->customer) ? $this->context->customer->getGroups() : array(1); if ($this->context->cart->id_address_delivery) { $delivery_address = new Address($this->context->cart->id_address_delivery); } $id_country = isset($delivery_address) && $delivery_address->id ? (int) $delivery_address->id_country : (int) Tools::getCountry(); Cart::addExtraCarriers($result); } $result['summary'] = $this->context->cart->getSummaryDetails(null, true); $result['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true); $result['HOOK_SHOPPING_CART'] = Hook::exec('displayShoppingCartFooter', $result['summary']); $result['HOOK_SHOPPING_CART_EXTRA'] = Hook::exec('displayShoppingCart', $result['summary']); foreach ($result['summary']['products'] as $key => &$product) { $product['quantity_without_customization'] = $product['quantity']; if ($result['customizedDatas'] && isset($result['customizedDatas'][(int) $product['id_product']][(int) $product['id_product_attribute']])) { foreach ($result['customizedDatas'][(int) $product['id_product']][(int) $product['id_product_attribute']] as $addresses) { foreach ($addresses as $customization) { if ($product['id_cart_product'] == $customization['id_cart_product']) { $product['quantity_without_customization'] -= (int) $customization['quantity']; } } } } $product['price_without_quantity_discount'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], 6, null, false, false); $ppropertiessmartprice_hook1 = null; if ($product['reduction_type'] == 'amount') { $reduction = (double) $product['price_wt'] - (double) $product['price_without_quantity_discount']; $product['reduction_formatted'] = Tools::displayPrice($reduction); } } if ($result['customizedDatas']) { Product::addCustomizationPrice($result['summary']['products'], $result['customizedDatas']); } $json = null; Hook::exec('actionCartListOverride', array('summary' => $result, 'json' => &$json)); $this->ajaxDie(Tools::jsonEncode(array_merge($result, (array) Tools::jsonDecode($json, true)))); } elseif (file_exists(_PS_MODULE_DIR_ . '/blockcart/blockcart-ajax.php')) { $context = Context::getContext(); $cart = $context->cart; if ($cart && isset($cart->last_icp)) { $context->smarty->assign('last_icp', $cart->last_icp); } require_once _PS_MODULE_DIR_ . '/blockcart/blockcart-ajax.php'; } }
/** * Validate an order in database * Function called from a payment module * * @param integer $id_cart Value * @param integer $id_order_state Value * @param float $amountPaid Amount really paid by customer (in the default currency) * @param string $paymentMethod Payment method (eg. 'Credit card') * @param string $message Message to attach to order */ public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, $secure_key = false) { global $cart; $cart = new Cart((int) $id_cart); // Does order already exists ? if (!$this->active) { die(Tools::displayError()); } if (Validate::isLoadedObject($cart) && $cart->OrderExists() == false) { if ($secure_key !== false && $secure_key != $cart->secure_key) { die(Tools::displayError()); } // Copying data from cart $order = new Order(); $order->id_carrier = (int) $cart->id_carrier; $order->id_customer = (int) $cart->id_customer; $order->id_address_invoice = (int) $cart->id_address_invoice; $order->id_address_delivery = (int) $cart->id_address_delivery; $vat_address = new Address((int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $order->id_currency = $currency_special ? (int) $currency_special : (int) $cart->id_currency; $order->id_lang = (int) $cart->id_lang; $order->id_cart = (int) $cart->id; $customer = new Customer((int) $order->id_customer); $order->secure_key = $secure_key ? pSQL($secure_key) : pSQL($customer->secure_key); $order->payment = $paymentMethod; if (isset($this->name)) { $order->module = $this->name; } $order->recyclable = $cart->recyclable; $order->gift = (int) $cart->gift; $order->gift_message = $cart->gift_message; $currency = new Currency($order->id_currency); $order->conversion_rate = $currency->conversion_rate; $amountPaid = !$dont_touch_amount ? Tools::ps_round((double) $amountPaid, 2) : $amountPaid; $order->total_paid_real = $amountPaid; $order->total_products = (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS); $order->total_products_wt = (double) $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $order->total_discounts = (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS)); $order->total_shipping = (double) $cart->getOrderShippingCost(); $order->carrier_tax_rate = (double) Tax::getCarrierTaxRate($cart->id_carrier, (int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $order->total_wrapping = (double) abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING)); $order->total_paid = (double) Tools::ps_round((double) $cart->getOrderTotal(true, Cart::BOTH), 2); $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; // 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 (number_format($order->total_paid, 2) != number_format($order->total_paid_real, 2)) { $id_order_state = Configuration::get('PS_OS_ERROR'); } // Creating order if ($cart->OrderExists() == false) { $result = $order->add(); } else { $errorMessage = Tools::displayError('An order has already been placed using this cart.'); Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($order->id_cart)); die($errorMessage); } // Next ! if ($result and isset($order->id)) { if (!$secure_key) { $message .= $this->l('Warning : the secure key is empty, check your payment account before validation'); } // Optional message to attach to this order if (isset($message) and !empty($message)) { $msg = new Message(); $message = strip_tags($message, '<br>'); if (Validate::isCleanHtml($message)) { $msg->message = $message; $msg->id_order = intval($order->id); $msg->private = 1; $msg->add(); } } // Insert products from cart into order_detail table $products = $cart->getProducts(); $productsList = ''; $db = Db::getInstance(); $query = 'INSERT INTO `' . _DB_PREFIX_ . 'order_detail` (`id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`, `reduction_percent`, `reduction_amount`, `group_reduction`, `product_quantity_discount`, `product_ean13`, `product_upc`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `ecotax_tax_rate`, `discount_quantity_applied`, `download_deadline`, `download_hash`) VALUES '; $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); $outOfStock = false; $store_all_taxes = array(); foreach ($products as $key => $product) { $productQuantity = (int) Product::getQuantity((int) $product['id_product'], $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL); $quantityInStock = $productQuantity - (int) $product['cart_quantity'] < 0 ? $productQuantity : (int) $product['cart_quantity']; if ($id_order_state != Configuration::get('PS_OS_CANCELED') and $id_order_state != Configuration::get('PS_OS_ERROR')) { if (Product::updateQuantity($product, (int) $order->id)) { $product['stock_quantity'] -= $product['cart_quantity']; } if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) { $outOfStock = true; } Product::updateDefaultAttribute($product['id_product']); } $price = Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 6, NULL, false, true, $product['cart_quantity'], 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, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); /* Store tax info */ $id_country = (int) Country::getDefaultCountryId(); $id_state = 0; $id_county = 0; $rate = 0; $id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $address_infos = Address::getCountryAndState($id_address); if ($address_infos['id_country']) { $id_country = (int) $address_infos['id_country']; $id_state = (int) $address_infos['id_state']; $id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']); } $allTaxes = TaxRulesGroup::getTaxes((int) Product::getIdTaxRulesGroupByIdProduct((int) $product['id_product']), $id_country, $id_state, $id_county); // If its a freeOrder, there will be no calculation if ($order->total_products > 0) { // remove order discount quotepart on product price in order to obtain the real tax $ratio = $price / $order->total_products; $order_reduction_amount = (double) abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS)) * $ratio; $tmp_price = $price - $order_reduction_amount; foreach ($allTaxes as $res) { if (!isset($store_all_taxes[$res->id])) { $store_all_taxes[$res->id] = array(); $store_all_taxes[$res->id]['amount'] = 0; } $store_all_taxes[$res->id]['name'] = $res->name[(int) $order->id_lang]; $store_all_taxes[$res->id]['rate'] = $res->rate; $unit_tax_amount = $tmp_price * ($res->rate * 0.01); $tmp_price = $tmp_price + $unit_tax_amount; $store_all_taxes[$res->id]['amount'] += $unit_tax_amount * $product['cart_quantity']; } } /* End */ // Add some informations for virtual products $deadline = '0000-00-00 00:00:00'; $download_hash = null; if ($id_product_download = ProductDownload::getIdFromIdProduct((int) $product['id_product'])) { $productDownload = new ProductDownload((int) $id_product_download); $deadline = $productDownload->getDeadLine(); $download_hash = $productDownload->getHash(); } // Exclude VAT if (!_PS_TAX_) { $product['tax'] = 0; $product['rate'] = 0; $tax_rate = 0; } else { $tax_rate = Tax::getProductTaxRate((int) $product['id_product'], $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } $ecotaxTaxRate = 0; if (!empty($product['ecotax'])) { $ecotaxTaxRate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } $product_price = (double) Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC ? 2 : 6, NULL, false, false, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $specificPrice, false, false); $group_reduction = (double) GroupReduction::getValueForProduct((int) $product['id_product'], $customer->id_default_group) * 100; if (!$group_reduction) { $group_reduction = (double) Group::getReduction((int) $order->id_customer); } $quantityDiscount = SpecificPrice::getQuantityDiscount((int) $product['id_product'], Shop::getCurrentShop(), (int) $cart->id_currency, (int) $vat_address->id_country, (int) $customer->id_default_group, (int) $product['cart_quantity']); $unitPrice = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 2, NULL, false, true, 1, false, (int) $order->id_customer, NULL, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $quantityDiscountValue = $quantityDiscount ? (Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC ? Tools::ps_round($unitPrice, 2) : $unitPrice) - $quantityDiscount['price'] * (1 + $tax_rate / 100) : 0.0; $query .= '(' . (int) $order->id . ', ' . (int) $product['id_product'] . ', ' . (isset($product['id_product_attribute']) ? (int) $product['id_product_attribute'] : 'NULL') . ', \'' . pSQL($product['name'] . ((isset($product['attributes']) and $product['attributes'] != NULL) ? ' - ' . $product['attributes'] : '')) . '\', ' . (int) $product['cart_quantity'] . ', ' . $quantityInStock . ', ' . $product_price . ', ' . (double) (($specificPrice and $specificPrice['reduction_type'] == 'percentage') ? $specificPrice['reduction'] * 100 : 0.0) . ', ' . (double) (($specificPrice and $specificPrice['reduction_type'] == 'amount') ? !$specificPrice['id_currency'] ? Tools::convertPrice($specificPrice['reduction'], $order->id_currency) : $specificPrice['reduction'] : 0.0) . ', ' . $group_reduction . ', ' . $quantityDiscountValue . ', ' . (empty($product['ean13']) ? 'NULL' : '\'' . pSQL($product['ean13']) . '\'') . ', ' . (empty($product['upc']) ? 'NULL' : '\'' . pSQL($product['upc']) . '\'') . ', ' . (empty($product['reference']) ? 'NULL' : '\'' . pSQL($product['reference']) . '\'') . ', ' . (empty($product['supplier_reference']) ? 'NULL' : '\'' . pSQL($product['supplier_reference']) . '\'') . ', ' . (double) ($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']) . ', \'' . (empty($tax_rate) ? '' : pSQL($product['tax'])) . '\', ' . (double) $tax_rate . ', ' . (double) Tools::convertPrice(floatval($product['ecotax']), intval($order->id_currency)) . ', ' . (double) $ecotaxTaxRate . ', ' . (($specificPrice and $specificPrice['from_quantity'] > 1) ? 1 : 0) . ', \'' . pSQL($deadline) . '\', \'' . pSQL($download_hash) . '\'),'; $customizationQuantity = 0; if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) { $customizationText = ''; foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] as $customization) { if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) { foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text) { $customizationText .= $text['name'] . ':' . ' ' . $text['value'] . '<br />'; } } if (isset($customization['datas'][_CUSTOMIZE_FILE_])) { $customizationText .= count($customization['datas'][_CUSTOMIZE_FILE_]) . ' ' . Tools::displayError('image(s)') . '<br />'; } $customizationText .= '---<br />'; } $customizationText = rtrim($customizationText, '---<br />'); $customizationQuantity = (int) $product['customizationQuantityTotal']; $productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding: 0.6em 0.4em;">' . (isset($product['reference']) && !empty($product['reference']) ? $product['reference'] : ' ') . '</td> <td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : '') . ' - ' . $this->l('Customized') . (!empty($customizationText) ? ' - ' . $customizationText : '') . '</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt, $currency, false) . '</td> <td style="padding: 0.6em 0.4em; text-align: center;">' . $customizationQuantity . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt), $currency, false) . '</td> </tr>'; } if (!$customizationQuantity or (int) $product['cart_quantity'] > $customizationQuantity) { $productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding: 0.6em 0.4em;">' . (isset($product['reference']) && !empty($product['reference']) ? $product['reference'] : ' ') . '</td> <td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : '') . '</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt, $currency, false) . '</td> <td style="padding: 0.6em 0.4em; text-align: center;">' . ((int) $product['cart_quantity'] - $customizationQuantity) . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(((int) $product['cart_quantity'] - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt), $currency, false) . '</td> </tr>'; } } // end foreach ($products) $query = rtrim($query, ','); $result = $db->Execute($query); /* Add carrier tax */ $shippingCostTaxExcl = $cart->getOrderShippingCost((int) $order->id_carrier, false); $allTaxes = TaxRulesGroup::getTaxes((int) Carrier::getIdTaxRulesGroupByIdCarrier((int) $order->id_carrier), $id_country, $id_state, $id_county); $nTax = 0; foreach ($allTaxes as $tax) { if (!isset($tax->id)) { continue; } if (!isset($store_all_taxes[$tax->id])) { $store_all_taxes[$tax->id] = array(); } if (!isset($store_all_taxes[$tax->id]['amount'])) { $store_all_taxes[$tax->id]['amount'] = 0; } $store_all_taxes[$tax->id]['name'] = $tax->name[(int) $order->id_lang]; $store_all_taxes[$tax->id]['rate'] = $tax->rate; if (!$nTax++) { $store_all_taxes[$tax->id]['amount'] += $shippingCostTaxExcl * (1 + $tax->rate * 0.01) - $shippingCostTaxExcl; } else { $store_all_taxes[$tax->id]['amount'] += $order->total_shipping - $order->total_shipping / (1 + $tax->rate * 0.01); } } /* Store taxes */ foreach ($store_all_taxes as $tax) { Db::getInstance()->Execute(' INSERT INTO `' . _DB_PREFIX_ . 'order_tax` (`id_order`, `tax_name`, `tax_rate`, `amount`) VALUES (' . (int) $order->id . ', \'' . pSQL($tax['name']) . '\', ' . (double) $tax['rate'] . ', ' . (double) $tax['amount'] . ')'); } // Insert discounts from cart into order_discount table $discounts = $cart->getDiscounts(); $discountsList = ''; $total_discount_value = 0; $shrunk = false; foreach ($discounts as $discount) { $objDiscount = new Discount((int) $discount['id_discount']); $value = $objDiscount->getValue(count($discounts), $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), $order->total_shipping, $cart->id); if ($objDiscount->id_discount_type == 2 and in_array($objDiscount->behavior_not_exhausted, array(1, 2))) { $shrunk = true; } if ($shrunk and $total_discount_value + $value > $order->total_products_wt + $order->total_shipping + $order->total_wrapping) { $amount_to_add = $order->total_products_wt + $order->total_shipping + $order->total_wrapping - $total_discount_value; if ($objDiscount->id_discount_type == 2 and $objDiscount->behavior_not_exhausted == 2) { $voucher = new Discount(); foreach ($objDiscount as $key => $discountValue) { $voucher->{$key} = $discountValue; } $voucher->name = 'VSRK' . (int) $order->id_customer . 'O' . (int) $order->id; $voucher->value = (double) $value - $amount_to_add; $voucher->add(); $params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false); $params['{voucher_num}'] = $voucher->name; $params['{firstname}'] = $customer->firstname; $params['{lastname}'] = $customer->lastname; $params['{id_order}'] = $order->id; $params['{order_name}'] = sprintf("#%06d", (int) $order->id); @Mail::Send((int) $order->id_lang, 'voucher', Mail::l('New voucher regarding your order #', (int) $order->id_lang) . sprintf("%06d", (int) $order->id), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname); } } else { $amount_to_add = $value; } $order->addDiscount($objDiscount->id, $objDiscount->name, $amount_to_add); $total_discount_value += $amount_to_add; if ($id_order_state != Configuration::get('PS_OS_ERROR') and $id_order_state != Configuration::get('PS_OS_CANCELED')) { $objDiscount->quantity = $objDiscount->quantity - 1; } $objDiscount->update(); $discountsList .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding: 0.6em 0.4em; text-align: right;">' . $this->l('Voucher code:') . ' ' . $objDiscount->name . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . ($value != 0.0 ? '-' : '') . Tools::displayPrice($value, $currency, false) . '</td> </tr>'; } // Specify order id for message $oldMessage = Message::getMessageByCartId((int) $cart->id); if ($oldMessage) { $message = new Message((int) $oldMessage['id_message']); $message->id_order = (int) $order->id; $message->update(); } // Hook new order $orderStatus = new OrderState((int) $id_order_state, (int) $order->id_lang); if (Validate::isLoadedObject($orderStatus)) { Hook::newOrder($cart, $order, $customer, $currency, $orderStatus); foreach ($cart->getProducts() as $product) { if ($orderStatus->logable) { ProductSale::addProductSale((int) $product['id_product'], (int) $product['cart_quantity']); } } } if (isset($outOfStock) && $outOfStock && Configuration::get('PS_STOCK_MANAGEMENT')) { $history = new OrderHistory(); $history->id_order = (int) $order->id; $history->changeIdOrderState(Configuration::get('PS_OS_OUTOFSTOCK'), (int) $order->id); $history->addWithemail(); } // Set order state in order history ONLY even if the "out of stock" status has not been yet reached // So you migth have two order states $new_history = new OrderHistory(); $new_history->id_order = (int) $order->id; $new_history->changeIdOrderState((int) $id_order_state, (int) $order->id); $new_history->addWithemail(true, $extraVars); // Order is reloaded because the status just changed $order = new Order($order->id); // Send an e-mail to customer if ($id_order_state != Configuration::get('PS_OS_ERROR') and $id_order_state != Configuration::get('PS_OS_CANCELED') and $customer->id) { $invoice = new Address((int) $order->id_address_invoice); $delivery = new Address((int) $order->id_address_delivery); $carrier = new Carrier((int) $order->id_carrier, $order->id_lang); $delivery_state = $delivery->id_state ? new State((int) $delivery->id_state) : false; $invoice_state = $invoice->id_state ? new State((int) $invoice->id_state) : false; $data = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $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="color:#DB3484; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')), '{invoice_block_html}' => $this->_getFormatedAddress($invoice, "<br />", array('firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:#DB3484; 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}' => sprintf("#%06d", (int) $order->id), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), (int) $order->id_lang, 1), '{carrier}' => $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false)); if (is_array($extraVars)) { $data = array_merge($data, $extraVars); } // Join PDF invoice if ((int) Configuration::get('PS_INVOICE') and Validate::isLoadedObject($orderStatus) and $orderStatus->invoice and $order->invoice_number) { $fileAttachment['content'] = PDF::invoice($order, 'S'); $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', (int) $order->id_lang) . sprintf('%06d', $order->invoice_number) . '.pdf'; $fileAttachment['mime'] = 'application/pdf'; } else { $fileAttachment = null; } if (Validate::isEmail($customer->email)) { Mail::Send((int) $order->id_lang, 'order_conf', Mail::l('Order confirmation', (int) $order->id_lang), $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, NULL, NULL, $fileAttachment); } } $this->currentOrder = (int) $order->id; return true; } else { $errorMessage = Tools::displayError('Order creation failed'); Logger::addLog($errorMessage, 4, '0000002', 'Cart', intval($order->id_cart)); die($errorMessage); } } else { $errorMessage = Tools::displayError('Cart cannot be loaded or an order has already been placed using this cart'); Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id)); die($errorMessage); } }
/** * Assign template vars related to order tracking informations */ protected function assignOrderTracking($order_collection) { $customer = new Customer((int) $order_collection->getFirst()->id_customer); $order_collection = $order_collection->getAll(); $order_list = array(); foreach ($order_collection as $order) { $order_list[] = $order; } foreach ($order_list as &$order) { $order->id_order_state = (int) $order->getCurrentState(); $order->invoice = OrderState::invoiceAvailable((int) $order->id_order_state) && $order->invoice_number; $order->order_history = $order->getHistory((int) $this->context->language->id, false, true); $order->carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang); $order->address_invoice = new Address((int) $order->id_address_invoice); $order->address_delivery = new Address((int) $order->id_address_delivery); $order->inv_adr_fields = AddressFormat::getOrderedAddressFields($order->address_invoice->id_country); $order->dlv_adr_fields = AddressFormat::getOrderedAddressFields($order->address_delivery->id_country); $order->invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($order->address_invoice, $order->inv_adr_fields); $order->deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($order->address_delivery, $order->dlv_adr_fields); $order->currency = new Currency($order->id_currency); $order->discounts = $order->getCartRules(); $order->invoiceState = Validate::isLoadedObject($order->address_invoice) && $order->address_invoice->id_state ? new State((int) $order->address_invoice->id_state) : false; $order->deliveryState = Validate::isLoadedObject($order->address_delivery) && $order->address_delivery->id_state ? new State((int) $order->address_delivery->id_state) : false; $order->products = $order->getProducts(); $order->customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($order->products, $order->customizedDatas); $order->total_old = $order->total_discounts > 0 ? (double) ($order->total_paid - $order->total_discounts) : false; if ($order->carrier->url && $order->shipping_number) { $order->followup = str_replace('@', $order->shipping_number, $order->carrier->url); } $order->hook_orderdetaildisplayed = Hook::exec('displayOrderDetail', array('order' => $order)); Hook::exec('actionOrderDetail', array('carrier' => $order->carrier, 'order' => $order)); } $this->context->smarty->assign(array('shop_name' => Configuration::get('PS_SHOP_NAME'), 'order_collection' => $order_list, 'return_allowed' => false, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'is_guest' => true, 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'use_tax' => Configuration::get('PS_TAX'))); }
/** * Product table with price, quantities... */ public function ProdTab($delivery = false) { if (!$delivery) { $w = array(100, 15, 30, 15, 30); } else { $w = array(120, 30, 10); } self::ProdTabHeader($delivery); if (!self::$orderSlip) { if (isset(self::$order->products) and sizeof(self::$order->products)) { $products = self::$order->products; } else { $products = self::$order->getProducts(); } } else { $products = self::$orderSlip->getOrdersSlipProducts(self::$orderSlip->id, self::$order); } $customizedDatas = Product::getAllCustomizedDatas((int) self::$order->id_cart); Product::addCustomizationPrice($products, $customizedDatas); $counter = 0; $lines = 25; $lineSize = 0; $line = 0; foreach ($products as $product) { if (!$delivery or (int) $product['product_quantity'] - (int) $product['product_quantity_refunded'] > 0) { if ($counter >= $lines) { $this->AddPage(); $this->Ln(); self::ProdTabHeader($delivery); $lineSize = 0; $counter = 0; $lines = 40; $line++; } $counter = $counter + $lineSize / 5; $i = -1; // Unit vars $unit_without_tax = $product['product_price'] + $product['ecotax']; $unit_with_tax = $product['product_price_wt']; if (self::$_priceDisplayMethod == PS_TAX_EXC) { $unit_price =& $unit_without_tax; } else { $unit_price =& $unit_with_tax; } $productQuantity = $delivery ? (int) $product['product_quantity'] - (int) $product['product_quantity_refunded'] : (int) $product['product_quantity']; if ($productQuantity <= 0) { continue; } // Total prices $total_with_tax = $unit_with_tax * $productQuantity; $total_without_tax = $unit_without_tax * $productQuantity; // Spec if (self::$_priceDisplayMethod == PS_TAX_EXC) { $final_price =& $total_without_tax; } else { $final_price =& $total_with_tax; } // End Spec if (isset($customizedDatas[$product['product_id']][$product['product_attribute_id']])) { $custoLabel = ''; foreach ($customizedDatas[$product['product_id']][$product['product_attribute_id']] as $customizedData) { $customizationGroup = $customizedData['datas']; $nb_images = 0; if (array_key_exists(_CUSTOMIZE_FILE_, $customizationGroup)) { $nb_images = sizeof($customizationGroup[_CUSTOMIZE_FILE_]); } if (array_key_exists(_CUSTOMIZE_TEXTFIELD_, $customizationGroup)) { foreach ($customizationGroup[_CUSTOMIZE_TEXTFIELD_] as $customization) { if (!empty($customization['name'])) { $custoLabel .= '- ' . $customization['name'] . ': ' . $customization['value'] . "\n"; } } } if ($nb_images > 0) { $custoLabel .= '- ' . $nb_images . ' ' . self::l('image(s)') . "\n"; } $custoLabel .= "---\n"; } $custoLabel = rtrim($custoLabel, "---\n"); $productQuantity = (int) $product['product_quantity'] - (int) $product['customizationQuantityTotal']; if ($delivery) { $this->SetX(25); } $before = $this->GetY(); $this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']) . ' - ' . self::l('Customized') . " \n" . Tools::iconv('utf-8', self::encoding(), $custoLabel), 'B'); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX() + $w[0] + ($delivery ? 15 : 0), $this->GetY() - $lineSize); $this->Cell($w[++$i], $lineSize, $product['product_reference'], 'B'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($unit_price, self::$currency, true)), 'B', 0, 'R'); } $this->Cell($w[++$i], $lineSize, (int) $product['customizationQuantityTotal'], 'B', 0, 'C'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($unit_price * (int) $product['customizationQuantityTotal'], self::$currency, true)), 'B', 0, 'R'); } $this->Ln(); $i = -1; $total_with_tax = $unit_with_tax * $productQuantity; $total_without_tax = $unit_without_tax * $productQuantity; } if ($delivery) { $this->SetX(25); } if ($productQuantity) { $before = $this->GetY(); $this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'B'); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX() + $w[0] + ($delivery ? 15 : 0), $this->GetY() - $lineSize); $this->Cell($w[++$i], $lineSize, $product['product_reference'] ? Tools::iconv('utf-8', self::encoding(), $product['product_reference']) : '--', 'B'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($unit_price, self::$currency, true)), 'B', 0, 'R'); } $this->Cell($w[++$i], $lineSize, $productQuantity, 'B', 0, 'C'); if (!$delivery) { $this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($final_price, self::$currency, true)), 'B', 0, 'R'); } $this->Ln(); } } } if (!sizeof(self::$order->getDiscounts()) and !$delivery) { $this->Cell(array_sum($w), 0, ''); } }