* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminCarts extends AdminTab { public function __construct() { $this->table = 'cart'; $this->className = 'Cart'; $this->lang = false; $this->edit = false; $this->view = true; $this->delete = false; $this->_select = 'CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, a.id_cart as total, ca.name as carrier'; $this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer c on (c.id_customer = a.id_customer) LEFT JOIN '._DB_PREFIX_.'currency cu on (cu.id_currency = a.id_currency) LEFT JOIN '._DB_PREFIX_.'carrier ca on (ca.id_carrier = a.id_carrier) '; $this->fieldsDisplay = array( 'id_cart' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'customer' => array('title' => $this->l('Customer'), 'width' => 80, 'filter_key' => 'c!lastname'), 'total' => array('title' => $this->l('Total'), 'callback' => 'getTotalCart', 'orderby' => false, 'search' => false, 'width' => 50, 'align' => 'right', 'prefix' => '', 'suffix' => '', 'currency' => true), 'carrier' => array('title' => $this->l('Carrier'), 'width' => 25, 'align' => 'center', 'callback' => 'replaceZeroByShopName'), 'date_add' => array('title' => $this->l('Date'), 'width' => 90, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add')); parent::__construct(); } public function viewDetails() { global $currentIndex, $cookie; $cart = $this->loadObject(); $customer = new Customer($cart->id_customer); $customerStats = $customer->getStats(); $products = $cart->getProducts(); $customizedDatas = Product::getAllCustomizedDatas(intval($cart->id)); Product::addCustomizationPrice($products, $customizedDatas); $summary = $cart->getSummaryDetails(); $discounts = $cart->getDiscounts(); $currency = new Currency($cart->id_currency); $currentLanguage = new Language(intval($cookie->id_lang)); // display cart header echo '

'.(($customer->id) ? $customer->firstname.' '.$customer->lastname : $this->l('Guest')).' - '.$this->l('Cart #').sprintf('%06d', $cart->id).' '.$this->l('from').' '.$cart->date_upd.'

'; /* Display customer information */ echo '
'.$this->l('Customer information').' '; if ($customer->id) echo ' '.$customer->firstname.' '.$customer->lastname.' ('.$this->l('#').$customer->id.')
('.$customer->email.')

'.$this->l('Account registered:').' '.Tools::displayDate($customer->date_add, intval($cookie->id_lang), true).'
'.$this->l('Valid orders placed:').' '.$customerStats['nb_orders'].'
'.$this->l('Total paid since registration:').' '.Tools::displayPrice($customerStats['total_orders'], $currency, false, false).'
'; else echo $this->l('Guest not registered').''; echo '
'; echo '
'; /* Display order information */ $id_order = intval(Order::getOrderByCartId($cart->id)); $order = new Order($id_order); echo '
'.$this->l('Order information').' '; if ($order->id) echo ' '.$this->l('Order #').sprintf('%06d', $order->id).'

'.$this->l('Made on:').' '.$order->date_add.'



'; else echo $this->l('No order created from this cart').''; echo '
'; echo '
'; // List of products echo '
'.$this->l('Products').''.$this->l('Cart summary').'
'; $tokenCatalog = Tools::getAdminToken('AdminCatalog'.intval(Tab::getIdFromClassName('AdminCatalog')).intval($cookie->id_employee)); foreach ($products as $k => $product) { $image = array(); if (isset($product['id_product_attribute']) AND intval($product['id_product_attribute'])) $image = Db::getInstance()->getRow(' SELECT id_image FROM '._DB_PREFIX_.'product_attribute_image WHERE id_product_attribute = '.intval($product['id_product_attribute'])); if (!isset($image['id_image'])) $image = Db::getInstance()->getRow(' SELECT id_image FROM '._DB_PREFIX_.'image WHERE id_product = '.intval($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 = '.intval($product['id_product']).' '.($product['id_product_attribute'] ? 'AND pa.id_product_attribute = '.intval($product['id_product_attribute']) : '')); /* Customization display */ $this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $stock); if ($product['cart_quantity'] > $product['customizationQuantityTotal']) echo ' '; if (isset($image['id_image'])) { $target = '../img/tmp/product_mini_'.intval($product['id_product']).(isset($product['id_product_attribute']) ? '_'.intval($product['id_product_attribute']) : '').'.jpg'; if (file_exists($target)) $products[$k]['image_size'] = getimagesize($target); } } echo ' '; if ($summary['total_discounts'] != 0) echo ' '; if ($summary['total_wrapping'] > 0) echo ' '; if ($cart->getOrderTotal(true, 5) > 0) echo ' '; echo '
  '.$this->l('Product').' '.$this->l('UP').' '.$this->l('Qty').' '.$this->l('Stock').' '.$this->l('Total').'
