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.

Show which seller supplies a product, and fix the review messages

Damian Legawiec663cbe06809a
diff --git a/packages/dashboard/src/components/spree/products/product-seller-card.tsx b/packages/dashboard/src/components/spree/products/product-seller-card.tsx
new file mode 100644
index 0000000000..01d5494f34
--- /dev/null
+++ b/packages/dashboard/src/components/spree/products/product-seller-card.tsx
@@ -0,0 +1,58 @@
+import type { Product } from '@spree/admin-sdk'
+import { getInitials } from '@spree/dashboard-core'
+import {
+ Avatar,
+ AvatarFallback,
+ AvatarImage,
+ Card,
+ CardContent,
+ CardHeader,
+ CardTitle,
+ StatusBadge,
+} from '@spree/dashboard-ui'
+import { Link } from '@tanstack/react-router'
+import { useTranslation } from 'react-i18next'
+
+/**
+ * Who supplies this product.
+ *
+ * Only rendered for a seller's product — the marketplace's own listings have
+ * no seller, and an empty card saying so on every first-party product would
+ * be noise. The seller's status rides along because a product from a
+ * suspended seller is not on sale whatever the product's own status says.
+ */
+export function ProductSellerCard({ product }: { product: Product }) {
+ const { t } = useTranslation()
+
+ if (!product.seller_id) return null
+
+ const name = product.seller?.name ?? product.seller_name ?? product.seller_id
+
+ return (
+ <Card>
+ <CardHeader>
+ <CardTitle>{t('admin.products.seller.title')}</CardTitle>
+ </CardHeader>
+ <CardContent className="flex items-center gap-3">
+ <Avatar className="size-8">
+ {product.seller?.logo_url && <AvatarImage src={product.seller.logo_url} alt="" />}
+ <AvatarFallback>{getInitials(name, '?')}</AvatarFallback>
+ </Avatar>
+ <div className="flex min-w-0 flex-col">
+ <Link
+ to={'/$storeId/sellers/$sellerId' as string}
+ params={{ sellerId: product.seller_id }}
+ className="truncate font-medium text-foreground no-underline"
+ >
+ {name}
+ </Link>
+ {product.seller?.status && (
+ <span className="mt-1">
+ <StatusBadge status={product.seller.status} />
+ </span>
+ )}
+ </div>
+ </CardContent>
+ </Card>
+ )
+}
diff --git a/packages/dashboard/src/hooks/use-product.ts b/packages/dashboard/src/hooks/use-product.ts
index 1aa0497761..c67969f389 100644
--- a/packages/dashboard/src/hooks/use-product.ts
+++ b/packages/dashboard/src/hooks/use-product.ts
@@ -29,6 +29,11 @@ export function useProduct(id: string) {
'product_publications',
'channels',
'custom_fields',
+ // The seller card shows their standing alongside the name: a product
+ // from a suspended seller is not on sale whatever its own status
+ // says. One record on a detail page, so the expand is cheap here in
+ // a way it would not be on the list.
+ 'seller',
],
}),
enabled: !!id,
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index 14ce810cd3..979cb80d53 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -3726,6 +3726,9 @@
"send_back": "إعادة للبائع"
},
"save_label": "حفظ المنتج",
+ "seller": {
+ "title": "البائع"
+ },
"seo": {
"meta_description_placeholder": "SEO description",
"meta_title_placeholder": "SEO title",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index b0d638a4f0..63d2a1f747 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -3705,6 +3705,9 @@
"send_back": "Zurücksenden"
},
"save_label": "Produkt speichern",
+ "seller": {
+ "title": "Verkäufer"
+ },
"seo": {
"meta_description_placeholder": "SEO-Beschreibung",
"meta_title_placeholder": "SEO-Titel",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 2817257e1b..490bb172ed 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -3705,6 +3705,9 @@
"send_back": "Send back"
},
"save_label": "Save product",
+ "seller": {
+ "title": "Seller"
+ },
"seo": {
"meta_description_placeholder": "SEO description",
"meta_title_placeholder": "SEO title",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index 10d56a384e..17cbb3b8e5 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -3705,6 +3705,9 @@
"send_back": "Renvoyer"
},
"save_label": "Enregistrer le produit",
+ "seller": {
+ "title": "Vendeur"
+ },
"seo": {
"meta_description_placeholder": "Description SEO",
"meta_title_placeholder": "Titre SEO",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index dca93a450c..b6963e03ec 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -3765,6 +3765,9 @@
"send_back": "Odeślij"
},
"save_label": "Zapisz produkt",
+ "seller": {
+ "title": "Sprzedawca"
+ },
"seo": {
"meta_description_placeholder": "Opis SEO",
"meta_title_placeholder": "Tytuł SEO",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 8a349068d2..3934a366d0 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -3696,6 +3696,9 @@
"send_back": "退回"
},
"save_label": "保存产品",
+ "seller": {
+ "title": "卖家"
+ },
"seo": {
"meta_description_placeholder": "SEO 描述",
"meta_title_placeholder": "SEO 标题",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
index 7c9cd382bc..67e110a742 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
@@ -41,6 +41,7 @@ import { CustomFieldsInlineCard } from '../../../../components/spree/custom-fiel
import { MediaRichTextEditor } from '../../../../components/spree/media-rich-text-editor'
import { ProductCustomFieldsProvider } from '../../../../components/spree/products/product-custom-fields-provider'
import { ProductReviewActions } from '../../../../components/spree/products/product-review-actions'
+import { ProductSellerCard } from '../../../../components/spree/products/product-seller-card'
import { PublishingCard } from '../../../../components/spree/products/publishing-card'
import { ResourceTranslationsCard } from '../../../../components/spree/translations/resource-translations-card'
import { useDeleteProduct, useProduct, useUpdateProduct } from '../../../../hooks/use-product'
@@ -301,6 +302,7 @@ function ProductForm({ product }: { product: Product }) {
}
sidebar={
<>
+ <ProductSellerCard product={product} />
<StatusCard
form={form}
reviewActions={
diff --git a/spree/core/app/workflows/spree/products/approve.rb b/spree/core/app/workflows/spree/products/approve.rb
index d3e7d2bc7f..e333d52bb5 100644
--- a/spree/core/app/workflows/spree/products/approve.rb
+++ b/spree/core/app/workflows/spree/products/approve.rb
@@ -14,7 +14,7 @@ module Spree
def perform(product:, reviewer: nil)
super
- reject!(Spree.t('activerecord.errors.models.spree/product.attributes.base.not_awaiting_review')) unless product.proposed?
+ reject!(I18n.t('activerecord.errors.models.spree/product.attributes.base.not_awaiting_review')) unless product.proposed?
run_hooks :validate
diff --git a/spree/core/app/workflows/spree/products/propose.rb b/spree/core/app/workflows/spree/products/propose.rb
index 5b90531908..f51244bdce 100644
--- a/spree/core/app/workflows/spree/products/propose.rb
+++ b/spree/core/app/workflows/spree/products/propose.rb
@@ -22,7 +22,7 @@ module Spree
# 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'))
+ reject!(I18n.t('activerecord.errors.models.spree/product.attributes.base.cannot_propose'))
end
run_hooks :validate
diff --git a/spree/core/app/workflows/spree/products/reject.rb b/spree/core/app/workflows/spree/products/reject.rb
index 1d5b8735ba..6d528a3e5f 100644
--- a/spree/core/app/workflows/spree/products/reject.rb
+++ b/spree/core/app/workflows/spree/products/reject.rb
@@ -15,7 +15,12 @@ module Spree
def perform(product:, reason: nil, reviewer: nil)
super
- reject!(Spree.t('activerecord.errors.models.spree/product.attributes.base.not_awaiting_review')) unless product.proposed?
+ # Already rejected counts: correcting the note you gave a seller is
+ # not a second decision, and the panel offers exactly that. Anything
+ # else has not been submitted, so there is nothing to turn down.
+ unless product.proposed? || product.rejected?
+ reject!(I18n.t('activerecord.errors.models.spree/product.attributes.base.not_awaiting_review'))
+ end
run_hooks :validate
diff --git a/spree/core/spec/workflows/spree/products/review_spec.rb b/spree/core/spec/workflows/spree/products/review_spec.rb
index 687da63608..bca981bf62 100644
--- a/spree/core/spec/workflows/spree/products/review_spec.rb
+++ b/spree/core/spec/workflows/spree/products/review_spec.rb
@@ -91,6 +91,17 @@ RSpec.describe 'Spree::Products review workflows' do
expect(product.metadata['rejection_reason']).to eq('Photos are too dark')
end
+ # The panel offers "Edit reason" on a product already turned down, so the
+ # workflow has to accept one — correcting the note is not a new decision.
+ it 'rewrites the reason on one already rejected' do
+ product.update!(status: 'rejected', metadata: { 'rejection_reason' => 'Too dark' })
+
+ result = Spree.product_reject_workflow.call(product: product, reason: 'Needs a scale photo')
+
+ expect(result).to be_success
+ expect(product.reload.metadata['rejection_reason']).to eq('Needs a scale photo')
+ end
+
it 'refuses a product nobody submitted' do
result = Spree.product_reject_workflow.call(product: product)
@@ -99,6 +110,16 @@ RSpec.describe 'Spree::Products review workflows' do
end
end
+ # These messages are shown to an operator, so a missing key does not fail
+ # quietly — it renders `translation_missing` markup into the toast.
+ it 'refuses with a real message rather than a missing-translation key' do
+ result = Spree.product_approve_workflow.call(product: product)
+
+ message = result.error.value.full_messages.join
+ expect(message).not_to include('translation missing', 'translation_missing')
+ expect(message).to include('not awaiting review')
+ end
+
# A product under review is not on sale. The storefront scope keys off
# `active` alone, so this holds for any status we add without touching it.
it 'keeps products under review out of the storefront' do