From 779be7c5a0657d1fccba5cf35dfe197a4f3843e1 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 21 Apr 2016 16:37:15 +1000 Subject: [PATCH] Extract params parsing into single method --- app/models/spree/order_populator_decorator.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/spree/order_populator_decorator.rb b/app/models/spree/order_populator_decorator.rb index 82d9aa85e7..38c908a530 100644 --- a/app/models/spree/order_populator_decorator.rb +++ b/app/models/spree/order_populator_decorator.rb @@ -11,8 +11,7 @@ Spree::OrderPopulator.class_eval do if valid? @order.with_lock do - variants = read_products_hash(from_hash) + - read_variants_hash(from_hash) + variants = read_variants from_hash variants.each do |v| if varies_from_cart(v) @@ -31,6 +30,11 @@ Spree::OrderPopulator.class_eval do valid? end + def read_variants(data) + read_products_hash(data) + + read_variants_hash(data) + end + def read_products_hash(data) (data[:products] || []).map do |product_id, variant_id| {variant_id: variant_id, quantity: data[:quantity]}