mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-24 05:38:52 +00:00
Starting to restructure data injection
This commit is contained in:
@@ -2,6 +2,8 @@ Darkswarm.factory 'Cart', (CurrentOrder)->
|
||||
# Handles syncing of current cart/order state to server
|
||||
new class Cart
|
||||
order: CurrentOrder.order
|
||||
line_items: CurrentOrder.order.line_items
|
||||
constructor: ->
|
||||
console.log @order.line_items
|
||||
|
||||
|
||||
# How to structure this?
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ Darkswarm.factory 'Products', ($resource, Enterprises, Dereferencer, Taxons) ->
|
||||
@products = $resource("/shop/products").query (products)=>
|
||||
@extend()
|
||||
@dereference()
|
||||
@loading = false
|
||||
@loading = false
|
||||
@
|
||||
|
||||
dereference: ->
|
||||
|
||||
@@ -4,7 +4,7 @@ module InjectionHelper
|
||||
end
|
||||
|
||||
def inject_current_order
|
||||
inject_json_ams "currentOrder", current_order, Api::CurrentOrderSerializer
|
||||
inject_json_ams "currentOrder", current_order, Api::CurrentOrderSerializer, current_distributor: current_distributor, current_order_cycle: current_order_cycle
|
||||
end
|
||||
|
||||
def inject_available_shipping_methods
|
||||
|
||||
11
app/serializers/api/image_serializer.rb
Normal file
11
app/serializers/api/image_serializer.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Api::ImageSerializer < ActiveModel::Serializer
|
||||
attributes :id, :alt, :small_url, :large_url
|
||||
|
||||
def small_url
|
||||
object.attachment.url(:small, false)
|
||||
end
|
||||
|
||||
def large_url
|
||||
object.attachment.url(:large, false)
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,5 @@
|
||||
class Api::LineItemSerializer < ActiveModel::Serializer
|
||||
attributes :id, :variant_id, :quantity, :price
|
||||
attributes :id, :quantity, :price
|
||||
|
||||
has_one :variant, serializer: Api::VariantSerializer
|
||||
end
|
||||
|
||||
10
app/serializers/api/variant_serializer.rb
Normal file
10
app/serializers/api/variant_serializer.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class Api::VariantSerializer < ActiveModel::Serializer
|
||||
attributes :id, :is_master, :count_on_hand, :name_to_display, :on_demand,
|
||||
:price
|
||||
|
||||
has_many :images, serializer: Api::ImageSerializer
|
||||
|
||||
def price
|
||||
object.price_with_fees(options[:current_distributor], options[:current_order_cycle])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user