Last active
June 15, 2016 07:10
-
-
Save WietseWind/7949712c6c700f9fa6a1d9720da03a39 to your computer and use it in GitHub Desktop.
nodum.io - Cart (JSON) + Cart Modify (Winkelwagentje in nodum)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% if param.postAllRaw() %} | |
| {% set cart = session.get.cart|default({}) %} | |
| {% set postdata = { | |
| code : param.postAllRaw().code|s, | |
| title : param.postAllRaw().title, | |
| count : param.postAllRaw().count|default(1)|i | |
| } %} | |
| {% if cart[param.postAllRaw().code] %} | |
| {% set postdata = postdata|merge({ count : ( postdata.count + cart[param.postAllRaw().code].count|i ) }) %} | |
| {% endif %} | |
| {% set cart = cart|merge({ (param.postAllRaw().code) : postdata })|assoc('code') %} | |
| {% do session.set('cart', cart) %} | |
| {% endif %} | |
| {{ { done: true, numItems : cart|length, cart: cart, item: postdata.code }|json_encode }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% for d in session.get.cart %} | |
| <tr class="" rel="{{ (d.code ~ ' ' ~ d.title)|lower|preg_replace('@[^a-z0-9]@',' ')|trim }}"> | |
| <td class="item">{{ d.code }}</td> | |
| <td class="title">{{ d.title }}</td> | |
| <td class="text-right amount"> | |
| <input type="number" name="order[{{ d.code }}]" value="{{ d.count }}" min="1" max="10000" class="form-control order input-sm" /> | |
| </td> | |
| <td class="text-right buttons"> | |
| <a href="{{ baselocation ~ folder }}/{{ page }}?remove={{ d.code|e('url') }}" class="btn btn-xs btn-rood cart text-center"> | |
| <i class="fa fa-fw fa-trash"></i> | |
| </a> | |
| </td> | |
| </tr> | |
| {% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% set changed = false %} | |
| {% if param.getAllRaw().remove or param.postAllRaw.order %} | |
| {% set cart = [] %} | |
| {% for c in session.get.cart %} | |
| {% if c.code != param.getAllRaw().remove %} | |
| {% if param.postAllRaw.order[c.code] and c.count != param.postAllRaw.order[c.code] %} | |
| {% set changed = true %} | |
| {% endif %} | |
| {% set c = c|merge({ count : (param.postAllRaw.order[c.code]|default(c.count))|i }) %} | |
| {% set cart = cart|merge([ c ]) %} | |
| {% else %} | |
| {% set changed = true %} | |
| {% endif %} | |
| {% endfor %} | |
| {% do session.set('cart', cart) %} | |
| {% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% if param.postAllRaw.order and not changed %} | |
| {# Verzonden maar aantal niet gewijzigd #} | |
| <p class="alert alert-groen text-center"> | |
| <b>{{ 'Je order wordt verwerkt, dank je wel!'|t }}</b> | |
| </p> | |
| <a href="{{ baselocation ~ folder }}" class="btn btn-blauw pull-right"><i class="fa fa-arrow-left"></i>{{ 'Terug'|t }}</a> | |
| <br clear="both" /> | |
| {% do orders.set({ | |
| 'from' : session.get.afas_sso|a, | |
| 'cart' : session.get.cart|assoc('code'), | |
| moment : { '$date' : 'now'|date('U') }, | |
| processed : false, | |
| error : false | |
| }) %} | |
| {% do session.remove('cart') %} | |
| {% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment