Skip to content

Instantly share code, notes, and snippets.

@shioyama
Created April 16, 2014 00:05
Show Gist options
  • Save shioyama/10791298 to your computer and use it in GitHub Desktop.
Save shioyama/10791298 to your computer and use it in GitHub Desktop.
Spree::OrderPopulator.class_eval do
def populate_with_options(from_hash)
binding.pry
if variants_with_options = from_hash[:variants].select { |variant, quantity| quantity.is_a?(Hash) }
variants_with_options.each do |variant_id, options|
quantity = options.delete(:quantity) || 1
attempt_cart_add(variant_id, quantity)
if (line_item = order.line_items.where(variant_id: variant_id).first)
line_item.assign_options!(options)
end
from_hash[:variants].delete(variant_id)
end
end
populate_without_options(from_hash)
end
alias_method_chain :populate, :options
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment