@anker-in/shopify-react 0.1.1-beta.23 → 0.1.1-beta.25

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.
@@ -95,7 +95,7 @@ function normalizeAddToCartLines(lines) {
95
95
  customAttributes: line.attributes || [],
96
96
  variant: {
97
97
  id: variant.id,
98
- price: variant.price?.amount ? Number(variant.price.amount) : 0,
98
+ price: finalPrice,
99
99
  listPrice: variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : 0,
100
100
  sku: variant.sku || "",
101
101
  name: variant.title || "",
@@ -126,7 +126,7 @@ function createMockCartFromLines(lines, existingCart) {
126
126
  const normalizedLines = normalizeAddToCartLines(lines);
127
127
  const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
128
128
  const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
129
- console.log("lines createMockCartFromLines", lines);
129
+ console.log("lines createMockCartFromLines4444", normalizedLines, lines);
130
130
  const currency = lines[0]?.variant?.price?.currencyCode;
131
131
  return {
132
132
  id: existingCart?.id || "temp-cart-id",
@@ -376,6 +376,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
376
376
  }
377
377
  return cart;
378
378
  }, [lines, cart]);
379
+ console.log("effectiveCart useCalcAutoFreeGift", effectiveCart);
379
380
  const { activeCampaign, subtotal } = react.useMemo(() => {
380
381
  for (const campaign of autoFreeGiftConfig) {
381
382
  const { rule_conditions = [], rule_result } = campaign;
@@ -391,6 +392,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
391
392
  all_store_variant: spend_get_reward.main_product?.all_store_variant || false
392
393
  }
393
394
  );
395
+ console.log("matchedSubtotal useCalcAutoFreeGift", matchedSubtotal);
394
396
  if (matchedSubtotal > 0) {
395
397
  return { activeCampaign: campaign, subtotal: matchedSubtotal };
396
398
  }
@@ -1639,29 +1641,22 @@ var useUpdateLineCodeAmountAttributes = ({
1639
1641
  }).filter(
1640
1642
  ({ attrNeedUpdate, attrNeedDelete }) => attrNeedUpdate.length || attrNeedDelete.length
1641
1643
  ).map(({ line, attrNeedUpdate, attrNeedDelete }) => {
1644
+ let lineId = line.id;
1645
+ let attributes = line.customAttributes || [];
1646
+ if (attrNeedDelete.length) {
1647
+ attributes = attributes.filter(
1648
+ (attr) => !attrNeedDelete.includes(attr.key)
1649
+ );
1650
+ }
1642
1651
  if (attrNeedUpdate.length) {
1643
- return {
1644
- id: line.id,
1645
- attributes: [
1646
- ...line.customAttributes?.filter(
1647
- (attr) => !attrNeedUpdate.some((updateAttr) => updateAttr.key === attr.key)
1648
- ) || [],
1649
- ...attrNeedUpdate
1650
- ]
1651
- };
1652
- } else if (attrNeedDelete.length) {
1653
- return {
1654
- id: line.id,
1655
- attributes: line.customAttributes?.filter(
1656
- (attr) => !attrNeedDelete.includes(attr.key)
1657
- ) || []
1658
- };
1659
- } else {
1660
- return {
1661
- id: line.id,
1662
- attributes: line.customAttributes || []
1663
- };
1652
+ attributes = attributes.filter(
1653
+ (attr) => !attrNeedUpdate.some((updateAttr) => updateAttr.key === attr.key)
1654
+ ).concat(attrNeedUpdate);
1664
1655
  }
1656
+ return {
1657
+ id: lineId,
1658
+ attributes
1659
+ };
1665
1660
  }),
1666
1661
  [cart?.lineItems, mainProductDiscountCodes]
1667
1662
  );