@sgflabs/storefront-core 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/src/components/cells/CartItemsProducts/CartItemsProducts.tsx +5 -4
- package/src/components/molecules/CartDropdownItem/CartDropdownItem.tsx +4 -3
- package/src/lib/data/cart-retrieve-fields.ts +8 -2
- package/src/lib/data/cart.ts +1 -1
- package/src/lib/data/customer.ts +1 -1
- package/src/lib/data/orders.ts +2 -2
- package/src/lib/data/products.ts +3 -1
- package/src/lib/helpers/variant-option-title.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgflabs/storefront-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Shared storefront library consumed as raw TypeScript source by the brand apps.",
|
|
5
5
|
"license": "PolyForm-Shield-1.0.0",
|
|
6
6
|
"sideEffects": [
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@sentry/nextjs": "^10.63.0",
|
|
57
57
|
"@sgflabs/artha-go-sdk": "^0.3.0",
|
|
58
|
-
"@sgflabs/gstin": "^0.1.
|
|
59
|
-
"@sgflabs/page-spec": "^0.1.
|
|
60
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
58
|
+
"@sgflabs/gstin": "^0.1.16",
|
|
59
|
+
"@sgflabs/page-spec": "^0.1.16",
|
|
60
|
+
"@sgflabs/storefront-core-common": "^0.1.16",
|
|
61
61
|
"@testing-library/dom": "^10.4.1",
|
|
62
62
|
"@testing-library/jest-dom": "^7.0.0",
|
|
63
63
|
"@testing-library/react": "^16.3.2",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@sentry/nextjs": "^10.63.0",
|
|
75
75
|
"@sgflabs/artha-go-sdk": "^0.3.0",
|
|
76
|
-
"@sgflabs/gstin": "^0.1.
|
|
77
|
-
"@sgflabs/page-spec": "^0.1.
|
|
78
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
76
|
+
"@sgflabs/gstin": "^0.1.16",
|
|
77
|
+
"@sgflabs/page-spec": "^0.1.16",
|
|
78
|
+
"@sgflabs/storefront-core-common": "^0.1.16",
|
|
79
79
|
"next": "15.5.27",
|
|
80
80
|
"react": "^19.2.3",
|
|
81
81
|
"react-dom": "^19.2.3"
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { DeleteCartItemButton } from '../../molecules';
|
|
12
12
|
import LocalizedClientLink from '../../molecules/LocalizedLink/LocalizedLink';
|
|
13
13
|
import { UpdateCartItemButton } from '../../molecules/UpdateCartItemButton/UpdateCartItemButton';
|
|
14
|
+
import { variantOptionTitle } from '../../../lib/helpers/variant-option-title';
|
|
14
15
|
import { filterValidCartItems } from '../../../lib/helpers/filter-valid-cart-items';
|
|
15
16
|
import { getCartLineItemDisplayAmount } from '../../../lib/helpers/cart-line-item';
|
|
16
17
|
import { convertToLocale } from '../../../lib/helpers/money';
|
|
@@ -128,10 +129,10 @@ export const CartItemsProducts = ({
|
|
|
128
129
|
</div>
|
|
129
130
|
<div className="lg:flex justify-between lg:gap-6 -mt-4 lg:mt-0">
|
|
130
131
|
<div className="label-md min-w-0 text-secondary">
|
|
131
|
-
{options?.map((
|
|
132
|
-
<p key={id ?? `opt-${optIndex}`}>
|
|
133
|
-
{
|
|
134
|
-
<span className="text-primary">{value}</span>
|
|
132
|
+
{options?.map((variantOption, optIndex) => (
|
|
133
|
+
<p key={variantOption.id ?? `opt-${optIndex}`}>
|
|
134
|
+
{variantOptionTitle(variantOption, product.product)}:{" "}
|
|
135
|
+
<span className="text-primary">{variantOption.value}</span>
|
|
135
136
|
</p>
|
|
136
137
|
))}
|
|
137
138
|
{change_quantity ? (
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { getCartLineItemDisplayAmount } from "../../../lib/helpers/cart-line-item"
|
|
4
4
|
import { convertToLocale } from "../../../lib/helpers/money"
|
|
5
5
|
import { formatPackQuantityForSystem } from "../../../lib/helpers/measurement"
|
|
6
|
+
import { variantOptionTitle } from "../../../lib/helpers/variant-option-title"
|
|
6
7
|
import { variantOptionValues } from "../../../lib/helpers/unit-price"
|
|
7
8
|
import { resolveExplicitPriceUnitMode } from "../../../lib/helpers/price-unit-mode"
|
|
8
9
|
import { useMeasurement } from "../../providers/Measurement/MeasurementProvider"
|
|
@@ -55,9 +56,9 @@ export const CartDropdownItem = ({
|
|
|
55
56
|
<div className="py-2">
|
|
56
57
|
<h4 className="heading-xs">{item.product_title}</h4>
|
|
57
58
|
<div className="label-md text-secondary">
|
|
58
|
-
{item.variant?.options?.map((
|
|
59
|
-
<p key={id}>
|
|
60
|
-
{
|
|
59
|
+
{item.variant?.options?.map((variantOption) => (
|
|
60
|
+
<p key={variantOption.id}>
|
|
61
|
+
{variantOptionTitle(variantOption, item.product)}: <span className="text-primary">{variantOption.value}</span>
|
|
61
62
|
</p>
|
|
62
63
|
))}
|
|
63
64
|
<p>
|
|
@@ -29,8 +29,14 @@ export const CART_SHIPPING_METHOD_FIELDS = "*shipping_methods"
|
|
|
29
29
|
export const CART_RETRIEVE_CHECKOUT_FIELDS =
|
|
30
30
|
"email,completed_at,*shipping_address,*billing_address,*payment_collection,*payment_collection.payment_sessions"
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* `*items.product.options` carries the option titles on every Medusa version: the cart fields no longer ask for
|
|
34
|
+
* `items.variant.options.option.title` (four relations deep, over the limit of three on Medusa 2.21+), so a line's
|
|
35
|
+
* option title is always matched by `option_id` (see `variantOptionTitle`).
|
|
36
|
+
* Read from `GET /store/opticomm/carts/:id/detail`, which serves the extension fields core's allow-list lacks.
|
|
37
|
+
*/
|
|
32
38
|
export const CART_RETRIEVE_FIELDS_PRIMARY =
|
|
33
|
-
"*items,*region,*region.countries, *items.product,*items.product.type, *items.variant, *items.variant.options, items.
|
|
39
|
+
"*items,*region,*region.countries, *items.product,*items.product.type, *items.variant, *items.variant.options, *items.product.options," +
|
|
34
40
|
"*items.thumbnail, *items.metadata, items.total,items.subtotal,items.unit_price, *promotions, *items.product.sellers, metadata," +
|
|
35
41
|
CART_SHIPPING_METHOD_FIELDS +
|
|
36
42
|
"," +
|
|
@@ -41,7 +47,7 @@ export const CART_RETRIEVE_FIELDS_PRIMARY =
|
|
|
41
47
|
|
|
42
48
|
/** Same as primary but omits nested product sellers (some backends 500 on this expansion). */
|
|
43
49
|
export const CART_RETRIEVE_FIELDS_FALLBACK =
|
|
44
|
-
"*items,*region,*region.countries, *items.product,*items.product.type, *items.variant, *items.variant.options, items.
|
|
50
|
+
"*items,*region,*region.countries, *items.product,*items.product.type, *items.variant, *items.variant.options, *items.product.options," +
|
|
45
51
|
"*items.thumbnail, *items.metadata, items.total,items.subtotal,items.unit_price, *promotions, metadata," +
|
|
46
52
|
CART_SHIPPING_METHOD_FIELDS +
|
|
47
53
|
"," +
|
package/src/lib/data/cart.ts
CHANGED
|
@@ -126,7 +126,7 @@ export async function retrieveCart(cartId?: string) {
|
|
|
126
126
|
|
|
127
127
|
const fetchCart = (fields: string | undefined) =>
|
|
128
128
|
sdk.client
|
|
129
|
-
.fetch<HttpTypes.StoreCartResponse>(`/store/carts/${id}`, {
|
|
129
|
+
.fetch<HttpTypes.StoreCartResponse>(`/store/opticomm/carts/${id}/detail`, {
|
|
130
130
|
method: 'GET',
|
|
131
131
|
...(fields ? { query: { fields } } : {}),
|
|
132
132
|
headers,
|
package/src/lib/data/customer.ts
CHANGED
|
@@ -45,7 +45,7 @@ export const retrieveCustomer = async (): Promise<StoreCustomerWithB2b | null> =
|
|
|
45
45
|
...(await getCacheOptions("customers")),
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
return await sdk.client.fetch<{ customer: StoreCustomerWithB2b }>(`/store/customers/me`, {
|
|
48
|
+
return await sdk.client.fetch<{ customer: StoreCustomerWithB2b }>(`/store/opticomm/customers/me`, {
|
|
49
49
|
method: "GET",
|
|
50
50
|
query: {
|
|
51
51
|
fields: "*orders,+addresses.address_name,*employee,*employee.company",
|
package/src/lib/data/orders.ts
CHANGED
|
@@ -40,7 +40,7 @@ export const retrieveOrder = async (id: string) => {
|
|
|
40
40
|
|
|
41
41
|
return sdk.client
|
|
42
42
|
.fetch<HttpTypes.StoreOrderResponse & { seller: SellerProps }>(
|
|
43
|
-
`/store/orders/${id}`,
|
|
43
|
+
`/store/opticomm/orders/${id}`,
|
|
44
44
|
{
|
|
45
45
|
method: "GET",
|
|
46
46
|
query: {
|
|
@@ -66,7 +66,7 @@ export const retrieveOrderUncached = async (id: string) => {
|
|
|
66
66
|
|
|
67
67
|
return sdk.client
|
|
68
68
|
.fetch<HttpTypes.StoreOrderResponse & { seller: SellerProps }>(
|
|
69
|
-
`/store/orders/${id}`,
|
|
69
|
+
`/store/opticomm/orders/${id}/confirmation`,
|
|
70
70
|
{
|
|
71
71
|
method: "GET",
|
|
72
72
|
query: { fields: ORDER_STORE_FIELDS },
|
package/src/lib/data/products.ts
CHANGED
|
@@ -206,6 +206,8 @@ export const listProducts = async ({
|
|
|
206
206
|
queryParams,
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
+
// Owned route, not core `/store/products`: Medusa 2.21+ strips `sellers`, `moq_rules`, `product_documents` and
|
|
210
|
+
// `attribute_values` from core's response. `store.opticomm.listProducts` cannot carry the `next`/`cache` options below.
|
|
209
211
|
//@TODO to fix multiple sellers fetching we need to update the SDK to support array of includes
|
|
210
212
|
// `static` / no request context is the "no shopper" read: env key, never headers().
|
|
211
213
|
const sdk = await (isStatic || !canUseRequestCookies ? getStaticSdk() : getSdk());
|
|
@@ -213,7 +215,7 @@ export const listProducts = async ({
|
|
|
213
215
|
.fetch<{
|
|
214
216
|
products: (HttpTypes.StoreProduct & { sellers?: SellerProps[] })[];
|
|
215
217
|
count: number;
|
|
216
|
-
}>(`/store/products`, {
|
|
218
|
+
}>(`/store/opticomm/products`, {
|
|
217
219
|
method: 'GET',
|
|
218
220
|
query: {
|
|
219
221
|
category_id,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cart line's option title (for example "Pack size"). The cart fields no longer ask for
|
|
3
|
+
* `items.variant.options.option.title` (four relations deep, over Medusa's limit of three), so on both 2.18 and 2.23
|
|
4
|
+
* the title comes from `items.product.options`, matched to the variant's option value by `option_id`. A title the
|
|
5
|
+
* variant option already carries wins only as a safe fallback (a caller that still selects it).
|
|
6
|
+
*/
|
|
7
|
+
export const variantOptionTitle = (
|
|
8
|
+
variantOption: { option_id?: string | null; option?: { title?: string | null } | null },
|
|
9
|
+
product: { options?: Array<{ id?: string | null; title?: string | null }> | null } | null | undefined
|
|
10
|
+
) =>
|
|
11
|
+
variantOption.option?.title ??
|
|
12
|
+
product?.options?.find((option) => option.id === variantOption.option_id)?.title ??
|
|
13
|
+
undefined
|