Guest User

Untitled

a guest
Nov 29th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. public function display_cart() {
  2. $config = $this->config;
  3. $errorMessage = null;
  4.  
  5. $checkout = $config['checkoutPath'];
  6. $priceFormat = $config['priceFormat'];
  7.  
  8. $id = $config['item']['id'];
  9. $name = $config['item']['name'];
  10. $price = $config['item']['price'];
  11. $qty = $config['item']['qty'];
  12. $url = $config['item']['url'];
  13. $add = $config['item']['add'];
  14.  
  15. $id = $_POST[$id];
  16. $name = $_POST[$name];
  17. $price = $_POST[$price];
  18. $qty = $_POST[$qty];
  19. $url = $_POST[$url];
  20.  
  21. $cartToken = $_POST['cartToken'];
  22.  
  23. if(!$_SESSION['cartToken']){
  24. $_SESSION['cartToken'] = md5(session_id() . time() . $_SERVER['HTTP_USER_AGENT']);
  25. }
  26.  
  27. if ($config['csrfToken'] === 'true' && $_POST && $cartToken != $_SESSION['cartToken']) {
  28. $errorMessage = 'Invalid token!' . $cartToken . ' / ' . $_SESSION['cartToken'];
  29. }
  30.  
  31. $id = filter_var($id, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW);
  32. $name = filter_var($name, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW);
  33. $url = filter_var($url, FILTER_SANITIZE_URL);
  34.  
  35. if($config['decimalPlaces'] === true) {
  36. $qty = round($qty, $config['decimalPlaces']);
  37. }
  38.  
  39. if ($_POST[$add]) {
  40. $itemAdded = $this->add_item($id, $name, $price, $qty, $url);
  41. if ($itemAdded !== true) {
  42. $errorType = $itemAdded;
  43. switch($errorType) {
  44. case 'qty':
  45. $errorMessage = $config['text']['quantityError'];
  46. break;
  47. case 'price':
  48. $errorMessage = $config['text']['priceError'];
  49. break;
  50. }
  51. }
  52. }
  53.  
  54. if ($_POST['cartUpdate']) {
  55. $itemUpdated = $this->update_item($_POST['itemId'], $_POST['itemQty']);
  56. if ($itemUpdated !== true) {
  57. $errorMessage = $config['text']['quantityError'];
  58. }
  59. }
  60.  
  61. if($_POST['cartUpdateCart'] || $_POST['cartCheckout']) {
  62. $cartUpdated = $this->update_cart();
  63. if ($cartUpdated !== true) {
  64. $errorMessage = $config['text']['quantityError'];
  65. }
  66. }
  67.  
  68. if($_GET['cartRemove'] && !$_POST) {
  69. $this->remove_item($_GET['cartRemove']);
  70. }
  71.  
  72. if($_POST['cartEmpty']) {
  73. $this->empty_cart();
  74. }
  75.  
  76. $itemsText = $config['text']['multipleItems'];
  77. if ($this->itemCount == 1) {
  78. $itemsText = $config['text']['singleItem'];
  79. }
  80.  
  81. $isCheckout = strpos(request_uri(), $checkout);
  82. if ($isCheckout !== false || $_REQUEST['cartIsCheckout'] == 'true') {
  83. $isCheckout = true;
  84. } else {
  85. $isCheckout = false;
  86. }
  87.  
  88. if ($isCheckout === true) {
  89. $path = filter_var($config['cartPath'], FILTER_SANITIZE_URL);
  90. $path = rtrim($path, '');
  91. $checkout = 'gateway.php';
  92. }
  93.  
  94. $inputType = 'submit';
  95.  
  96. if ($_SESSION['quantityError'] === true) {
  97. $errorMessage = $config['text']['quantityError'];
  98. unset($_SESSION['quantityError']);
  99. }
  100.  
  101. $currencyCode = trim(strtoupper($config['currencyCode']));
  102. switch($currencyCode) {
  103. case 'EUR':
  104. $currencySymbol = '€';
  105. break;
  106. case 'GBP':
  107. $currencySymbol = '£';
  108. break;
  109. case 'JPY':
  110. $currencySymbol = '¥';
  111. break;
  112. case 'CHF':
  113. $currencySymbol = 'CHF ';
  114. break;
  115. case 'SEK':
  116. case 'DKK':
  117. case 'NOK':
  118. $currencySymbol = 'Kr ';
  119. break;
  120. case 'PLN':
  121. $currencySymbol = 'zł ';
  122. break;
  123. case 'HUF':
  124. $currencySymbol = 'Ft ';
  125. break;
  126. case 'CZK':
  127. $currencySymbol = 'Kč ';
  128. break;
  129. case 'ILS':
  130. $currencySymbol = '₪ ';
  131. break;
  132. case 'TWD':
  133. $currencySymbol = 'NT$';
  134. break;
  135. case 'THB':
  136. $currencySymbol = '฿';
  137. break;
  138. case 'MYR':
  139. $currencySymbol = 'RM';
  140. break;
  141. case 'PHP':
  142. $currencySymbol = 'Php';
  143. break;
  144. case 'BRL':
  145. $currencySymbol = 'R$';
  146. break;
  147. case 'USD':
  148. default:
  149. $currencySymbol = '$';
  150. break;
  151. }
  152.  
  153. function tab($n) {
  154. $tabs = null;
  155. while ($n > 0) {
  156. $tabs .= "\t";
  157. --$n;
  158. }
  159. return $tabs;
  160. }
  161.  
  162. if ($errorMessage) {
  163. $errorMessage = "<p id='cart-error'>$errorMessage</p>";
  164. }
  165.  
  166. echo tab(1) . "$errorMessage\n";
  167. echo tab(1) . "<form method='post' action='$checkout'>\n";
  168. echo tab(2) . "<fieldset>\n";
  169. echo tab(3) . "<input type='hidden' name='cartToken' value='{$_SESSION['cartToken']}' />\n";
  170.  
  171.  
  172.  
  173. //total items in cart label
  174. echo tab(7) . "<b><div style='float: right; '>{$config['text']['cartTitle']} ($this->itemCount $itemsText)</div></b>";
  175.  
  176. echo tab(3) . "<table class='table table-striped'>\n";
  177. echo tab(4) . "<thead>\n";
  178. echo tab(5) . "<tr>\n";
  179. echo tab(6) . "<th>\n";
  180.  
  181.  
  182.  
  183.  
  184. echo tab(6) . "</th>\n";
  185. echo tab(5) . "</tr>". "\n";
  186. echo tab(4) . "</thead>\n";
  187. echo tab(4) . "<tfoot>\n";
  188. echo tab(5) . "<tr>\n";
  189. echo tab(6) . "<th colspan='3'>\n";
  190.  
  191. if ($isCheckout !== true) {
  192. if ($config['button']['checkout']) {
  193. $inputType = "image";
  194. $src = " src='{$config['button']['checkoutPaypal']}' alt='{$config['text']['checkout']}' title='' ";
  195. }
  196.  
  197. }
  198. //subtotal
  199. echo tab(7) . "<div style='float: right;'>{$config['text']['subtotal']}: <strong>$currencySymbol" . number_format($this->subtotal, $priceFormat['decimals'], $priceFormat['dec_point'], $priceFormat['thousands_sep']) . "</strong></span></div>";
  200. echo tab(6) . "</th>\n";
  201. echo tab(5) . "</tr>\n";
  202. echo tab(4) . "</tfoot>\n";
  203. echo tab(4) . "<tbody>\n";
  204.  
  205. if($this->itemCount > 0) {
  206. foreach($this->get_contents() as $item) {
  207. echo tab(5) . "<tr>\n";
  208. echo tab(6) . "<td>\n";
  209. echo tab(7) . "<input name='cartItemId[]' type='hidden' value='{$item['id']}' />\n";
  210. echo tab(7) . "<input id='cartItemQty-{$item['id']}' name='cartItemQty[]' size='2' type='text' value='{$item['qty']}' />\n";
  211. echo tab(6) . "</td>\n";
  212.  
  213.  
  214. echo tab(6) . "<td class='cart-item-name'>\n";
  215.  
  216. if ($item['url']) {
  217. echo tab(7) . "<a href='{$item['url']}'>{$item['name']}</a>\n";
  218. } else {
  219. echo tab(7) . $item['name'] . "\n";
  220. }
  221.  
  222.  
  223. echo tab(7) . "<input name='cartItemName[]' type='hidden' value='{$item['name']}' />\n";
  224. echo tab(6) . "</td>\n";
  225.  
  226.  
  227.  
  228. echo tab(6) . "<td class='cart-item-price'>\n";
  229. echo tab(7) . "<span>$currencySymbol" . number_format($item['subtotal'], $priceFormat['decimals'], $priceFormat['dec_point'], $priceFormat['thousands_sep']) . "</span><input name='cartItemPrice[]' type='hidden' value='{$item['price']}' />\n";
  230. echo tab(7) . "<a class='cart-remove' href='?cartRemove={$item['id']}'>{$config['text']['removeLink']}</a>\n";
  231. echo tab(6) . "</td>\n";
  232. echo tab(5) . "</tr>\n";
  233. }
  234. } else {
  235. //empty button?
  236. echo tab(5) . "<tr><td id='cart-empty' colspan='3'>{$config['text']['emptyMessage']}</td></tr>\n";
  237. }
  238. echo tab(4) . "</tbody>\n";
  239. echo tab(3) . "</table>\n\n";
  240.  
  241. //checkout button
  242. //echo tab(7) . "<div class='checkout'><input type='$inputType' $src id='cart-checkout' name='cartCheckout' class='btn btn-primary' value='{$config['text']['checkout']}' /></div>";
  243.  
  244.  
  245.  
  246.  
  247. echo tab(3) . "<div id='cart-buttons'>\n";
  248.  
  249. if ($config['button']['update']) {
  250. $inputType = "image";
  251. $src = " src='{$config['button']['update']}' alt='{$config['text']['update']}' title='' ";
  252. }
  253. //uncomment to enable update button
  254. //echo tab(4) . "<input type='$inputType' $src name='cartUpdateCart' value='{$config['text']['update']}' class='cart-button' />\n";
  255.  
  256. if ($config['button']['empty']) {
  257. $inputType = "image";
  258. $src = " src='{$config['button']['empty']}' alt='{$config['text']['emptyButton']}' title='' ";
  259. }
  260.  
  261. //empty button
  262. //echo tab(4) . "<input type='$inputType' $src name='cartEmpty' value='{$config['text']['emptyButton']}' class='btn btn-primary' />\n";
  263.  
  264.  
  265.  
  266. echo tab(3) . "</div>\n";
  267.  
  268.  
  269.  
  270.  
  271. if ($isCheckout === true) {
  272. echo tab(3) . "<input type='hidden' id='cart-is-checkout' name='cartIsCheckout' value='true' />\n";
  273.  
  274. if ($config['button']['checkout']) {
  275. $inputType = "image";
  276. $src = " src='{$config['button']['checkout']}' alt='{$config['text']['checkoutPaypal']}' title='' ";
  277. }
  278.  
  279. if($this->itemCount <= 0) {
  280. $disablePaypalCheckout = " disabled='disabled'";
  281. }
  282.  
  283. //checkout with paypal button (disabled version)
  284. echo tab(3) . "<div style='float: right;'><input type='$inputType' $src id='cart-paypal-checkout' name='cartPaypalCheckout' value='{$config['text']['checkoutPaypal']}' class='btn btn-primary' $disablePaypalCheckout /></div>";
  285. }
  286.  
  287. echo tab(2) . "</fieldset>\n";
  288. echo tab(1) . "</form>\n\n";
  289.  
  290. echo tab(1) . "<div id='cart-tooltip'></div>\n";
  291. }
Advertisement
Add Comment
Please, Sign In to add comment