고객이 지정된 요일에 배달 될 제품을 주문할 수있는 Spree 기반 프로그램이 있습니다. 올바른 제품으로 여러 주문을 생성하기 위해 주문 생성 로직을 재정의하려고 시도하고 있습니다. 나는 Spree source에서 그대로 꽤 많은 코드를 뽑아프로그래밍 방식으로 생성 된 Spree 주문 항목이 관리 인터페이스에 표시되지 않음
class OrderController < ApplicationController
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Order
include Spree::Core::ControllerHelpers::Common
⋮
def process_order
params[:order].each do |index, order|
products = []
order[:product_id].each do |index, id|
products << Spree::Product.find(id) if id and not id.empty?
end
if products.any?
populator = Spree::OrderPopulator.new current_order(create_order_if_necessary: true), current_currency
current_order.update_attribute :delivery_date, Date.parse(order[:date])
products.each do |product|
variant = Spree::Variant.find_by product_id: product.id
populator.populate({ products: { product_id: product.id, variant_id: variant.id }, quantity: 1 })
end
end
end
redirect_to main_path
end
end
: 같은
양식 게시물을 처리하는 방법을 보인다. 주문이 만들어지고 order.products 메서드가 작동합니다. 그러나 관리 인터페이스에서 주문을 볼 때 가격은 있지만 제품은 없습니다. 관리 인터페이스를 통해 제품을 추가하면 프로그래밍 방식으로 추가 된 제품 수를 포함한 제품 수가 표시됩니다.
관리자 인터페이스를 통해 주문을 완료하면 모든 제품이 완료된 주문으로 표시됩니다.