Commits

Rhys ! committed 7945057

hoodies can now be added to cart

  • Participants
  • Parent commits 8666371

Comments (0)

Files changed (5)

-window.cart_items = ->
-    cart = $.cookie 'cart'
-    if cart
-        return cart.split ';'
-    else
-        return []
-
-window.update_cart = (code, quantity) ->
-    cart = cart_items()
-    if code not in cart
-        cart.push code
-        $.cookie 'cart', cart.join ';'
-    $.cookie code, quantity
-
-window.store_item = (code, props) ->
-    localStorage.setItem code, props.join ';'
-
-window.retr_item = (code) ->
-    props = localStorage.getItem(code)
-    if props
-        return props.split ';'
-    else
-        return null
-
-window.remove_from_cart = (code) ->
-    cart = cart_items()
-    loc = cart.indexOf code
-    if loc >= 0
-        cart = cart.slice(0, loc).concat cart.slice loc + 1
-        $.cookie 'cart', cart.join ';'
-    $.cookie code, null
-
-window.clear_cart = ->
-    for code in cart_items()
-        $.cookie code, null
-    $.cookie 'cart', null
-
 item_row = (code, editable) ->
     data = retr_item code
     quantity = $.cookie(code) or 1

site/global.coffee

-get_parameter = (name) ->
-    match = RegExp('[?&]' + name + '=([^&]*)').exec window.location.search
-    return match && decodeURIComponent match[1].replace /\+/g, ' '
+window.cart_items = ->
+    cart = $.cookie 'cart'
+    if cart
+        return cart.split ';'
+    else
+        return []
+
+window.update_cart = (code, quantity) ->
+    cart = cart_items()
+    if code not in cart
+        cart.push code
+        $.cookie 'cart', cart.join ';'
+    $.cookie code, quantity
+
+window.store_item = (code, props) ->
+    localStorage.setItem code, props.join ';'
+
+window.retr_item = (code) ->
+    props = localStorage.getItem(code)
+    if props
+        return props.split ';'
+    else
+        return null
+
+window.remove_from_cart = (code) ->
+    cart = cart_items()
+    loc = cart.indexOf code
+    if loc >= 0
+        cart = cart.slice(0, loc).concat cart.slice loc + 1
+        $.cookie 'cart', cart.join ';'
+    $.cookie code, null
+
+window.clear_cart = ->
+    for code in cart_items()
+        $.cookie code, null
+    $.cookie 'cart', null
 
 window.url_basename = (url) ->
     li = url.lastIndexOf('/') + 1
     else
         return url.substring li, url.length
 
+get_parameter = (name) ->
+    match = RegExp('[?&]' + name + '=([^&]*)').exec window.location.search
+    return match && decodeURIComponent match[1].replace /\+/g, ' '
+
 $ ->
     cur_bn = url_basename(document.location.pathname) or 'index.php'
     $('#left a').each ->

site/hoodies.coffee

+$ ->
+    $('form').submit ->
+        form = $(this)
+        size = form.find('input[name="size"]:checked')
+        if size.length
+            size = size.val()
+            color = form.data('color')
+            id = "#{color}-#{size}-hoodie"
+            store_item id, ["#{size} #{color} Varsity Hoodie", "Clothing", "Swinburne", "12345678", "20", "$69.95"]
+            update_cart id, 1
+            return true
+        else
+            alert 'You must select a size first.'
+            return false

site/product_hoodies.shpaml

 {{enddef}}
 {{py: global left_insert; left_insert = {'Product list': bins()} }}
 {{def title}}Varsity Hoodies{{enddef}}
+{{def script}}hoodies{{enddef}}
 ul.breadcrumb
     li
         >
                 strong | {{color.replace('_', ' ').title()}} Hoodie
             p
                 {{pcolor}} Print $69.95
-            form.table
+            form.table method=get action=cart.php data-color="{{color.replace('_', ' ').title()}}"
                 div
-                    > input type=checkbox name=size value=XXS id=size-XXS
+                    > input type=radio name=size value=XXS id=size-XXS
                     label for=size-XXS | XXS
                 div
-                    > input type=checkbox name=size value=XS id=size-XS
+                    > input type=radio name=size value=XS id=size-XS
                     label for=size-XS | XS
                 div
-                    > input type=checkbox name=size value=S id=size-S
+                    > input type=radio name=size value=S id=size-S
                     label for=size-S | Small
                 div
-                    > input type=checkbox name=size value=M id=size-M
+                    > input type=radio name=size value=M id=size-M
                     label for=size-M | Medium
                 div
-                    > input type=checkbox name=size value=L id=size-L
+                    > input type=radio name=size value=L id=size-L
                     label for=size-L | Large
                 div
-                    > input type=checkbox name=size value=XL id=size-XL
+                    > input type=radio name=size value=XL id=size-XL
                     label for=size-XL | XL
                 div
-                    > input type=checkbox name=size value=XXL id=size-XXL
+                    > input type=radio name=size value=XXL id=size-XXL
                     label for=size-XXL | XXL
                 div
-                    > input type=checkbox name=size value=3XL id=size-3XL
+                    > input type=radio name=size value=3XL id=size-3XL
                     label for=size-3XL | 3XL
                 div
-                    > input type=checkbox name=size value=4XL id=size-4XL
+                    > input type=radio name=size value=4XL id=size-4XL
                     label for=size-4XL | 4XL
                 div
-                    > input type=checkbox name=size value=5XL id=size-5XL
+                    > input type=radio name=size value=5XL id=size-5XL
                     label for=size-5XL | 5XL
                 > input type=submit value="Add to cart"
   {{endfor}}

site/product_list.shpaml

 .panel
     ul
         li
-            > img src=https://bookshop.swin.edu.au/html/images/product/black_hoodie.jpg
-            a href=product_hoodies.php | Varsity Hoodies
+            a href=product_hoodies.php
+                > img src=https://bookshop.swin.edu.au/html/images/product/black_hoodie.jpg
+                Varsity Hoodies
             p | Be proud and show off your University to everyone you meet