* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7046 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ 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 = true; $this->_select = 'CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) `customer`, a.id_cart total, ca.name carrier, o.id_order '; $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) LEFT JOIN '._DB_PREFIX_.'orders o ON (o.id_cart = a.id_cart) '; $this->fieldsDisplay = array( 'id_cart' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'id_order' => array('title' => $this->l('ID Order'), 'align' => 'center', 'width' => 25), 'customer' => array('title' => $this->l('Customer'), 'width' => 80, 'filter_key' => 'c!lastname'), 'total' => array('title' => $this->l('Total'), 'callback' => 'getOrderTotalUsingTaxCalculationMethod', 'orderby' => false, 'search' => false, 'width' => 50, 'align' => 'right', 'prefix' => '', 'suffix' => '', 'currency' => true), 'carrier' => array('title' => $this->l('Carrier'), 'width' => 25, 'align' => 'center', 'callback' => 'replaceZeroByShopName', 'filter_key' => 'ca!name'), '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; 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 '

'.(($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, (int)($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).'
'; else echo $this->l('Guest not registered').''; echo '
'; echo '
'; /* 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 '
'.$this->l('Order information').' '; if ($order->id) echo ' '.$this->l('Order #').sprintf('%06d', $order->id).'

'.$this->l('Made on:').' '.Tools::displayDate($order->date_add, (int)$cookie->id_lang, true).'



'; 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'.(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 ' '; } } echo ' '; if ($summary['total_discounts'] != 0) echo ' '; if ($summary['total_wrapping'] > 0) echo ' '; if ($cart->getOrderTotal(true, Cart::ONLY_SHIPPING) > 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/'.$imageProduct->getExistingImgPath().'.jpg', 'product_mini_'.(int)($product['id_product']).(isset($product['id_product_attribute']) ? '_'.(int)($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, $currency, false).' '.((int)($product['cart_quantity']) - $product['customizationQuantityTotal']).' '.(int)($stock['quantity']).' '.Tools::displayPrice($product_total, $currency, false).'
'.$this->l('Total products:').' '.Tools::displayPrice($total_products, $currency, false).'
'.$this->l('Total vouchers:').' '.Tools::displayPrice($total_discount, $currency, false).'
'.$this->l('Total gift-wrapping:').' '.Tools::displayPrice($total_wrapping, $currency, false).'
'.$this->l('Total shipping:').' '.Tools::displayPrice($total_shipping, $currency, false).'
'.$this->l('Total:').' '.Tools::displayPrice($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 '
'. $this->l('According to the group of this customer, prices are printed:').' '.($order->getTaxCalculationMethod() == PS_TAX_EXC ? $this->l('tax excluded.') : $this->l('tax included.')).'
'; // Cancel product echo '
 
'; } private function displayCustomizedDatas(&$customizedDatas, &$product, &$currency, &$image, $tokenCatalog, &$stock) { if (!($order = $this->loadObject(true))) return; if (is_array($customizedDatas) AND isset($customizedDatas[(int)($product['id_product'])][(int)($product['id_product_attribute'])])) { $image = new Image($image['id_image']); echo ' '.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.$image->getExistingImgPath().'.jpg', 'product_mini_'.(int)($product['id_product']).(isset($product['id_product_attribute']) ? '_'.(int)($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).' '.$product['customizationQuantityTotal'].' '.(int)($stock['quantity']).' '.Tools::displayPrice($product['total_customization_wt'], $currency, false).' '; foreach ($customizedDatas[(int)($product['id_product'])][(int)($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((int)($cookie->id_lang), !Tools::getValue($this->table.'Orderby') ? 'date_add' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL); $this->displayList(); } } protected function _displayDeleteLink($token = NULL, $id) { global $currentIndex; foreach ($this->_list as $cart) if ($id == $cart['id_cart']) if ($cart['id_order']) return; $_cacheLang['Delete'] = $this->l('Delete', __CLASS__, true, false); $_cacheLang['DeleteItem'] = $this->l('Delete item #', __CLASS__, true, false).$id.' ?)'; echo ' '.$_cacheLang['Delete'].' '; } }