mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Starting a basic implementation of the Cart/CurrentOrder so we know whether it's empty
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
Darkswarm.controller "CartCtrl", ($scope, CurrentOrder) ->
|
||||
$scope.CurrentOrder = CurrentOrder
|
||||
@@ -1,10 +1,11 @@
|
||||
Darkswarm.directive "ofnEmptiesCart", (CurrentHub, Navigation) ->
|
||||
Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation) ->
|
||||
restrict: "A"
|
||||
scope:
|
||||
hub: '=ofnEmptiesCart'
|
||||
template: "{{action}} <strong>{{hub.name}}</strong>"
|
||||
link: (scope, elm, attr)->
|
||||
if CurrentHub.id and CurrentHub.id isnt scope.hub.id
|
||||
# A hub is selected, we're changing to a different hub, and the cart isn't empty
|
||||
if CurrentHub.id and CurrentHub.id isnt scope.hub.id and not CurrentOrder.empty()
|
||||
scope.action = attr.change
|
||||
elm.bind 'click', (ev)->
|
||||
ev.preventDefault()
|
||||
@@ -12,5 +13,3 @@ Darkswarm.directive "ofnEmptiesCart", (CurrentHub, Navigation) ->
|
||||
Navigation.go scope.hub.path
|
||||
else
|
||||
scope.action = attr.shop
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Darkswarm.factory 'CurrentOrder', (currentOrder) ->
|
||||
new class CurrentOrder
|
||||
constructor: ->
|
||||
@[k] = v for k, v of currentOrder
|
||||
|
||||
empty: =>
|
||||
@line_items.length == 0
|
||||
13
app/views/json/_current_order.rabl
Normal file
13
app/views/json/_current_order.rabl
Normal file
@@ -0,0 +1,13 @@
|
||||
object current_order
|
||||
attributes :id, :item_total
|
||||
|
||||
if current_order
|
||||
child line_items: :line_items do
|
||||
attributes :id, :variant_id, :quantity, :price
|
||||
end
|
||||
|
||||
node :cart_count do
|
||||
cart_count
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
%body.off-canvas{"ng-app" => "Darkswarm"}
|
||||
= inject_json "currentHub", "current_hub"
|
||||
= inject_json "currentOrder", "current_order"
|
||||
= inject_json "user", "current_user"
|
||||
|
||||
.off-canvas-wrap{offcanvas: true}
|
||||
|
||||
5
app/views/shared/menu/_cart.html.haml
Normal file
5
app/views/shared/menu/_cart.html.haml
Normal file
@@ -0,0 +1,5 @@
|
||||
%a.icon{href: cart_url, "ng-controller" => "CartCtrl"}
|
||||
%i.fi-shopping-cart.nav-branded
|
||||
%span
|
||||
{{ CurrentOrder.cart_count }}
|
||||
items
|
||||
@@ -43,8 +43,4 @@
|
||||
%span.nav-primary.nav-branded {{ CurrentHub.name }}
|
||||
%li.divider
|
||||
%li.cart
|
||||
%a.icon{href: cart_url}
|
||||
%i.fi-shopping-cart.nav-branded
|
||||
%span
|
||||
= cart_count
|
||||
items
|
||||
= render partial: "shared/menu/cart"
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
%a.left-off-canvas-toggle.menu-icon
|
||||
%span
|
||||
%section.right
|
||||
%a.nav-branded.icon{href: cart_url}
|
||||
%i.fi-shopping-cart
|
||||
%span
|
||||
= cart_count
|
||||
items
|
||||
= render partial: "shared/menu/cart"
|
||||
%a{href: main_app.shop_path}
|
||||
{{ CurrentHub.name }}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user