'.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.intval($product['id_product']).'-'.intval($image['id_image']).'.jpg', 'product_mini_'.intval($product['id_product']).(isset($product['id_product_attribute']) ? '_'.intval($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--').' '.$product['name'].'
'.($product['reference'] ? $this->l('Ref:').' '.$product['reference'] : '') .(($product['reference'] AND $product['supplier_reference']) ? ' / '.$product['supplier_reference'] : '') .'
'.Tools::displayPrice($product['price_wt'], $currency, false, false).' '.(intval($product['cart_quantity']) - $product['customizationQuantityTotal']).' '.intval($stock['quantity']).' '.Tools::displayPrice($product['total_wt'], $currency, false, false).'
'.$this->l('Total products:').' '.Tools::displayPrice($summary['total_products_wt'], $currency, false).'
'.$this->l('Total vouchers:').' '.Tools::displayPrice($summary['total_discounts'], $currency, false).'
'.$this->l('Total gift-wrapping:').' '.Tools::displayPrice($summary['total_wrapping'], $currency, false).'
'.$this->l('Total shipping:').' '.Tools::displayPrice($cart->getOrderTotal(true, 5), $currency, false).'
'.$this->l('Total:').' '.Tools::displayPrice($summary['total_price'], $currency, false).'
'; if (sizeof($discounts)) { echo ' '; foreach ($discounts as $discount) echo ' '; echo '
'.$this->l('Discounts').''.$this->l('Discount name').' '.$this->l('Value').'
'.$discount['name'].' - '.Tools::displayPrice($discount['value_real'], $currency, false).'
'; } echo '
'; // Cancel product echo '
 
'; } private function displayCustomizedDatas(&$customizedDatas, &$product, &$currency, &$image, $tokenCatalog, &$stock) { $order = $this->loadObject(); if (is_array($customizedDatas) AND isset($customizedDatas[intval($product['id_product'])][intval($product['id_product_attribute'])])) { echo ' '.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.intval($product['id_product']).'-'.intval($image['id_image']).'.jpg', 'product_mini_'.intval($product['id_product']).(isset($product['id_product_attribute']) ? '_'.intval($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--').' '.$product['name'].'
'.($product['reference'] ? $this->l('Ref:').' '.$product['reference'] : '') .(($product['reference'] AND $product['supplier_reference']) ? ' / '.$product['supplier_reference'] : '') .'
'.Tools::displayPrice($product['price_wt'], $currency, false, false).' '.$product['customizationQuantityTotal'].' '.intval($stock['quantity']).' '.Tools::displayPrice($product['total_customization_wt'], $currency, false, false).' '; foreach ($customizedDatas[intval($product['id_product'])][intval($product['id_product_attribute'])] AS $customization) { echo ' '; foreach ($customization['datas'] AS $type => $datas) if ($type == _CUSTOMIZE_FILE_) { $i = 0; echo ''; } elseif ($type == _CUSTOMIZE_TEXTFIELD_) { $i = 0; echo ''; } echo ' '.$customization['quantity'].' '; } } } public function display() { global $cookie; if (isset($_GET['view'.$this->table])) $this->viewDetails(); else { $this->getList(intval($cookie->id_lang), !Tools::getValue($this->table.'Orderby') ? 'date_add' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL); $this->displayList(); } } } ?>