1
0

item_cart.qsrc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # item_cart
  2. if $ARGS[0] = 'shoppping_aisle':
  3. gs 'item_stock_db', 'cleanup'
  4. $curr_aisle = $ARGS[1]
  5. gs 'item_stock_db', $ARGS[1]
  6. !! Page Header
  7. '<center><table border=5 cellspacing=0 cellpadding=5 bgcolor='+$bcolor+'><TD>&nbsp;<font size="+2"><b><<$shop_title>></b></font>&nbsp;</TD></table></center>'
  8. !! Table Headers
  9. *p '<center><table border=5 cellspacing=0 cellpadding=5 bgcolor='+$bcolor+' width="80%"><TR><TH>Item</TH><TH>You own</TH><TH>Units/pack</TH><TH>Cost in <b>₽</b></TH><TH colspan="2" width="12%">Remove 10/1</TH><TH width="8%">In cart</TH><TH colspan="2" width="12%">Add 1/10</TH></TR>'
  10. !! Table Rows
  11. $icon_selector = iif(theme['is_dark'] = 0, '_b', '_w')
  12. icon_height = fsize * 15 / 10
  13. i = 1
  14. :loopshopping_cart
  15. !! if item is uninitialized (has blank name) - skip it
  16. if $item_curr_aisle['<<i>>'] = '': i += 1 & jump 'loopshopping_cart'
  17. $temp_bcolor = func('themes', 'alt_color', $temp_bcolor)
  18. $item_line = '<TR bgcolor='+$temp_bcolor+'>'
  19. $item_line += '<TD align="left"><<$item_curr_aisle[''<<i>>'']>></TD>'
  20. $cart_tmp = $var_curr_aisle['<<i>>']
  21. $item_line += '<TD><<mc_inventory[''<<$cart_tmp>>'']>></TD>'
  22. $item_line += '<TD><<quantity_curr_aisle[''<<i>>'']>></TD>'
  23. $item_line += '<TD><<cost_curr_aisle[''<<i>>'']>></TD>'
  24. if cart_curr_quantity['<<i>>'] > 0:
  25. $item_line += '<TD valign="center" align="center" width="6%"><a href="exec:gt ''item_cart'', ''remove'', <<i>>, 10"><img src="images/system/ui/less<<$icon_selector>>.png" height="<<icon_height>>"></a></TD>'
  26. $item_line += '<TD valign="center" align="center" width="6%"><a href="exec:gt ''item_cart'', ''remove'', <<i>>, 1"><img src="images/system/ui/less<<$icon_selector>>.png" height="<<icon_height>>"></a></TD>'
  27. else
  28. $item_line += '<TD></TD><TD></TD>'
  29. end
  30. $item_line += '<TD align="center"><<cart_curr_quantity[''<<i>>'']>></TD>'
  31. if max_curr_aisle['<<i>>'] > cart_curr_quantity['<<i>>'] + mc_inventory['<<$cart_tmp>>'] or max_curr_aisle['<<i>>'] = 0:
  32. $item_line += '<TD valign="center" align="center" width="6%"><a href="exec:gt ''item_cart'', ''add'', <<i>>, 1"><img src="images/system/ui/more<<$icon_selector>>.png" height="<<icon_height>>"></a></TD>'
  33. $item_line += '<TD valign="center" align="center" width="6%"><a href="exec:gt ''item_cart'', ''add'', <<i>>, 10"><img src="images/system/ui/more<<$icon_selector>>.png" height="<<icon_height>>"></a></TD>'
  34. else
  35. $item_line += '<TD align="center" colspan="2" width="6%">Max</TD>'
  36. end
  37. $item_line += '</TR>'
  38. *p $item_line
  39. i += 1
  40. if i <= item_idx:jump 'loopshopping_cart'
  41. '</table></center>'
  42. killvar '$temp_bcolor' & killvar '$icon_selector' & killvar 'icon_height'
  43. !! Checkout
  44. gs 'item_cart', 'cart_total'
  45. end
  46. if $ARGS[0] = 'remove':
  47. ARGS[2] = min(cart_curr_quantity['<<ARGS[1]>>'], ARGS[2])
  48. cart_tally -= cost_curr_aisle['<<ARGS[1]>>'] * ARGS[2]
  49. cart_curr_quantity['<<ARGS[1]>>'] -= ARGS[2]
  50. gt $loc_s, $args_s
  51. end
  52. if $ARGS[0] = 'add':
  53. ARGS[2] = iif(max_curr_aisle['<<ARGS[1]>>'] ! 0, min(max_curr_aisle['<<ARGS[1]>>'] - (cart_curr_quantity['<<ARGS[1]>>'] + mc_inventory[$var_curr_aisle['<<ARGS[1]>>']]), ARGS[2]), ARGS[2])
  54. cart_tally += cost_curr_aisle['<<ARGS[1]>>'] * ARGS[2]
  55. cart_curr_quantity['<<ARGS[1]>>'] += ARGS[2]
  56. if $event_curr_aisle['<<ARGS[1]>>'] ! '': dynamic "<<$event_curr_aisle['<<ARGS[1]>>']>>"
  57. gt $loc_s, $args_s
  58. end
  59. if $ARGS[0] = 'simple_add':
  60. cart_tally += cost_curr_aisle['<<ARGS[1]>>'] * max(1, ARGS[2])
  61. cart_curr_quantity['<<ARGS[1]>>'] += 1 * max(1, ARGS[2])
  62. end
  63. if $ARGS[0] = 'cart_total':
  64. '<center><table border=5 cellspacing=0 cellpadding=5 bgcolor='+$bcolor+'><TD>&nbsp;<b>Total cost of items in cart: <<cart_tally>>₽</b>&nbsp;</TD></table></center>'
  65. *p '<center><table border=5 cellspacing=0 cellpadding=5 bgcolor='+$bcolor+'><TR>'
  66. $item_line[2] = ''
  67. if cart_tally > 0:
  68. if karta < cart_tally and money < cart_tally:
  69. $item_line[2] = '<TD>&nbsp;You cannot afford this&nbsp;</TD>'
  70. else
  71. if money >= cart_tally:
  72. $item_line[2] = '<TD>&nbsp;<a href="exec:gt ''item_cart'', ''cash'', <<i>>">Buy (cash)</a>&nbsp;</TD>'
  73. else
  74. $item_line[2] = '<TD>&nbsp;Not enough cash&nbsp;</TD>'
  75. end
  76. if karta >= cart_tally:
  77. $item_line[2] += '<TD>&nbsp;<a href="exec:gt ''item_cart'', ''card'', <<i>>">Buy (card)</a>&nbsp;</TD>'
  78. else
  79. $item_line[2] += '<TD>&nbsp;Not enough on card&nbsp;</TD>'
  80. end
  81. end
  82. end
  83. $item_line[2] += '<TD>&nbsp;<a href="exec:gt ''item_cart'', ''cancel''">cancel</a>&nbsp;</TD>'
  84. $item_line[2] += '</TR></table></center>'
  85. *p $item_line[2]
  86. end
  87. if $ARGS[0] = 'cash':
  88. i = 1
  89. :loopshopping_cash
  90. $cart_tmp1 = $var_curr_aisle['<<i>>']
  91. dynamic 'cart_quantity = quantity_curr_aisle[''<<i>>''] * cart_curr_quantity[''<<i>>'']'
  92. dynamic 'mc_inventory[''<<$cart_tmp1>>''] += cart_quantity'
  93. i += 1
  94. if i <= item_idx:jump 'loopshopping_cash'
  95. money -= cart_tally
  96. gs 'item_cart', 'shopping_var_clear'
  97. gt $loc_s, $args_s
  98. end
  99. if $ARGS[0] = 'card':
  100. i = 1
  101. :loopshopping_card
  102. $cart_tmp1 = $var_curr_aisle['<<i>>']
  103. dynamic 'cart_quantity = quantity_curr_aisle[''<<i>>''] * cart_curr_quantity[''<<i>>'']'
  104. dynamic 'mc_inventory[''<<$cart_tmp1>>''] += cart_quantity'
  105. i += 1
  106. if i <= item_idx:jump 'loopshopping_card'
  107. karta -= cart_tally
  108. gs 'item_cart', 'shopping_var_clear'
  109. gt $loc_s, $args_s
  110. end
  111. if $ARGS[0] = 'cancel':
  112. gs 'item_cart', 'shopping_var_clear'
  113. gt $loc_s, $args_s
  114. end
  115. if $ARGS[0] = 'shopping_var_clear':
  116. !! clean up all transient variables/arrays.
  117. killvar 'cart_tally'
  118. killvar 'cart_curr_quantity'
  119. killvar 'cart_quantity'
  120. killvar '$cart_tmp'
  121. killvar '$cart_tmp1'
  122. gs 'item_stock_db', 'cleanup'
  123. end
  124. --- item_cart ---------------------------------