An easy point of sale system with automatic inventory tracking. https://netsyms.biz/apps/nickelbox/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

action.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. require_once __DIR__ . "/required.php";
  8. require_once __DIR__ . "/lib/item.php";
  9. switch ($VARS['action']) {
  10. case "addtocart":
  11. $item = $VARS['item'];
  12. $qty = $VARS['qty'];
  13. if (!$binstack->has('items', ['AND' => ['itemid' => $item, 'price[>]' => 0]])) {
  14. header('Location: ./?page=cart&msg=invaliditem');
  15. die("Invalid item");
  16. }
  17. $cart = [];
  18. if (!empty($_SESSION['cart'])) {
  19. $cart = $_SESSION['cart'];
  20. }
  21. if (empty($cart[$item])) {
  22. $cart[$item] = $qty;
  23. } else {
  24. $cart[$item] += $qty;
  25. }
  26. $_SESSION['cart'] = $cart;
  27. header('Location: ./?page=cart&msg=itemadded');
  28. die();
  29. break;
  30. case "updatecart":
  31. $item = $VARS['item'];
  32. $qty = $VARS['qty'];
  33. $cart = [];
  34. if (!empty($_SESSION['cart'])) {
  35. $cart = $_SESSION['cart'];
  36. }
  37. $cart[$item] = $qty;
  38. if ($qty <= 0) {
  39. unset($cart[$item]);
  40. }
  41. $_SESSION['cart'] = $cart;
  42. header('Location: ./?page=cart&msg=itemupdated');
  43. break;
  44. }