/**
  * @param OrderSlip $order_slip
  * @param $smarty
  * @throws PrestaShopException
  */
 public function __construct(OrderSlip $order_slip, $smarty)
 {
     $this->order_slip = $order_slip;
     $this->order = new Order((int) $order_slip->id_order);
     $this->id_cart = $this->order->id_cart;
     $products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order);
     foreach ($products as $product) {
         $customized_datas = Product::getAllCustomizedDatas($this->id_cart, null, true, null, (int) $product['id_customization']);
         Product::addProductCustomizationPrice($product, $customized_datas);
     }
     $this->order->products = $products;
     $this->smarty = $smarty;
     // header informations
     $this->date = Tools::displayDate($this->order_slip->date_add);
     $prefix = Configuration::get('PS_CREDIT_SLIP_PREFIX', Context::getContext()->language->id);
     $this->title = sprintf(HTMLTemplateOrderSlip::l('%1$s%2$06d'), $prefix, (int) $this->order_slip->id);
     $this->shop = new Shop((int) $this->order->id_shop);
 }
Example #2
0
 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 = $this->trans('Cart #%ID%', array('%ID%' => $this->context->cart->id), 'Admin.OrdersCustomers.Feature');
     $products = $cart->getProducts();
     $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') : '--';
         $customized_datas = Product::getAllCustomizedDatas($this->context->cart->id, null, true, null, (int) $product['id_customization']);
         $this->context->cart->setProductCustomizedDatas($product, $customized_datas);
         if ($customized_datas) {
             Product::addProductCustomizationPrice($product, $customized_datas);
         }
     }
     $helper = new HelperKpi();
     $helper->id = 'box-kpi-cart';
     $helper->icon = 'icon-shopping-cart';
     $helper->color = 'color1';
     $helper->title = $this->trans('Total Cart', array(), 'Admin.OrdersCustomers.Feature');
     $helper->subtitle = $this->trans('Cart #%ID%', array('%ID%' => $cart->id), 'Admin.OrdersCustomers.Feature');
     $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, 'tax_calculation_method' => $tax_calculation_method);
     return parent::renderView();
 }
Example #3
0
 /**
  * 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);
     $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);
         $customized_datas = Product::getAllCustomizedDatas($order->id_cart, null, true, null, (int) $row['id_customization']);
         $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'];
         if ($customized_datas) {
             Product::addProductCustomizationPrice($row, $customized_datas);
         }
         /* Stock product */
         $result_array[(int) $row['id_order_detail']] = $row;
     }
     return $result_array;
 }
Example #4
0
 /**
  * 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();
     }
     $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);
         // Backward compatibility 1.4 -> 1.5
         $this->setProductPrices($row);
         $customized_datas = Product::getAllCustomizedDatas($this->id_cart, null, true, null, (int) $row['id_customization']);
         $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;
         if ($customized_datas) {
             Product::addProductCustomizationPrice($row, $customized_datas);
         }
         /* Stock product */
         $result_array[(int) $row['id_order_detail']] = $row;
     }
     return $result_array;
 }