Pull shipping method service computations out of the serialization loop

This commit is contained in:
Rohan Mitchell
2015-05-21 12:40:04 +10:00
parent f0e909c92b
commit ee8db23fd9
2 changed files with 5 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
module InjectionHelper
def inject_enterprises
inject_json_ams "enterprises", Enterprise.activated.all, Api::EnterpriseSerializer, active_distributors: @active_distributors, earliest_closing_times: OrderCycle.earliest_closing_times
inject_json_ams "enterprises", Enterprise.activated.all, Api::EnterpriseSerializer, active_distributors: @active_distributors, earliest_closing_times: OrderCycle.earliest_closing_times, shipping_method_services: Spree::ShippingMethod.services
end
def inject_current_order

View File

@@ -42,11 +42,13 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
has_one :address, serializer: Api::AddressSerializer
def pickup
object.shipping_methods.where(:require_ship_address => false).present?
services = options[:shipping_method_services][object.id]
services ? services[:pickup] : false
end
def delivery
object.shipping_methods.where(:require_ship_address => true).present?
services = options[:shipping_method_services][object.id]
services ? services[:delivery] : false
end
def email