spree-multi-domain icon indicating copy to clipboard operation
spree-multi-domain copied to clipboard

Product gets dissociated of its current stores due to callback misbehavior

Open horacio opened this issue 10 years ago • 2 comments

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.

horacio avatar Dec 19 '14 00:12 horacio

what about removing the callback ? the stores the product belongs to, keep their checked state if the details or the attributes are updated

blset avatar Mar 31 '16 07:03 blset

Do we have any update on this? the same behaviour for:

  • spree-multi-domain rev: 04aefcfe6630b34ed05c0ec14cb904ee886437e5
  • spree ver 3.2.1

amalkov avatar Jul 13 '17 08:07 amalkov