pb-sxp-ui 1.20.28 → 1.20.29

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.
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importStar(require("react"));
5
5
  const hooks_1 = require("../../../../core/hooks");
6
+ const tool_1 = require("../../../../core/utils/tool");
6
7
  require("./index.less");
7
8
  const AddToCartPopup = ({ isActive = true, onClose }) => {
8
9
  var _a, _b, _c, _d, _e, _f, _g;
9
- const { popupDetailData, globalConfig } = (0, hooks_1.useSxpDataSource)();
10
+ const { popupDetailData, globalConfig, bffFbReport } = (0, hooks_1.useSxpDataSource)();
10
11
  const [productData, setProductData] = (0, react_1.useState)(null);
11
12
  const [selectedOptions, setSelectedOptions] = (0, react_1.useState)({});
12
13
  const [selectedVariant, setSelectedVariant] = (0, react_1.useState)(null);
@@ -122,6 +123,17 @@ const AddToCartPopup = ({ isActive = true, onClose }) => {
122
123
  alert('Please select all options');
123
124
  return;
124
125
  }
126
+ bffFbReport === null || bffFbReport === void 0 ? void 0 : bffFbReport({
127
+ eventName: 'sessionCompleted',
128
+ product: product ? [product] : undefined,
129
+ contentType: 'product',
130
+ rec: data,
131
+ position: data === null || data === void 0 ? void 0 : data.index,
132
+ cta_text: 'Add To Cart',
133
+ cta_action_type: 'add_to_cart',
134
+ target_content_id: product === null || product === void 0 ? void 0 : product.itemId,
135
+ target_url: `https://${shopifyDomain}/cart`
136
+ });
125
137
  const variantId = selectedVariant.id.split('/').pop();
126
138
  const checkoutUrl = `https://${shopifyDomain}/cart/${variantId}:${quantity}`;
127
139
  window.location.href = checkoutUrl;
@@ -129,7 +141,9 @@ const AddToCartPopup = ({ isActive = true, onClose }) => {
129
141
  const totalPrice = selectedVariant
130
142
  ? (parseFloat(selectedVariant.price.amount) * quantity).toFixed(2)
131
143
  : '0.00';
132
- const currency = (selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.price.currencyCode) || 'USD';
144
+ const displayPrice = selectedVariant
145
+ ? `${(0, tool_1.getCurrencySymbol)(selectedVariant.price.currencyCode)}${totalPrice}`
146
+ : totalPrice;
133
147
  if (loading) {
134
148
  return (react_1.default.createElement("div", { className: "add-to-cart-popup" },
135
149
  react_1.default.createElement("div", { className: "loading" }, "Loading...")));
@@ -154,9 +168,7 @@ const AddToCartPopup = ({ isActive = true, onClose }) => {
154
168
  react_1.default.createElement("div", { className: "variant-info" },
155
169
  react_1.default.createElement("div", { className: "variant-specs" }, Object.keys(selectedOptions).length > 0 ? (Object.entries(selectedOptions).map(([key, value]) => (react_1.default.createElement("span", { key: key, className: "spec-item" }, value)))) : (react_1.default.createElement("span", { className: "spec-placeholder" }, "Please select options"))),
156
170
  react_1.default.createElement("div", { className: "variant-price-row" },
157
- react_1.default.createElement("div", { className: "price" },
158
- "$",
159
- totalPrice),
171
+ react_1.default.createElement("div", { className: "price" }, displayPrice),
160
172
  react_1.default.createElement("div", { className: "quantity-selector" },
161
173
  react_1.default.createElement("button", { className: "qty-btn", onClick: () => setQuantity(Math.max(1, quantity - 1)), disabled: quantity <= 1 }, "\u2212"),
162
174
  react_1.default.createElement("span", { className: "qty-value" }, quantity),
@@ -166,7 +178,16 @@ const AddToCartPopup = ({ isActive = true, onClose }) => {
166
178
  react_1.default.createElement("div", { className: "option-values" }, option.values.map(value => {
167
179
  const isAvailable = productData.variants.edges.some(({ node: variant }) => {
168
180
  const hasThisOption = variant.selectedOptions.some(opt => opt.name === option.name && opt.value === value);
169
- return hasThisOption && variant.availableForSale;
181
+ if (!hasThisOption)
182
+ return false;
183
+ const matchesOtherSelections = Object.entries(selectedOptions).every(([key, val]) => {
184
+ if (key === option.name)
185
+ return true;
186
+ return variant.selectedOptions.some(opt => opt.name === key && opt.value === val);
187
+ });
188
+ if (!matchesOtherSelections)
189
+ return false;
190
+ return variant.availableForSale;
170
191
  });
171
192
  const isSelected = selectedOptions[option.name] === value;
172
193
  return (react_1.default.createElement("button", { key: value, className: `option-btn ${isSelected ? 'selected' : ''} ${!isAvailable ? 'disabled' : ''}`, onClick: () => isAvailable && handleOptionSelect(option.name, value), disabled: !isAvailable }, value));
@@ -229,6 +229,17 @@ const AddToCartPopup = (_a) => {
229
229
  quantity
230
230
  }]
231
231
  });
232
+ bffFbReport === null || bffFbReport === void 0 ? void 0 : bffFbReport({
233
+ eventName: 'sessionCompleted',
234
+ product: product ? [product] : undefined,
235
+ contentType: 'product',
236
+ rec: data,
237
+ position,
238
+ cta_text: 'Add To Cart',
239
+ cta_action_type: 'add_to_cart',
240
+ target_content_id: product === null || product === void 0 ? void 0 : product.itemId,
241
+ target_url: cartUrl
242
+ });
232
243
  window.location.href = cartUrl;
233
244
  }, [selectedVariant, quantity, finalShopifyDomain, bffFbReport, product, data, position]);
234
245
  const totalPrice = (0, react_1.useMemo)(() => {
@@ -277,7 +288,7 @@ const AddToCartPopup = (_a) => {
277
288
  option.value)))),
278
289
  react_1.default.createElement("div", { className: "price-display" },
279
290
  react_1.default.createElement("span", { className: "price-value", style: variantStyles.price, dangerouslySetInnerHTML: {
280
- __html: (0, tool_1.setFontForText)(`${selectedVariant.price.currencyCode} $${totalPrice}`, variantStyles.price)
291
+ __html: (0, tool_1.setFontForText)(selectedVariant ? `${(0, tool_1.getCurrencySymbol)(selectedVariant.price.currencyCode)}${totalPrice}` : totalPrice, variantStyles.price)
281
292
  } })),
282
293
  react_1.default.createElement("div", { className: "quantity-selector-wrapper", style: quantityStyle },
283
294
  react_1.default.createElement("button", { className: "quantity-btn quantity-decrease", onClick: () => handleQuantityChange(-1), disabled: quantity <= 1, "aria-label": "Decrease quantity" }, "-"),
@@ -41,25 +41,30 @@ const CommodityDetail = (_a) => {
41
41
  }
42
42
  const handleLink = (e) => {
43
43
  if (enableAddToCart && addToCartPopupId) {
44
- setPopupDetailData === null || setPopupDetailData === void 0 ? void 0 : setPopupDetailData(Object.assign(Object.assign({}, data), { index: position }));
45
- bffFbReport === null || bffFbReport === void 0 ? void 0 : bffFbReport({
46
- eventName: 'ClickCTA',
47
- product: product ? [product] : undefined,
48
- contentType: 'product',
49
- data,
50
- position,
51
- cta_text: cta === null || cta === void 0 ? void 0 : cta.enTitle,
52
- cta_action_type: 'open_internal_popup',
53
- target_content_id: product === null || product === void 0 ? void 0 : product.itemId
54
- });
55
- console.log('[CommodityDetail] 打开加购弹窗:', addToCartPopupId);
56
- if (typeof window !== 'undefined' && window.sxpPopup) {
57
- window.sxpPopup(addToCartPopupId);
44
+ if (!(product === null || product === void 0 ? void 0 : product.shopifyId)) {
45
+ console.warn('[CommodityDetail] Shopify 商品,跳过加购弹窗');
58
46
  }
59
47
  else {
60
- console.warn('[CommodityDetail] sxpPopup 方法不存在');
48
+ setPopupDetailData === null || setPopupDetailData === void 0 ? void 0 : setPopupDetailData(Object.assign(Object.assign({}, data), { index: position }));
49
+ bffFbReport === null || bffFbReport === void 0 ? void 0 : bffFbReport({
50
+ eventName: 'ClickCTA',
51
+ product: product ? [product] : undefined,
52
+ contentType: 'product',
53
+ data,
54
+ position,
55
+ cta_text: cta === null || cta === void 0 ? void 0 : cta.enTitle,
56
+ cta_action_type: 'open_internal_popup',
57
+ target_content_id: product === null || product === void 0 ? void 0 : product.itemId
58
+ });
59
+ console.log('[CommodityDetail] 打开加购弹窗:', addToCartPopupId);
60
+ if (typeof window !== 'undefined' && window.sxpPopup) {
61
+ window.sxpPopup(addToCartPopupId);
62
+ }
63
+ else {
64
+ console.warn('[CommodityDetail] sxpPopup 方法不存在');
65
+ }
66
+ return;
61
67
  }
62
- return;
63
68
  }
64
69
  if (product === null || product === void 0 ? void 0 : product.link) {
65
70
  jumpToWeb(e, data, product, cta, position);
@@ -43,6 +43,31 @@ const CommodityDetailDiroNew = (_a) => {
43
43
  }
44
44
  const handleLink = (e) => {
45
45
  e.preventDefault();
46
+ if (!(product === null || product === void 0 ? void 0 : product.shopifyId)) {
47
+ console.warn('[CommodityDetailDiroNew] 非 Shopify 商品,跳转到外链');
48
+ ctaEvent === null || ctaEvent === void 0 ? void 0 : ctaEvent({
49
+ eventSubject: 'clickCta',
50
+ eventDescription: 'User clicked the CTA'
51
+ }, data, product, position);
52
+ bffFbReport === null || bffFbReport === void 0 ? void 0 : bffFbReport({
53
+ eventName: 'ClickCTA',
54
+ product: product ? [product] : undefined,
55
+ contentType: 'product',
56
+ data,
57
+ position,
58
+ cta_text: cta === null || cta === void 0 ? void 0 : cta.enTitle,
59
+ cta_action_type: 'open_external_link',
60
+ target_content_id: product === null || product === void 0 ? void 0 : product.itemId,
61
+ target_url: product === null || product === void 0 ? void 0 : product.link
62
+ });
63
+ if (!isPost) {
64
+ productView(data, product, cta, viewTime || curTimeRef.current, position);
65
+ }
66
+ if (product === null || product === void 0 ? void 0 : product.link) {
67
+ window.location.href = window.getJointUtmLink(product.link);
68
+ }
69
+ return;
70
+ }
46
71
  ctaEvent === null || ctaEvent === void 0 ? void 0 : ctaEvent({
47
72
  eventSubject: 'clickCta',
48
73
  eventDescription: 'User clicked the CTA'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pb-sxp-ui",
3
- "version": "1.20.28",
3
+ "version": "1.20.29",
4
4
  "description": "React enterprise-class UI components",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",