spree-multi-domain
spree-multi-domain copied to clipboard
Product gets dissociated of its current stores due to callback misbehavior
Related (hopefully) to #97.
Currently, the set_stores
callback is called before an update is made to a Product
or to one of its associations via nested attributes. In the latter case, this causes the product to dissociate from the store (or stores) because the store_ids
aren't passed in the parameters, effectively meeting the condition which I think was meant to work only if you are editing the product details, specifically, if this product would be part of this or that store. This is indeed buggy behavior.
The following feels like a sketchy workaround, but it does the job:
def set_stores
if user_comes_from_product_details? && no_stores_selected?
@product.store_ids = nil
end
end
def user_comes_from_product_details?
params = Spree::Core::Engine.routes.recognize_path(request.referer)
params[:controller] == "spree/admin/products" && params[:action] == "edit"
end
def no_stores_selected?
params[:product][:store_ids].blank?
end
Does any of this make any sense? Could I achieve what I want in another, better way?
Thanks a lot,
H.
what about removing the callback ? the stores the product belongs to, keep their checked state if the details or the attributes are updated
Do we have any update on this? the same behaviour for:
- spree-multi-domain rev: 04aefcfe6630b34ed05c0ec14cb904ee886437e5
- spree ver 3.2.1