PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/admin444/tabs/AdminCarts.php

http://marocmall.googlecode.com/
PHP | 285 lines | 248 code | 21 blank | 16 comment | 17 complexity | 82ef21e0dc737df85ed2b28824bb058a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * Customers tab for admin panel, AdminContacts.php
  4. * @category admin
  5. *
  6. * @author PrestaShop <support@prestashop.com>
  7. * @copyright PrestaShop
  8. * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
  9. * @version 1.3
  10. *
  11. */
  12. include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
  13. class AdminCarts extends AdminTab
  14. {
  15. public function __construct()
  16. {
  17. $this->table = 'cart';
  18. $this->className = 'Cart';
  19. $this->lang = false;
  20. $this->edit = false;
  21. $this->view = true;
  22. $this->delete = false;
  23. $this->_select = 'CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, a.id_cart as total, ca.name as carrier';
  24. $this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer c on (c.id_customer = a.id_customer)
  25. LEFT JOIN '._DB_PREFIX_.'currency cu on (cu.id_currency = a.id_currency)
  26. LEFT JOIN '._DB_PREFIX_.'carrier ca on (ca.id_carrier = a.id_carrier)
  27. ';
  28. $this->fieldsDisplay = array(
  29. 'id_cart' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
  30. 'customer' => array('title' => $this->l('Customer'), 'width' => 80, 'filter_key' => 'c!lastname'),
  31. 'total' => array('title' => $this->l('Total'), 'callback' => 'getTotalCart', 'orderby' => false, 'search' => false, 'width' => 50, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'currency' => true),
  32. 'carrier' => array('title' => $this->l('Carrier'), 'width' => 25, 'align' => 'center', 'callback' => 'replaceZeroByShopName'),
  33. 'date_add' => array('title' => $this->l('Date'), 'width' => 90, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'));
  34. parent::__construct();
  35. }
  36. public function viewDetails()
  37. {
  38. global $currentIndex, $cookie;
  39. $cart = $this->loadObject();
  40. $customer = new Customer($cart->id_customer);
  41. $customerStats = $customer->getStats();
  42. $products = $cart->getProducts();
  43. $customizedDatas = Product::getAllCustomizedDatas(intval($cart->id));
  44. Product::addCustomizationPrice($products, $customizedDatas);
  45. $summary = $cart->getSummaryDetails();
  46. $discounts = $cart->getDiscounts();
  47. $currency = new Currency($cart->id_currency);
  48. $currentLanguage = new Language(intval($cookie->id_lang));
  49. // display cart header
  50. 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>';
  51. /* Display customer information */
  52. echo '
  53. <br />
  54. <div style="float: left;">
  55. <fieldset style="width: 400px">
  56. <legend><img src="../img/admin/tab-customers.gif" /> '.$this->l('Customer information').'</legend>
  57. <span style="font-weight: bold; font-size: 14px;">';
  58. if ($customer->id)
  59. echo '
  60. <a href="?tab=AdminCustomers&id_customer='.$customer->id.'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.intval(Tab::getIdFromClassName('AdminCustomers')).intval($cookie->id_employee)).'"> '.$customer->firstname.' '.$customer->lastname.'</a></span> ('.$this->l('#').$customer->id.')<br />
  61. (<a href="mailto:'.$customer->email.'">'.$customer->email.'</a>)<br /><br />
  62. '.$this->l('Account registered:').' '.Tools::displayDate($customer->date_add, intval($cookie->id_lang), true).'<br />
  63. '.$this->l('Valid orders placed:').' <b>'.$customerStats['nb_orders'].'</b><br />
  64. '.$this->l('Total paid since registration:').' <b>'.Tools::displayPrice($customerStats['total_orders'], $currency, false, false).'</b><br />';
  65. else
  66. echo $this->l('Guest not registered').'</span>';
  67. echo '</fieldset>';
  68. echo '
  69. </div>
  70. <div style="float: left; margin-left: 40px">';
  71. /* Display order information */
  72. $id_order = intval(Order::getOrderByCartId($cart->id));
  73. $order = new Order($id_order);
  74. echo '
  75. <fieldset style="width: 400px">
  76. <legend><img src="../img/admin/cart.gif" /> '.$this->l('Order information').'</legend>
  77. <span style="font-weight: bold; font-size: 14px;">';
  78. if ($order->id)
  79. echo '
  80. <a href="?tab=AdminOrders&id_order='.intval($order->id).'&vieworder&token='.Tools::getAdminToken('AdminOrders'.intval(Tab::getIdFromClassName('AdminOrders')).intval($cookie->id_employee)).'"> '.$this->l('Order #').sprintf('%06d', $order->id).'</a></span>
  81. <br /><br />
  82. '.$this->l('Made on:').' '.Tools::displayDate($order->date_add, intval($cookie->id_lang), true).'<br /><br /><br /><br />';
  83. else
  84. echo $this->l('No order created from this cart').'</span>';
  85. echo '</fieldset>';
  86. echo '
  87. </div>';
  88. // List of products
  89. echo '
  90. <br style="clear:both;" />
  91. <fieldset style="margin-top:25px; width: 715px; ">
  92. <legend><img src="../img/admin/cart.gif" alt="'.$this->l('Products').'" />'.$this->l('Cart summary').'</legend>
  93. <div style="float:left;">
  94. <table style="width: 700px;" cellspacing="0" cellpadding="0" class="table" id="orderProducts">
  95. <tr>
  96. <th align="center" style="width: 60px">&nbsp;</th>
  97. <th>'.$this->l('Product').'</th>
  98. <th style="width: 80px; text-align: center">'.$this->l('UP').'</th>
  99. <th style="width: 20px; text-align: center">'.$this->l('Qty').'</th>
  100. <th style="width: 30px; text-align: center">'.$this->l('Stock').'</th>
  101. <th style="width: 90px; text-align: right; font-weight:bold;">'.$this->l('Total').'</th>
  102. </tr>';
  103. $tokenCatalog = Tools::getAdminToken('AdminCatalog'.intval(Tab::getIdFromClassName('AdminCatalog')).intval($cookie->id_employee));
  104. foreach ($products as $k => $product)
  105. {
  106. $image = array();
  107. if (isset($product['id_product_attribute']) AND intval($product['id_product_attribute']))
  108. $image = Db::getInstance()->getRow('
  109. SELECT id_image
  110. FROM '._DB_PREFIX_.'product_attribute_image
  111. WHERE id_product_attribute = '.intval($product['id_product_attribute']));
  112. if (!isset($image['id_image']))
  113. $image = Db::getInstance()->getRow('
  114. SELECT id_image
  115. FROM '._DB_PREFIX_.'image
  116. WHERE id_product = '.intval($product['id_product']).' AND cover = 1');
  117. $stock = Db::getInstance()->getRow('
  118. SELECT '.($product['id_product_attribute'] ? 'pa' : 'p').'.quantity
  119. FROM '._DB_PREFIX_.'product p
  120. '.($product['id_product_attribute'] ? 'LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON p.id_product = pa.id_product' : '').'
  121. WHERE p.id_product = '.intval($product['id_product']).'
  122. '.($product['id_product_attribute'] ? 'AND pa.id_product_attribute = '.intval($product['id_product_attribute']) : ''));
  123. /* Customization display */
  124. $this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $stock);
  125. if ($product['cart_quantity'] > $product['customizationQuantityTotal'])
  126. echo '
  127. <tr>
  128. <td align="center">'.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.intval($product['id_product']).'-'.intval($image['id_image']).'.jpg',
  129. 'product_mini_'.intval($product['id_product']).(isset($product['id_product_attribute']) ? '_'.intval($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--').'</td>
  130. <td><a href="index.php?tab=AdminCatalog&id_product='.$product['id_product'].'&updateproduct&token='.$tokenCatalog.'">
  131. <span class="productName">'.$product['name'].'</span><br />
  132. '.($product['reference'] ? $this->l('Ref:').' '.$product['reference'] : '')
  133. .(($product['reference'] AND $product['supplier_reference']) ? ' / '.$product['supplier_reference'] : '')
  134. .'</a></td>
  135. <td align="center">'.Tools::displayPrice($product['price_wt'], $currency, false, false).'</td>
  136. <td align="center" class="productQuantity">'.(intval($product['cart_quantity']) - $product['customizationQuantityTotal']).'</td>
  137. <td align="center" class="productQuantity">'.intval($stock['quantity']).'</td>
  138. <td align="right">'.Tools::displayPrice($product['total_wt'], $currency, false, false).'</td>
  139. </tr>';
  140. if (isset($image['id_image']))
  141. {
  142. $target = '../img/tmp/product_mini_'.intval($product['id_product']).(isset($product['id_product_attribute']) ? '_'.intval($product['id_product_attribute']) : '').'.jpg';
  143. if (file_exists($target))
  144. $products[$k]['image_size'] = getimagesize($target);
  145. }
  146. }
  147. echo '
  148. <tr class="cart_total_product">
  149. <td colspan="5">'.$this->l('Total products:').'</td>
  150. <td class="price bold right">'.Tools::displayPrice($summary['total_products_wt'], $currency, false).'</td>
  151. </tr>';
  152. if ($summary['total_discounts'] != 0)
  153. echo '
  154. <tr class="cart_total_voucher">
  155. <td colspan="5">'.$this->l('Total vouchers:').'</td>
  156. <td class="price-discount bold right">'.Tools::displayPrice($summary['total_discounts'], $currency, false).'</td>
  157. </tr>';
  158. if ($summary['total_wrapping'] > 0)
  159. echo '
  160. <tr class="cart_total_voucher">
  161. <td colspan="5">'.$this->l('Total gift-wrapping:').'</td>
  162. <td class="price-discount bold right">'.Tools::displayPrice($summary['total_wrapping'], $currency, false).'</td>
  163. </tr>';
  164. if ($cart->getOrderTotal(true, 5) > 0)
  165. echo '
  166. <tr class="cart_total_delivery">
  167. <td colspan="5">'.$this->l('Total shipping:').'</td>
  168. <td class="price bold right">'.Tools::displayPrice($cart->getOrderTotal(true, 5), $currency, false).'</td>
  169. </tr>';
  170. echo '
  171. <tr class="cart_total_price">
  172. <td colspan="5" class="bold">'.$this->l('Total:').'</td>
  173. <td class="price bold right">'.Tools::displayPrice($summary['total_price'], $currency, false).'</td>
  174. </tr>
  175. </table>';
  176. if (sizeof($discounts))
  177. {
  178. echo '
  179. <table cellspacing="0" cellpadding="0" class="table" style="width:280px; margin:15px 0px 0px 420px;">
  180. <tr>
  181. <th><img src="../img/admin/coupon.gif" alt="'.$this->l('Discounts').'" />'.$this->l('Discount name').'</th>
  182. <th align="center" style="width: 100px">'.$this->l('Value').'</th>
  183. </tr>';
  184. foreach ($discounts as $discount)
  185. echo '
  186. <tr>
  187. <td><a href="?tab=AdminDiscounts&id_discount='.$discount['id_discount'].'&updatediscount&token='.Tools::getAdminToken('AdminDiscounts'.intval(Tab::getIdFromClassName('AdminDiscounts')).intval($cookie->id_employee)).'">'.$discount['name'].'</a></td>
  188. <td align="center">- '.Tools::displayPrice($discount['value_real'], $currency, false).'</td>
  189. </tr>';
  190. echo '
  191. </table>';
  192. }
  193. echo '
  194. </div>';
  195. // Cancel product
  196. echo '
  197. </fieldset>
  198. <div class="clear" style="height:20px;">&nbsp;</div>';
  199. }
  200. private function displayCustomizedDatas(&$customizedDatas, &$product, &$currency, &$image, $tokenCatalog, &$stock)
  201. {
  202. $order = $this->loadObject();
  203. if (is_array($customizedDatas) AND isset($customizedDatas[intval($product['id_product'])][intval($product['id_product_attribute'])]))
  204. {
  205. echo '
  206. <tr>
  207. <td align="center">'.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.intval($product['id_product']).'-'.intval($image['id_image']).'.jpg',
  208. 'product_mini_'.intval($product['id_product']).(isset($product['id_product_attribute']) ? '_'.intval($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--').'</td>
  209. <td><a href="index.php?tab=AdminCatalog&id_product='.$product['id_product'].'&updateproduct&token='.$tokenCatalog.'">
  210. <span class="productName">'.$product['name'].'</span><br />
  211. '.($product['reference'] ? $this->l('Ref:').' '.$product['reference'] : '')
  212. .(($product['reference'] AND $product['supplier_reference']) ? ' / '.$product['supplier_reference'] : '')
  213. .'</a></td>
  214. <td align="center">'.Tools::displayPrice($product['price_wt'], $currency, false, false).'</td>
  215. <td align="center" class="productQuantity">'.$product['customizationQuantityTotal'].'</td>
  216. <td align="center" class="productQuantity">'.intval($stock['quantity']).'</td>
  217. <td align="right">'.Tools::displayPrice($product['total_customization_wt'], $currency, false, false).'</td>
  218. </tr>';
  219. foreach ($customizedDatas[intval($product['id_product'])][intval($product['id_product_attribute'])] AS $customization)
  220. {
  221. echo '
  222. <tr>
  223. <td colspan="2">';
  224. foreach ($customization['datas'] AS $type => $datas)
  225. if ($type == _CUSTOMIZE_FILE_)
  226. {
  227. $i = 0;
  228. echo '<ul style="margin: 4px 0px 4px 0px; padding: 0px; list-style-type: none;">';
  229. foreach ($datas AS $data)
  230. echo '<li style="display: inline; margin: 2px;">
  231. <a href="displayImage.php?img='.$data['value'].'&name='.intval($order->id).'-file'.++$i.'" target="_blank"><img src="'._THEME_PROD_PIC_DIR_.$data['value'].'_small" alt="" /></a>
  232. </li>';
  233. echo '</ul>';
  234. }
  235. elseif ($type == _CUSTOMIZE_TEXTFIELD_)
  236. {
  237. $i = 0;
  238. echo '<ul style="margin: 0px 0px 4px 0px; padding: 0px 0px 0px 6px; list-style-type: none;">';
  239. foreach ($datas AS $data)
  240. echo '<li>'.($data['name'] ? $data['name'] : $this->l('Text #').++$i).$this->l(':').' '.$data['value'].'</li>';
  241. echo '</ul>';
  242. }
  243. echo '</td>
  244. <td align="center"></td>
  245. <td align="center" class="productQuantity">'.$customization['quantity'].'</td>
  246. <td align="center" class="productQuantity"></td>
  247. <td align="center"></td>
  248. </tr>';
  249. }
  250. }
  251. }
  252. public function display()
  253. {
  254. global $cookie;
  255. if (isset($_GET['view'.$this->table]))
  256. $this->viewDetails();
  257. else
  258. {
  259. $this->getList(intval($cookie->id_lang), !Tools::getValue($this->table.'Orderby') ? 'date_add' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL);
  260. $this->displayList();
  261. }
  262. }
  263. }
  264. ?>