Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fix three findings from review

Damian Legawiec4bdd31d8e04b
diff --git a/packages/dashboard-core/src/products/variants-options-builder.tsx b/packages/dashboard-core/src/products/variants-options-builder.tsx
index 8a68e74b5f..9724d38fad 100644
--- a/packages/dashboard-core/src/products/variants-options-builder.tsx
+++ b/packages/dashboard-core/src/products/variants-options-builder.tsx
@@ -305,6 +305,10 @@ interface OptionPickerProps {
function OptionPicker({ optionType, initialValues, onSave, onCancel }: OptionPickerProps) {
const { t } = useTranslation()
const updateOptionType = useUpdateOptionType(optionType.id)
+ // Adding a value to an option type edits the store's own vocabulary, so it
+ // needs the write the create button needs — a panel that can list types but
+ // not update them would render an action whose mutation has nowhere to go.
+ const canAddValue = Boolean(getApiClient().optionTypes?.update)
const [pickedNames, setPickedNames] = useState<Set<string>>(
() => new Set(initialValues.map((v) => v.name)),
)
@@ -388,14 +392,16 @@ function OptionPicker({ optionType, initialValues, onSave, onCancel }: OptionPic
</button>
)
})}
- <button
- type="button"
- onClick={() => setCreatingValue(true)}
- className="inline-flex items-center gap-1.5 rounded-full border border-dashed border-border bg-background px-3 py-1 text-xs hover:bg-muted"
- >
- <PlusIcon className="size-3" />
- {t('admin.products.variants.create_value')}
- </button>
+ {canAddValue && (
+ <button
+ type="button"
+ onClick={() => setCreatingValue(true)}
+ className="inline-flex items-center gap-1.5 rounded-full border border-dashed border-border bg-background px-3 py-1 text-xs hover:bg-muted"
+ >
+ <PlusIcon className="size-3" />
+ {t('admin.products.variants.create_value')}
+ </button>
+ )}
</div>
<div className="flex items-center justify-end gap-2">
<Button type="button" variant="outline" size="sm" onClick={onCancel}>
diff --git a/packages/dashboard/e2e/seller-catalog.spec.ts b/packages/dashboard/e2e/seller-catalog.spec.ts
index d0367a2cd6..170d00a243 100644
--- a/packages/dashboard/e2e/seller-catalog.spec.ts
+++ b/packages/dashboard/e2e/seller-catalog.spec.ts
@@ -103,7 +103,9 @@ test.describe('seller catalog and orders', () => {
await expect(sellerPage.getByRole('heading', { name: /orders/i })).toBeVisible({
timeout: 20_000,
})
- await expect(sellerPage.getByText(/something went wrong/i)).toHaveCount(0)
+ // The empty state itself, not merely the absence of an error: a blank
+ // page would satisfy "no error" just as well as a working one.
+ await expect(sellerPage.getByText(/no orders yet/i)).toBeVisible({ timeout: 20_000 })
} finally {
await context.close()
}
diff --git a/spree/core/app/workflows/spree/products/propose.rb b/spree/core/app/workflows/spree/products/propose.rb
index 0506cbe587..5b90531908 100644
--- a/spree/core/app/workflows/spree/products/propose.rb
+++ b/spree/core/app/workflows/spree/products/propose.rb
@@ -16,7 +16,14 @@ module Spree
def perform(product:)
super
- reject!(Spree.t('activerecord.errors.models.spree/product.attributes.base.cannot_propose')) if product.active?
+ # Only a listing that is being worked on can be submitted. Guarding
+ # `active?` alone let an archived product through — and with
+ # auto-approval on, a withdrawn listing went straight back on sale
+ # without anybody reviewing it. Re-submitting one already in review
+ # is equally meaningless.
+ unless product.draft? || product.rejected?
+ reject!(Spree.t('activerecord.errors.models.spree/product.attributes.base.cannot_propose'))
+ end
run_hooks :validate
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index f04a29cc9a..571ebf6b84 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -338,7 +338,7 @@ en:
attributes:
base:
cannot_destroy_if_attached_to_line_items: Cannot delete Products that are added to placed Orders. In such cases, please discontinue them.
- cannot_propose: This product is already on sale.
+ cannot_propose: Only a draft or a product needing changes can be submitted for review.
not_awaiting_review: This product is not awaiting review.
discontinue_on:
invalid_date_range: must be later than available date
diff --git a/spree/core/spec/workflows/spree/products/review_spec.rb b/spree/core/spec/workflows/spree/products/review_spec.rb
index a08d5da501..687da63608 100644
--- a/spree/core/spec/workflows/spree/products/review_spec.rb
+++ b/spree/core/spec/workflows/spree/products/review_spec.rb
@@ -24,6 +24,23 @@ RSpec.describe 'Spree::Products review workflows' do
expect(product.reload).to be_active
end
+ # Auto-approval makes this the sharp one: without the guard an archived
+ # listing went straight back on sale with nobody reviewing it.
+ it 'refuses an archived product' do
+ product.update!(status: 'archived')
+
+ result = Spree.product_propose_workflow.call(product: product)
+
+ expect(result).not_to be_success
+ expect(product.reload).to be_archived
+ end
+
+ it 'refuses one already awaiting review' do
+ product.update!(status: 'proposed')
+
+ expect(Spree.product_propose_workflow.call(product: product)).not_to be_success
+ end
+
it 'resubmits a rejected product' do
product.update!(status: 'rejected')