Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Product gets dissociated of its current stores due to callback misbehavior #114

Open
horacio opened this issue Dec 19, 2014 · 2 comments
Open

Comments

@horacio
Copy link

horacio commented Dec 19, 2014

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.

@blset
Copy link

blset commented Mar 31, 2016

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

@amalkov
Copy link

amalkov commented Jul 13, 2017

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

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants