@anker-in/shopify-react 0.1.1-beta.21 → 0.1.1-beta.23
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/dist/hooks/index.d.mts +245 -210
- package/dist/hooks/index.d.ts +245 -210
- package/dist/hooks/index.js +72 -9
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +71 -8
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +72 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -8
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +1 -2
- package/dist/provider/index.d.ts +1 -2
- package/dist/provider/index.js +9 -7
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +8 -6
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-C1So3siD.d.mts → types-BSsb8OPm.d.mts} +1 -34
- package/dist/{types-C1So3siD.d.ts → types-BSsb8OPm.d.ts} +1 -34
- package/package.json +3 -3
package/dist/provider/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createContext, useMemo, useContext, useState, useCallback, useEffect, useRef } from 'react';
|
|
2
|
-
import { createShopifyClient, getCart, updateCartAttributes, updateCartLines,
|
|
2
|
+
import { createShopifyClient, getCart, updateCartAttributes, updateCartLines, getProductsByHandles, getLocalStorage } from '@anker-in/shopify-sdk';
|
|
3
3
|
import Cookies5 from 'js-cookie';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
import Decimal2 from 'decimal.js';
|
|
6
|
+
import { btoaID, atobID } from '@anker-in/shopify-core';
|
|
6
7
|
import useSWR from 'swr';
|
|
7
8
|
import useSWRMutation8 from 'swr/mutation';
|
|
8
9
|
import { useRequest } from 'ahooks';
|
|
@@ -101,9 +102,10 @@ function normalizeAddToCartLines(lines) {
|
|
|
101
102
|
const variant = line.variant;
|
|
102
103
|
const product = variant.product;
|
|
103
104
|
const quantity = line.quantity || 1;
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
const
|
|
105
|
+
const originalPrice = variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : variant.price?.amount ? Number(variant.price.amount) : 0;
|
|
106
|
+
const finalPrice = variant.finalPrice?.amount ? Number(variant.finalPrice.amount) : originalPrice;
|
|
107
|
+
const subtotalAmount = originalPrice * quantity;
|
|
108
|
+
const totalAmount = finalPrice * quantity;
|
|
107
109
|
return {
|
|
108
110
|
id: `temp-line-${index}-${variant.id}`,
|
|
109
111
|
// Temporary ID for pre-cart lines
|
|
@@ -117,7 +119,7 @@ function normalizeAddToCartLines(lines) {
|
|
|
117
119
|
customAttributes: line.attributes || [],
|
|
118
120
|
variant: {
|
|
119
121
|
id: variant.id,
|
|
120
|
-
price,
|
|
122
|
+
price: variant.price?.amount ? Number(variant.price.amount) : 0,
|
|
121
123
|
listPrice: variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : 0,
|
|
122
124
|
sku: variant.sku || "",
|
|
123
125
|
name: variant.title || "",
|
|
@@ -920,7 +922,7 @@ var useUpdateLineCodeAmountAttributes = ({
|
|
|
920
922
|
);
|
|
921
923
|
const functionEnvValue = getDiscountEnvAttributeValue(line.customAttributes);
|
|
922
924
|
const hasSameFunctionEnvAttribute = Number(functionEnvValue.discounted_amount) === Number(line.totalAmount);
|
|
923
|
-
if (!hasSameFunctionEnvAttribute && hasFunctionEnvAttribute) {
|
|
925
|
+
if (!hasSameFunctionEnvAttribute && hasFunctionEnvAttribute && !functionEnvValue.is_gift) {
|
|
924
926
|
attrNeedUpdate.push({
|
|
925
927
|
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
926
928
|
value: JSON.stringify({
|