Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide the master variants from stock management #4155

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Hide the master variants from stock management
This PR hides the master variants from the stock management list if the product has variants. This prevents a strange experience when managing inventory for these products - they don't really have SKUs, and aren't sellable in the general case.
  • Loading branch information
tmtrademarked committed Aug 27, 2021
commit 9cf55e511a1f2b710e6a9bb8a10b92db74f67a38
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ def load_stock_management_data

def variant_scope
scope = Spree::Variant.accessible_by(current_ability)
scope = scope.where(product: @product) if @product
if @product
scope = scope.where(
product: @product,
is_master: [email protected]_variants?
)
end
scope = scope.order(:sku)
scope
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,45 @@ module Admin
describe "#index" do
let!(:variant_1) { create(:variant) }
let!(:variant_2) { create(:variant) }
let!(:product_1) { create(:product) }
let!(:product_2) { create(:product) }
let!(:variant_3) { create(:variant, product: product_2) }
let!(:variant_4) { create(:variant, product: product_2) }

context "with product_slug param" do
it "scopes the variants by the product" do
get :index, params: { product_slug: variant_1.product.slug }
expect(assigns(:variants)).to include variant_1
expect(assigns(:variants)).not_to include variant_2
expect(assigns(:variants)).to contain_exactly(variant_1)
end

context "when a product with no variants is requested" do
it "returns the master variant of the product" do
get :index, params: { product_slug: product_1.slug }
expect(assigns(:variants)).to contain_exactly(product_1.master)
end
end

context "when a product with variants is requested" do
it "returns only the variants of the product" do
get :index, params: { product_slug: product_2.slug }
expect(assigns(:variants)).to contain_exactly(variant_3, variant_4)
end
end
end

context "without product_slug params" do
it "allows all accessible variants to be returned" do
get :index
expect(assigns(:variants)).to include variant_1
expect(assigns(:variants)).to include variant_2
expect(assigns(:variants)).to contain_exactly(
variant_1,
variant_1.product.master,
variant_2,
variant_2.product.master,
product_1.master,
product_2.master,
variant_3,
variant_4
)
end
end
end
Expand Down