@anker-in/shopify-react 0.1.1-beta.21 → 0.1.1-beta.22

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/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { createContext, useMemo, useContext, useRef, useState, useEffect, useCallback } from 'react';
2
- import { createShopifyClient, atobID, btoaID, getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getLocalStorage, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getCart, setLocalStorage, updateCartDeliveryOptions } from '@anker-in/shopify-sdk';
2
+ import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getLocalStorage, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getCart, setLocalStorage, updateCartDeliveryOptions } from '@anker-in/shopify-sdk';
3
3
  export * from '@anker-in/shopify-sdk';
4
4
  import Cookies5 from 'js-cookie';
5
5
  import { jsx } from 'react/jsx-runtime';
6
6
  import Decimal2 from 'decimal.js';
7
+ import { atobID, btoaID } from '@anker-in/shopify-core';
7
8
  import useSWR from 'swr';
8
9
  import useSWRMutation from 'swr/mutation';
9
10
  import { useRequest } from 'ahooks';
@@ -140,9 +141,10 @@ function normalizeAddToCartLines(lines) {
140
141
  const variant = line.variant;
141
142
  const product = variant.product;
142
143
  const quantity = line.quantity || 1;
143
- const price = variant.finalPrice?.amount ? Number(variant.finalPrice.amount) : variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : variant.price?.amount ? Number(variant.price.amount) : 0;
144
- const subtotalAmount = price * quantity;
145
- const totalAmount = subtotalAmount;
144
+ const originalPrice = variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : variant.price?.amount ? Number(variant.price.amount) : 0;
145
+ const finalPrice = variant.finalPrice?.amount ? Number(variant.finalPrice.amount) : originalPrice;
146
+ const subtotalAmount = originalPrice * quantity;
147
+ const totalAmount = finalPrice * quantity;
146
148
  return {
147
149
  id: `temp-line-${index}-${variant.id}`,
148
150
  // Temporary ID for pre-cart lines
@@ -156,7 +158,7 @@ function normalizeAddToCartLines(lines) {
156
158
  customAttributes: line.attributes || [],
157
159
  variant: {
158
160
  id: variant.id,
159
- price,
161
+ price: variant.price?.amount ? Number(variant.price.amount) : 0,
160
162
  listPrice: variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : 0,
161
163
  sku: variant.sku || "",
162
164
  name: variant.title || "",