Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add access to abilities in import and make `ProductVariant` processor… (#13212)
Damian Legawiece6b1dcb17b59
diff --git a/core/app/models/spree/import.rb b/core/app/models/spree/import.rbindex eff4f371cc..86da885cdd 100644--- a/core/app/models/spree/import.rb+++ b/core/app/models/spree/import.rb@@ -172,6 +172,11 @@ module Spreebroadcast_update_to "import_#{id}_loader", target: 'loader', partial: 'spree/admin/imports/loader', locals: { import: self }end++ def current_ability+ @current_ability ||= Spree::Dependencies.ability_class.constantize.new(user, { store: store })+ end+class << selfdef available_typesRails.application.config.spree.import_typesdiff --git a/core/app/services/spree/imports/row_processors/product_variant.rb b/core/app/services/spree/imports/row_processors/product_variant.rbindex dce397fa60..670d754682 100644--- a/core/app/services/spree/imports/row_processors/product_variant.rb+++ b/core/app/services/spree/imports/row_processors/product_variant.rb@@ -54,10 +54,20 @@ module Spreedef ensure_product_existsproduct = Spree::Product.newif attributes['slug'].present?- existing_product = Spree::Product.find_by(slug: attributes['slug'].strip.downcase)+ existing_product = product_scope.find_by(slug: attributes['slug'].strip.downcase)product = existing_product if existing_product.present?end+ product = assign_attributes_to_product(product)+ product.save!+ product+ end++ def product_scope+ Spree::Product.accessible_by(import.current_ability, :manage)+ end++ def assign_attributes_to_product(product)# setting SKU for master variant so it will be picked up in process! and won't try to create a non-master variantif product.new_record?product.slug = attributes['slug']@@ -74,8 +84,6 @@ module Spreeproduct.tag_list = attributes['tags'] if attributes['tags'].present?product.taxons = prepare_taxons if options.empty?-- product.save!productend