0

Hi I tried to add a product in spree using the supplier login. I have two gems related to spree marketplace installed

gem 'spree_drop_ship', github: 'spree-contrib/spree_drop_ship', branch: '3-0-stable'
gem 'spree_marketplace', github: 'firman/spree_marketplace'

Also, I updated my ability decorator to provide related authority using

if user.has_spree_role? "supplier"
        can [:admin, :manage, :index, :create, :update], Spree::Product do |product|
          product.supplier_ids.include?(user.supplier_id)
        end
end

I can see the form to add the product but when I add basic product details and click on create, it give me Authorization Failure error Please suggest what should I do to resolve the issue.

Update: I debugged the app and found there was some migration files missing, when I migrated db, I could see the supplier_id column in spree_products, but when I added new product using the supplier login, same error was being thrown as unauthorized, I checked with database the supplier_id column was NULL.

Where should I make changes so that correct supplier id is stored in spree_products

Mahi L
  • 75
  • 1
  • 5

1 Answers1

0

The product is created but not associated to supplier, then raise an authorization failure on edit because that product has no supplier.

You are using the 3-0-stable branch and that branch is missing an important method. Please see the 2-4-stable branch and copy the add_product_to_supplier method to your Spree::Admin::ProductsControllers.

Spree::Admin::ProductsController.class_eval do
  create.after :add_product_to_supplier

  # Newly added products by a Supplier are associated with it.
  def add_product_to_supplier
    if try_spree_current_user && try_spree_current_user.supplier?
      @product.add_supplier!(try_spree_current_user.supplier_id)
    end
  end
end