@meeovi/layer-commerce 1.0.10 → 1.0.13
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/app/components/catalog/product/ProductAccordion/ProductAccordion.vue +39 -0
- package/app/components/catalog/product/ProductAccordion/__tests__/ProductAccordion.spec.ts +15 -0
- package/app/components/catalog/product/ProductAccordion/types.ts +5 -0
- package/app/components/catalog/product/ProductProperties/ProductProperties.vue +50 -0
- package/app/components/catalog/product/ProductProperties/__tests__/ProductProperties.spec.ts +15 -0
- package/app/components/catalog/product/ProductProperties/types.ts +5 -0
- package/app/components/catalog/product/ProductSlider/ProductSlider.vue +28 -0
- package/app/components/catalog/product/ProductSlider/__tests__/ProductSlider.spec.ts +14 -0
- package/app/components/catalog/product/ProductSlider/types.ts +7 -0
- package/app/components/catalog/product/RecommendedProducts/RecommendedProducts.vue +12 -0
- package/app/components/catalog/product/RecommendedProducts/types.ts +5 -0
- package/app/components/catalog/product/RenderContentProductSlider/RenderContentProductSlider.vue +11 -0
- package/app/components/catalog/product/add-attribute.vue +54 -0
- package/app/components/catalog/product/add-product-type.vue +54 -0
- package/app/components/catalog/product/add-product.vue +53 -0
- package/app/components/catalog/product/add-showcase.vue +52 -0
- package/app/components/catalog/product/add-station.vue +54 -0
- package/app/components/catalog/product/bestsellers.vue +57 -0
- package/app/components/catalog/product/bidding.vue +93 -0
- package/app/components/catalog/product/colorOptions.vue +58 -0
- package/app/components/catalog/product/deals.vue +46 -0
- package/app/components/catalog/product/exclusives.vue +56 -0
- package/app/components/catalog/product/featuredproducts.vue +57 -0
- package/app/components/catalog/product/giftCard.vue +63 -0
- package/app/components/catalog/product/latestproducts.vue +46 -0
- package/app/components/catalog/product/productCard.vue +105 -0
- package/app/components/catalog/product/productCompare.vue +60 -0
- package/app/components/catalog/product/productCompareTable.vue +441 -0
- package/app/components/catalog/product/productDetails.vue +126 -0
- package/app/components/catalog/product/productFaqs.vue +17 -0
- package/app/components/catalog/product/productGallery.vue +16 -0
- package/app/components/catalog/product/productQty.vue +54 -0
- package/app/components/catalog/product/productReviews.vue +56 -0
- package/app/components/catalog/product/productSpecs.vue +116 -0
- package/app/components/catalog/product/radiostation.vue +36 -0
- package/app/components/catalog/product/recentlyviewed.vue +43 -0
- package/app/components/catalog/product/relatedbrands.vue +54 -0
- package/app/components/catalog/product/relatedproducts.vue +43 -0
- package/app/components/catalog/product/relatedstations.vue +40 -0
- package/app/components/catalog/product/shippingOptions.vue +41 -0
- package/app/components/catalog/product/sizeOptions.vue +42 -0
- package/app/components/catalog/product/update-attribute-set.vue +209 -0
- package/app/components/catalog/product/update-attribute.vue +118 -0
- package/app/components/catalog/product/update-product.vue +372 -0
- package/app/components/catalog/product/update-showcase.vue +153 -0
- package/app/components/catalog/shops/relatedstores.vue +37 -0
- package/app/components/catalog/shops/restaurant.vue +66 -0
- package/app/components/catalog/shops/stores.vue +44 -0
- package/app/components/catalog/vendor/README.md +3 -0
- package/app/components/catalog/vendor/blocks/biggestcustomers.vue +33 -0
- package/app/components/catalog/vendor/blocks/lowestselling.vue +33 -0
- package/app/components/catalog/vendor/blocks/topcategories.vue +33 -0
- package/app/components/catalog/vendor/blocks/topproducts.vue +27 -0
- package/app/components/catalog/vendor/pages/attributes.vue +43 -0
- package/app/components/catalog/vendor/pages/commissions.vue +43 -0
- package/app/components/catalog/vendor/pages/crm.vue +67 -0
- package/app/components/catalog/vendor/pages/dashboard.vue +46 -0
- package/app/components/catalog/vendor/pages/emails.vue +43 -0
- package/app/components/catalog/vendor/pages/enquiries.vue +43 -0
- package/app/components/catalog/vendor/pages/invoices.vue +43 -0
- package/app/components/catalog/vendor/pages/orders.vue +68 -0
- package/app/components/catalog/vendor/pages/products.vue +55 -0
- package/app/components/catalog/vendor/pages/reviews.vue +48 -0
- package/app/components/catalog/vendor/pages/shipments.vue +43 -0
- package/app/components/catalog/vendor/pages/stores.vue +43 -0
- package/app/components/categories/chart/[id].vue +200 -0
- package/app/components/categories/chart/add-chart.vue +142 -0
- package/app/components/categories/chart/chart.vue +82 -0
- package/app/components/categories/chart/monthlyChart.vue +46 -0
- package/app/components/categories/chart/weeklyChart.vue +46 -0
- package/app/components/categories/chart/yearlyChart.vue +46 -0
- package/app/components/categories/charts.vue +118 -0
- package/app/components/categories/deals.vue +101 -0
- package/app/components/categories/eats.vue +49 -0
- package/app/components/categories/restaurants.vue +26 -0
- package/app/components/categories/station/[id].vue +72 -0
- package/app/components/categories/stations.vue +124 -0
- package/app/components/categories/time/time.vue +63 -0
- package/app/components/categories/travel.vue +75 -0
- package/app/components/categories/weather/weather.vue +44 -0
- package/app/components/content/blocks/breadcrumbs.vue +0 -0
- package/app/components/content/blocks/currencySwitcher.vue +0 -0
- package/app/components/content/blocks/languageSwitcher.vue +0 -0
- package/app/components/content/blocks/videoproduct.vue +9 -0
- package/app/components/content/pages/checkout.vue +118 -0
- package/app/components/content/pages/meeoviGlobal.vue +68 -0
- package/app/components/content/pages/pickup-locations.vue +238 -0
- package/app/components/content/pages/showcases.vue +90 -0
- package/app/components/content/pages/success.vue +60 -0
- package/app/components/marketing/add-brand.vue +54 -0
- package/app/components/marketing/add-incentive.vue +54 -0
- package/app/components/marketing/promotions/giftcards.vue +102 -0
- package/app/components/marketing/promotions/subscriptions.vue +121 -0
- package/app/components/marketing/update-incentive.vue +326 -0
- package/app/components/menus/lowernav.vue +78 -0
- package/app/components/partials/LocaleSelector.vue +24 -0
- package/app/components/partials/ShoppingCart.vue +128 -0
- package/app/components/partials/StripePayment.vue +149 -0
- package/app/components/partials/addToCartBtn.vue +40 -0
- package/app/components/partials/cartItem.vue +124 -0
- package/app/components/partials/checkoutButton.vue +44 -0
- package/app/components/partials/compareBtn.vue +68 -0
- package/app/components/partials/ratings.vue +13 -0
- package/app/components/partials/store/CurrencySelector.vue +133 -0
- package/app/components/partials/store/StoreSwitcher.vue +13 -0
- package/app/components/placeholders/Comments.vue +15 -0
- package/app/components/placeholders/CreateListBtn.vue +7 -0
- package/app/components/placeholders/Event.vue +9 -0
- package/app/components/placeholders/ListShowcases.vue +9 -0
- package/app/components/placeholders/Short.vue +9 -0
- package/app/components/placeholders/Space.vue +9 -0
- package/app/components/placeholders/Tag.vue +7 -0
- package/app/components/related/brandCard.vue +41 -0
- package/app/components/related/incentiveCard.vue +44 -0
- package/app/components/related/invoiceCard.vue +43 -0
- package/app/components/related/orderCard.vue +43 -0
- package/app/components/related/relatedproducts.vue +17 -0
- package/app/components/sales/CartPageContent/CartPageContent.vue +37 -0
- package/app/components/sales/CheckoutAddress/CheckoutAddress.vue +50 -0
- package/app/components/sales/CheckoutAddress/__tests__/CheckoutAddress.spec.ts +16 -0
- package/app/components/sales/CheckoutAddress/types.ts +16 -0
- package/app/components/sales/CheckoutPayment/CheckoutPayment.vue +68 -0
- package/app/components/sales/CheckoutPayment/__tests__/CheckoutPayment.spec.ts +14 -0
- package/app/components/sales/CheckoutPayment/types.ts +12 -0
- package/app/components/sales/OrderSummary/OrderSummary.vue +57 -0
- package/app/components/sales/OrderSummary/__tests__/ContactInformation.spec.ts +52 -0
- package/app/components/sales/OrderSummary/types.ts +5 -0
- package/app/components/sales/incentives.vue +223 -0
- package/app/components/sales/invoices.vue +107 -0
- package/app/components/sales/orders.vue +378 -0
- package/app/components/sales/shipments.vue +65 -0
- package/app/components/sales/transactions.vue +109 -0
- package/app/components/shop/add-shop.vue +54 -0
- package/app/components/shop/cart/cartItem.vue +182 -0
- package/app/components/shop/cart/checkout.vue +415 -0
- package/app/components/shop/checkout/StripeCardElement.vue +206 -0
- package/app/components/shop/checkout/StripeCheckout.vue +49 -0
- package/app/components/shop/checkout/addressBilling.vue +263 -0
- package/app/components/shop/checkout/addressShipping.vue +175 -0
- package/app/components/shop/checkout/cart/ProductItem.vue +56 -0
- package/app/components/shop/checkout/cart/PromotionItem.vue +53 -0
- package/app/composables/_types.ts +18 -0
- package/app/composables/adapters/abstract/cartAdapter.ts +0 -0
- package/app/composables/adapters/abstract/categoryAdapter.ts +0 -0
- package/app/composables/adapters/abstract/customerAdapter.ts +0 -0
- package/app/composables/adapters/abstract/inventoryAdapter.ts +0 -0
- package/app/composables/adapters/abstract/orderAdapter.ts +0 -0
- package/app/composables/adapters/abstract/productAdapter.ts +7 -0
- package/app/composables/cart/registry.ts +20 -0
- package/app/composables/cart/types.ts +18 -0
- package/app/composables/cart/useCart.ts +15 -0
- package/app/composables/config.ts +19 -0
- package/app/composables/defs/apiDefinitions.ts +55 -0
- package/app/composables/defs/extension.feature +40 -0
- package/app/composables/defs/extension.mocks.ts +39 -0
- package/app/composables/defs/extension.test.ts +280 -0
- package/app/composables/defs/extension.ts +236 -0
- package/app/composables/defs/index.ts +3 -0
- package/app/composables/defs/types.ts +136 -0
- package/app/composables/domain/cart.ts +0 -0
- package/app/composables/domain/category.ts +0 -0
- package/app/composables/domain/order.ts +0 -0
- package/app/composables/domain/price.ts +0 -0
- package/app/composables/domain/product.ts +8 -0
- package/app/composables/domain/reward.ts +0 -0
- package/app/composables/domain/transactions.ts +0 -0
- package/app/composables/helpers/contextualizedNormalizers.feature +14 -0
- package/app/composables/helpers/contextualizedNormalizers.test.ts +85 -0
- package/app/composables/helpers/contextualizedNormalizers.ts +20 -0
- package/app/composables/helpers/index.ts +1 -0
- package/app/composables/index.ts +6 -0
- package/app/composables/methods/auth.ts +83 -0
- package/app/composables/methods/cart.ts +119 -0
- package/app/composables/methods/category.ts +27 -0
- package/app/composables/methods/checkout.ts +54 -0
- package/app/composables/methods/customer.ts +52 -0
- package/app/composables/methods/helpers.ts +5 -0
- package/app/composables/methods/index.ts +75 -0
- package/app/composables/methods/order.ts +39 -0
- package/app/composables/methods/product.ts +95 -0
- package/app/composables/methods/settings.ts +16 -0
- package/app/composables/models/cart.ts +95 -0
- package/app/composables/models/category.ts +13 -0
- package/app/composables/models/checkout.ts +17 -0
- package/app/composables/models/customer.ts +16 -0
- package/app/composables/models/facets.ts +25 -0
- package/app/composables/models/index.ts +94 -0
- package/app/composables/models/order.ts +43 -0
- package/app/composables/models/product.ts +73 -0
- package/app/composables/models/shared.ts +75 -0
- package/app/composables/products/registry.ts +20 -0
- package/app/composables/products/types.ts +13 -0
- package/app/composables/products/useEvents.ts +0 -0
- package/app/composables/products/useGiftCards.ts +0 -0
- package/app/composables/products/useProducts.ts +12 -0
- package/app/composables/products/useSubscriptions.ts +0 -0
- package/app/composables/registry.ts +21 -0
- package/app/composables/stores/cart.ts +218 -0
- package/app/composables/stores/cartStore.ts +300 -0
- package/app/composables/stores/checkout.ts +19 -0
- package/app/composables/stores/compare.ts +65 -0
- package/app/composables/stores/currency.js +29 -0
- package/app/composables/stores/digital-products.js +11 -0
- package/app/composables/stores/index.js +0 -0
- package/app/composables/stores/orders.ts +161 -0
- package/app/composables/stores/product.ts +26 -0
- package/app/composables/stores/productList.ts +0 -0
- package/app/composables/stores/productListInfo.ts +0 -0
- package/app/composables/stores/products.ts +112 -0
- package/app/composables/stores/recentlyViewedProducts.ts +0 -0
- package/app/composables/stores/review.ts +25 -0
- package/app/composables/stores/storeInPickUp.ts +22 -0
- package/app/composables/stores/user.ts +20 -0
- package/app/composables/stores/wishlist.ts +19 -0
- package/app/composables/types/Order.type.ts +181 -0
- package/app/composables/types/index.ts +285 -0
- package/app/composables/types/product.ts +14 -0
- package/app/composables/useBreakpoints/index.ts +1 -0
- package/app/composables/useBreakpoints/useBreakpoints.ts +28 -0
- package/app/composables/useCart/__tests__/useCart.spec.ts +11 -0
- package/app/composables/useCart/index.ts +1 -0
- package/app/composables/useCart/types.ts +17 -0
- package/app/composables/useCart/useCart.ts +46 -0
- package/app/composables/useCartShippingMethods/__tests__/useCartShippingMethods.spec.ts +11 -0
- package/app/composables/useCartShippingMethods/index.ts +1 -0
- package/app/composables/useCartShippingMethods/types.ts +17 -0
- package/app/composables/useCartShippingMethods/useCartShippingMethods.ts +47 -0
- package/app/composables/useCatalog.ts +64 -0
- package/app/composables/useContent/index.ts +1 -0
- package/app/composables/useContent/types.ts +44 -0
- package/app/composables/useContent/useContent.ts +45 -0
- package/app/composables/useContent.ts +57 -0
- package/app/composables/useCustomer/__tests__/useCustomer.spec.ts +25 -0
- package/app/composables/useCustomer/index.ts +2 -0
- package/app/composables/useCustomer/types.ts +17 -0
- package/app/composables/useCustomer/useCustomer.ts +40 -0
- package/app/composables/useCustomerAddress/__tests__/useCustomerAddress.spec.ts +11 -0
- package/app/composables/useCustomerAddress/index.ts +2 -0
- package/app/composables/useCustomerAddress/types.ts +17 -0
- package/app/composables/useCustomerAddress/useCustomerAddress.ts +55 -0
- package/app/composables/useCustomerOrder/__tests__/useCustomerOrder.spec.ts +11 -0
- package/app/composables/useCustomerOrder/adress.ts +10 -0
- package/app/composables/useCustomerOrder/index.ts +2 -0
- package/app/composables/useCustomerOrder/product.ts +37 -0
- package/app/composables/useCustomerOrder/types.ts +40 -0
- package/app/composables/useCustomerOrder/useCustomerOrder.ts +63 -0
- package/app/composables/useCustomerOrders/__tests__/useCustomerOrders.spec.ts +11 -0
- package/app/composables/useCustomerOrders/index.ts +2 -0
- package/app/composables/useCustomerOrders/types.ts +20 -0
- package/app/composables/useCustomerOrders/useCustomerOrders.ts +56 -0
- package/app/composables/useCustomerReturns/__tests__/useCustomerReturns.spec.ts +11 -0
- package/app/composables/useCustomerReturns/index.ts +2 -0
- package/app/composables/useCustomerReturns/types.ts +17 -0
- package/app/composables/useCustomerReturns/useCustomerReturns.ts +41 -0
- package/app/composables/useHandleError/index.ts +1 -0
- package/app/composables/useHandleError/types.ts +11 -0
- package/app/composables/useHandleError/useHandleError.ts +27 -0
- package/app/composables/usePageTitle.ts +16 -0
- package/app/composables/useProduct/index.ts +2 -0
- package/app/composables/useProduct/types.ts +17 -0
- package/app/composables/useProduct/useProduct.ts +42 -0
- package/app/composables/useProductAttribute/__tests__/useProduct.mock.ts +31 -0
- package/app/composables/useProductAttribute/__tests__/useProductAttribute.spec.ts +14 -0
- package/app/composables/useProductAttribute/index.ts +1 -0
- package/app/composables/useProductAttribute/useProductAttribute.ts +37 -0
- package/app/composables/useProductRecommended/__tests__/useProductRecommended.spec.ts +12 -0
- package/app/composables/useProductRecommended/index.ts +1 -0
- package/app/composables/useProductRecommended/types.ts +17 -0
- package/app/composables/useProductRecommended/useProductRecommended.ts +43 -0
- package/app/composables/useProductReviews/__tests__/productReviews.mock.ts +20 -0
- package/app/composables/useProductReviews/__tests__/useProductReviews.spec.ts +22 -0
- package/app/composables/useProductReviews/index.ts +2 -0
- package/app/composables/useProductReviews/types.ts +17 -0
- package/app/composables/useProductReviews/useProductReviews.ts +46 -0
- package/app/composables/useProducts/__tests__/useProducts.spec.ts +11 -0
- package/app/composables/useProducts/types.ts +22 -0
- package/app/composables/useProducts/useProducts.ts +41 -0
- package/app/composables/utils/countryList.ts +14 -0
- package/app/composables/utils/currency.js +56 -0
- package/app/composables/utils/glossary.ts +0 -0
- package/app/composables/utils/importExport.ts +0 -0
- package/app/composables/utils/index.js +0 -0
- package/app/composables/utils/print.ts +0 -0
- package/app/composables/utils/shopThemes.ts +0 -0
- package/app/composables/utils/statistics.ts +0 -0
- package/app/composables/utils/stock.ts +0 -0
- package/app/composables/utils/stripe.ts +16 -0
- package/app/composables/utils/taxation.ts +0 -0
- package/app/composables/utils/tellFriends.ts +0 -0
- package/app/composables/validationRules/index.ts +1 -0
- package/app/composables/validationRules/password.feature +67 -0
- package/app/composables/validationRules/password.test.ts +89 -0
- package/app/composables/validationRules/password.ts +25 -0
- package/app/composables/vendors/index.ts +0 -0
- package/app/composables/vendors/registry.ts +0 -0
- package/app/composables/vendors/useAffiliates.ts +0 -0
- package/app/composables/vendors/useCommission.ts +0 -0
- package/app/modules/vue-head/composables/useHead.ts +3 -0
- package/app/pages/brand/[...slug].vue +92 -0
- package/app/pages/brands.vue +90 -0
- package/app/pages/cart.vue +142 -0
- package/app/pages/compare.vue +166 -0
- package/app/pages/departments/[...slug].vue +385 -0
- package/app/pages/departments/category/[...slug].vue +135 -0
- package/app/pages/incentive/[...id].vue +66 -0
- package/app/pages/invoice/[id].vue +309 -0
- package/app/pages/order/[id].vue +327 -0
- package/app/pages/product/[...id].vue +309 -0
- package/app/pages/product/showcases/index.vue +86 -0
- package/app/pages/shipment/[...id].vue +176 -0
- package/app/pages/shop/[...slug].vue +158 -0
- package/app/pages/shops.vue +76 -0
- package/app/pages/subscription/[...id].vue +147 -0
- package/app/pages/transaction/[...id].vue +74 -0
- package/app/types/shims-imports.d.ts +13 -0
- package/app/utils/client.ts +26 -0
- package/app/utils/index.ts +53 -0
- package/app/utils/normalizer.ts +23 -0
- package/app/utils/normalizers/magento.ts +29 -0
- package/app/utils/normalizers/shopify.ts +29 -0
- package/global.d.ts +149 -0
- package/index.js +3 -0
- package/package.json +3 -9
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// stores/cartStore.ts
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
import { MagentoService } from '~/services/magento'
|
|
4
|
+
|
|
5
|
+
interface MagentoProduct {
|
|
6
|
+
sku: string
|
|
7
|
+
name: string
|
|
8
|
+
price: number
|
|
9
|
+
qty: number
|
|
10
|
+
quote_id?: string
|
|
11
|
+
item_id?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface CartState {
|
|
15
|
+
isGuest: boolean
|
|
16
|
+
items: MagentoProduct[]
|
|
17
|
+
total: number
|
|
18
|
+
quoteId: string | null
|
|
19
|
+
magentoService: MagentoService
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export const useCartStore = defineStore('cart', {
|
|
24
|
+
state: () => ({
|
|
25
|
+
isGuest: true,
|
|
26
|
+
items: [] as MagentoProduct[],
|
|
27
|
+
total: 0,
|
|
28
|
+
quoteId: null as string | null,
|
|
29
|
+
magentoService: new MagentoService()
|
|
30
|
+
}),
|
|
31
|
+
|
|
32
|
+
actions: {
|
|
33
|
+
async initializeCart() {
|
|
34
|
+
const auth = useAuth()
|
|
35
|
+
this.isGuest = !auth.token.value
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
if (this.isGuest) {
|
|
39
|
+
await this.createGuestCart()
|
|
40
|
+
} else {
|
|
41
|
+
await this.createCustomerCart()
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
errorHandler.handle(error)
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
async createGuestCart() {
|
|
49
|
+
const response = await fetch(`${process.env.MAGENTO_API_URL}/guest-carts`, {
|
|
50
|
+
method: 'POST'
|
|
51
|
+
})
|
|
52
|
+
const quoteId = await response.json()
|
|
53
|
+
this.quoteId = quoteId as string
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async createCustomerCart() {
|
|
57
|
+
const auth = useAuth()
|
|
58
|
+
const response = await fetch(`${process.env.MAGENTO_API_URL}/carts/mine`, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
'Authorization': `Bearer ${auth.token.value}`
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
this.quoteId = await response.json()
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
async addItem(product: MagentoProduct) {
|
|
68
|
+
const loading = useLoading()
|
|
69
|
+
loading.startLoading('Adding to cart...')
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
// Check authentication
|
|
73
|
+
const auth = useAuth()
|
|
74
|
+
if (auth.isTokenExpired()) {
|
|
75
|
+
await auth.refreshAccessToken()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Check inventory
|
|
79
|
+
const inventory = useInventory()
|
|
80
|
+
await inventory.checkInventory(product.sku, product.qty)
|
|
81
|
+
|
|
82
|
+
// If no quote ID, create cart
|
|
83
|
+
if (!this.quoteId) {
|
|
84
|
+
await this.initializeCart()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Ensure quoteId exists before proceeding
|
|
88
|
+
if (!this.quoteId) {
|
|
89
|
+
throw new CartError('Failed to create cart', 'CART_ERROR')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Add to Magento cart
|
|
93
|
+
const response = await fetch(`${process.env.MAGENTO_API_URL}/carts/mine/items`, {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: {
|
|
96
|
+
'Authorization': `Bearer ${auth.token.value}`,
|
|
97
|
+
'Content-Type': 'application/json'
|
|
98
|
+
},
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
cartItem: {
|
|
101
|
+
sku: product.sku,
|
|
102
|
+
qty: product.qty,
|
|
103
|
+
quote_id: this.quoteId
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
throw new CartError('Failed to add item to cart', 'CART_ERROR')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const cartItem = await response.json()
|
|
113
|
+
|
|
114
|
+
// Update local cart state
|
|
115
|
+
const existingItem = this.items.find(item => item.sku === product.sku)
|
|
116
|
+
if (existingItem) {
|
|
117
|
+
existingItem.qty += product.qty
|
|
118
|
+
} else {
|
|
119
|
+
this.items.push({
|
|
120
|
+
...product,
|
|
121
|
+
item_id: cartItem.item_id
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Calculate taxes
|
|
126
|
+
const tax = useTax()
|
|
127
|
+
if (this.quoteId) {
|
|
128
|
+
await tax.calculateTax(this.quoteId)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Cache product data
|
|
132
|
+
const cache = useCache()
|
|
133
|
+
cache.setCacheItem(`cart_product_${product.sku}`, product)
|
|
134
|
+
|
|
135
|
+
await this.calculateTotal()
|
|
136
|
+
|
|
137
|
+
loading.stopLoading()
|
|
138
|
+
const { show } = useNotification()
|
|
139
|
+
show({
|
|
140
|
+
type: 'success',
|
|
141
|
+
message: 'Product added to cart'
|
|
142
|
+
})
|
|
143
|
+
} catch (error) {
|
|
144
|
+
loading.stopLoading()
|
|
145
|
+
errorHandler.handle(error)
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
async removeItem(itemId: string) {
|
|
150
|
+
const loading = useLoading()
|
|
151
|
+
loading.startLoading('Removing item...')
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const auth = useAuth()
|
|
155
|
+
if (auth.isTokenExpired()) {
|
|
156
|
+
await auth.refreshAccessToken()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Remove from Magento cart
|
|
160
|
+
const response = await fetch(
|
|
161
|
+
`${process.env.MAGENTO_API_URL}/carts/mine/items/${itemId}`,
|
|
162
|
+
{
|
|
163
|
+
method: 'DELETE',
|
|
164
|
+
headers: {
|
|
165
|
+
'Authorization': `Bearer ${auth.token.value}`
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
if (!response.ok) {
|
|
171
|
+
throw new CartError('Failed to remove item from cart', 'CART_ERROR')
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Update local cart state
|
|
175
|
+
this.items = this.items.filter(item => item.item_id !== itemId)
|
|
176
|
+
await this.calculateTotal()
|
|
177
|
+
|
|
178
|
+
loading.stopLoading()
|
|
179
|
+
useNotification().show({
|
|
180
|
+
type: 'success',
|
|
181
|
+
message: 'Item removed from cart'
|
|
182
|
+
})
|
|
183
|
+
} catch (error) {
|
|
184
|
+
loading.stopLoading()
|
|
185
|
+
errorHandler.handle(error)
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
async calculateTotal() {
|
|
190
|
+
try {
|
|
191
|
+
const auth = useAuth()
|
|
192
|
+
if (!this.quoteId) return
|
|
193
|
+
|
|
194
|
+
// Get cart totals from Magento
|
|
195
|
+
const response = await fetch(
|
|
196
|
+
`${process.env.MAGENTO_API_URL}/carts/mine/totals`,
|
|
197
|
+
{
|
|
198
|
+
headers: {
|
|
199
|
+
'Authorization': `Bearer ${auth.token.value}`
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
if (!response.ok) {
|
|
205
|
+
throw new CartError('Failed to get cart totals', 'CART_ERROR')
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const totals = await response.json()
|
|
209
|
+
this.total = totals.grand_total
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.error('Error calculating totals:', error)
|
|
212
|
+
errorHandler.handle(error)
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
// Update other methods to use the notification composable
|
|
217
|
+
async clearCart() {
|
|
218
|
+
const loading = useLoading()
|
|
219
|
+
loading.startLoading('Clearing cart...')
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
const auth = useAuth()
|
|
223
|
+
if (this.quoteId) {
|
|
224
|
+
const response = await fetch(`${process.env.MAGENTO_API_URL}/carts/mine/clear`, {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
headers: {
|
|
227
|
+
'Authorization': `Bearer ${auth.token.value}`
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
if (!response.ok) {
|
|
232
|
+
throw new CartError('Failed to clear cart', 'CART_ERROR')
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
this.items = []
|
|
237
|
+
this.total = 0
|
|
238
|
+
this.quoteId = null
|
|
239
|
+
|
|
240
|
+
// Clear cart-related cache
|
|
241
|
+
const cache = useCache()
|
|
242
|
+
this.items.forEach(item => {
|
|
243
|
+
cache.setCacheItem(`cart_product_${item.sku}`, null)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
loading.stopLoading()
|
|
247
|
+
const { show } = useNotification()
|
|
248
|
+
show({
|
|
249
|
+
type: 'success',
|
|
250
|
+
message: 'Cart cleared successfully'
|
|
251
|
+
})
|
|
252
|
+
} catch (error) {
|
|
253
|
+
loading.stopLoading()
|
|
254
|
+
errorHandler.handle(error)
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
async syncCartWithMagento() {
|
|
259
|
+
try {
|
|
260
|
+
const auth = useAuth()
|
|
261
|
+
const response = await fetch(`${process.env.MAGENTO_API_URL}/carts/mine/items`, {
|
|
262
|
+
headers: {
|
|
263
|
+
'Authorization': `Bearer ${auth.token.value}`
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
if (!response.ok) {
|
|
268
|
+
throw new CartError('Failed to sync cart', 'CART_ERROR')
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const magentoItems = await response.json()
|
|
272
|
+
this.items = magentoItems
|
|
273
|
+
await this.calculateTotal()
|
|
274
|
+
} catch (error) {
|
|
275
|
+
errorHandler.handle(error)
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
async validateCart() {
|
|
280
|
+
try {
|
|
281
|
+
// Check all items inventory
|
|
282
|
+
for (const item of this.items) {
|
|
283
|
+
const inventory = useInventory()
|
|
284
|
+
const isAvailable = await inventory.checkInventory(item.sku, item.qty)
|
|
285
|
+
if (!isAvailable) {
|
|
286
|
+
throw new CartError(`${item.name} is out of stock`, 'INVENTORY_ERROR')
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Validate prices
|
|
291
|
+
await this.syncCartWithMagento()
|
|
292
|
+
|
|
293
|
+
return true
|
|
294
|
+
} catch (error) {
|
|
295
|
+
errorHandler.handle(error)
|
|
296
|
+
return false
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
import type { CheckoutState } from '@/types/checkout';
|
|
3
|
+
|
|
4
|
+
export const useCheckoutStore = defineStore('checkout', {
|
|
5
|
+
state: (): CheckoutState => ({
|
|
6
|
+
shippingAddress: null,
|
|
7
|
+
paymentMethod: null,
|
|
8
|
+
orderId: '',
|
|
9
|
+
isLoading: false
|
|
10
|
+
}),
|
|
11
|
+
actions: {
|
|
12
|
+
setShippingAddress(address: string) {
|
|
13
|
+
this.shippingAddress = address;
|
|
14
|
+
},
|
|
15
|
+
setPaymentMethod(method: string) {
|
|
16
|
+
this.paymentMethod = method;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// stores/compare.ts
|
|
2
|
+
import { defineStore } from 'pinia';
|
|
3
|
+
import type {
|
|
4
|
+
ComparableAttribute,
|
|
5
|
+
ComparableItem,
|
|
6
|
+
ComparableProduct,
|
|
7
|
+
CompareList,
|
|
8
|
+
} from '~/graphql/queries-mutations_subscriptions/types/ProductCompare.type';
|
|
9
|
+
|
|
10
|
+
export const useCompareStore = defineStore('compare', {
|
|
11
|
+
state: () => ({
|
|
12
|
+
isLoading: false,
|
|
13
|
+
count: 0,
|
|
14
|
+
attributes: [] as ComparableAttribute[],
|
|
15
|
+
products: [] as ComparableProduct[],
|
|
16
|
+
productSkus: [] as string[],
|
|
17
|
+
items: [] as ComparableItem[]
|
|
18
|
+
}),
|
|
19
|
+
|
|
20
|
+
actions: {
|
|
21
|
+
toggleLoader(isLoading: boolean) {
|
|
22
|
+
this.isLoading = isLoading;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
setCompareList(payload: CompareList) {
|
|
26
|
+
this.attributes = payload.attributes || [];
|
|
27
|
+
this.products = payload.products || [];
|
|
28
|
+
this.items = payload.items || [];
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
removeComparedProduct(productSku: string) {
|
|
32
|
+
this.products = this.products.filter(product => product.sku !== productSku);
|
|
33
|
+
this.productSkus = this.productSkus.filter(sku => sku !== productSku);
|
|
34
|
+
this.items = this.items.filter(item => item.product.sku !== productSku);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
clearComparedProducts() {
|
|
38
|
+
this.products = [];
|
|
39
|
+
this.productSkus = [];
|
|
40
|
+
this.items = [];
|
|
41
|
+
this.count = 0;
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
setCompareListSkus(productSkus: string[]) {
|
|
45
|
+
this.productSkus = productSkus;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
addComparedProductSku(productSku: string) {
|
|
49
|
+
if (!this.productSkus.includes(productSku)) {
|
|
50
|
+
this.productSkus.push(productSku);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
updateCompareTotals(compareTotals: string) {
|
|
55
|
+
this.count = parseInt(compareTotals, 10); // Convert string to number
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
getters: {
|
|
60
|
+
getCompareCount: (state) => state.count,
|
|
61
|
+
getComparedProducts: (state) => state.products,
|
|
62
|
+
getComparedProductSkus: (state) => state.productSkus,
|
|
63
|
+
getIsLoading: (state) => state.isLoading
|
|
64
|
+
}
|
|
65
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
|
|
3
|
+
export const useCurrencyStore = defineStore('currency', {
|
|
4
|
+
state: () => ({
|
|
5
|
+
currentCurrency: null,
|
|
6
|
+
exchangeRates: {}
|
|
7
|
+
}),
|
|
8
|
+
|
|
9
|
+
actions: {
|
|
10
|
+
setCurrency(currency) {
|
|
11
|
+
this.currentCurrency = currency
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
setExchangeRates(rates) {
|
|
15
|
+
this.exchangeRates = rates
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
async updateCurrency(currency) {
|
|
19
|
+
this.setCurrency(currency)
|
|
20
|
+
// Here you would typically make an API call to update the user's preference
|
|
21
|
+
// if they are logged in
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
getters: {
|
|
26
|
+
getCurrentCurrency: (state) => state.currentCurrency,
|
|
27
|
+
getExchangeRates: (state) => state.exchangeRates
|
|
28
|
+
}
|
|
29
|
+
})
|
|
File without changes
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// stores/orders.ts - Pinia store for order management
|
|
2
|
+
import type { Order, Return, Transaction, Invoice, CreditMemo, OrderFilters } from '~/app/types'
|
|
3
|
+
|
|
4
|
+
export const useOrdersStore = defineStore('orders', () => {
|
|
5
|
+
const orders = ref<Order[]>([])
|
|
6
|
+
const currentOrder = ref<Order | null>(null)
|
|
7
|
+
const returns = ref<Return[]>([])
|
|
8
|
+
const transactions = ref<Transaction[]>([])
|
|
9
|
+
const invoices = ref<Invoice[]>([])
|
|
10
|
+
const creditMemos = ref<CreditMemo[]>([])
|
|
11
|
+
const loading = ref(false)
|
|
12
|
+
const error = ref<string | null>(null)
|
|
13
|
+
|
|
14
|
+
// Import composables
|
|
15
|
+
const { getOrders, getOrderById } = useOrders()
|
|
16
|
+
const { getReturns, createReturn } = useReturns()
|
|
17
|
+
const { getTransactions } = useTransactions()
|
|
18
|
+
const { getInvoices } = useInvoices()
|
|
19
|
+
const { getCreditMemos } = useCreditMemos()
|
|
20
|
+
|
|
21
|
+
const fetchOrders = async (filters: OrderFilters = {}) => {
|
|
22
|
+
loading.value = true
|
|
23
|
+
error.value = null
|
|
24
|
+
try {
|
|
25
|
+
orders.value = await getOrders(filters)
|
|
26
|
+
} catch (err: any) {
|
|
27
|
+
error.value = err.message
|
|
28
|
+
console.error('Error fetching orders:', err)
|
|
29
|
+
} finally {
|
|
30
|
+
loading.value = false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fetchOrder = async (id: string) => {
|
|
35
|
+
loading.value = true
|
|
36
|
+
error.value = null
|
|
37
|
+
try {
|
|
38
|
+
currentOrder.value = await getOrderById(id)
|
|
39
|
+
} catch (err: any) {
|
|
40
|
+
error.value = err.message
|
|
41
|
+
console.error('Error fetching order:', err)
|
|
42
|
+
} finally {
|
|
43
|
+
loading.value = false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const fetchReturns = async (options: { search?: string } = {}) => {
|
|
48
|
+
loading.value = true
|
|
49
|
+
error.value = null
|
|
50
|
+
try {
|
|
51
|
+
returns.value = await getReturns(options)
|
|
52
|
+
} catch (err: any) {
|
|
53
|
+
error.value = err.message
|
|
54
|
+
console.error('Error fetching returns:', err)
|
|
55
|
+
} finally {
|
|
56
|
+
loading.value = false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const submitReturn = async (returnData: any) => {
|
|
61
|
+
loading.value = true
|
|
62
|
+
error.value = null
|
|
63
|
+
try {
|
|
64
|
+
const newReturn = await createReturn(returnData)
|
|
65
|
+
returns.value.unshift(newReturn)
|
|
66
|
+
return newReturn
|
|
67
|
+
} catch (err: any) {
|
|
68
|
+
error.value = err.message
|
|
69
|
+
console.error('Error submitting return:', err)
|
|
70
|
+
throw err
|
|
71
|
+
} finally {
|
|
72
|
+
loading.value = false
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const fetchTransactions = async (options: { search?: string } = {}) => {
|
|
77
|
+
loading.value = true
|
|
78
|
+
error.value = null
|
|
79
|
+
try {
|
|
80
|
+
transactions.value = await getTransactions(options)
|
|
81
|
+
} catch (err: any) {
|
|
82
|
+
error.value = err.message
|
|
83
|
+
console.error('Error fetching transactions:', err)
|
|
84
|
+
} finally {
|
|
85
|
+
loading.value = false
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const fetchInvoices = async (options: { search?: string } = {}) => {
|
|
90
|
+
loading.value = true
|
|
91
|
+
error.value = null
|
|
92
|
+
try {
|
|
93
|
+
invoices.value = await getInvoices(options)
|
|
94
|
+
} catch (err: any) {
|
|
95
|
+
error.value = err.message
|
|
96
|
+
console.error('Error fetching invoices:', err)
|
|
97
|
+
} finally {
|
|
98
|
+
loading.value = false
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const fetchCreditMemos = async (options: { search?: string } = {}) => {
|
|
103
|
+
loading.value = true
|
|
104
|
+
error.value = null
|
|
105
|
+
try {
|
|
106
|
+
creditMemos.value = await getCreditMemos(options)
|
|
107
|
+
} catch (err: any) {
|
|
108
|
+
error.value = err.message
|
|
109
|
+
console.error('Error fetching credit memos:', err)
|
|
110
|
+
} finally {
|
|
111
|
+
loading.value = false
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Computed properties
|
|
116
|
+
const ordersByStatus = computed(() => {
|
|
117
|
+
return orders.value.reduce((acc, order) => {
|
|
118
|
+
acc[order.status] = (acc[order.status] || 0) + 1
|
|
119
|
+
return acc
|
|
120
|
+
}, {} as Record<string, number>)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
const totalRevenue = computed(() => {
|
|
124
|
+
return orders.value
|
|
125
|
+
.filter(order => !['cancelled', 'refunded'].includes(order.status))
|
|
126
|
+
.reduce((sum, order) => sum + order.total, 0)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const averageOrderValue = computed(() => {
|
|
130
|
+
const validOrders = orders.value.filter(order =>
|
|
131
|
+
!['cancelled', 'refunded'].includes(order.status)
|
|
132
|
+
)
|
|
133
|
+
return validOrders.length > 0 ? totalRevenue.value / validOrders.length : 0
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
// State
|
|
138
|
+
orders: readonly(orders),
|
|
139
|
+
currentOrder: readonly(currentOrder),
|
|
140
|
+
returns: readonly(returns),
|
|
141
|
+
transactions: readonly(transactions),
|
|
142
|
+
invoices: readonly(invoices),
|
|
143
|
+
creditMemos: readonly(creditMemos),
|
|
144
|
+
loading: readonly(loading),
|
|
145
|
+
error: readonly(error),
|
|
146
|
+
|
|
147
|
+
// Computed
|
|
148
|
+
ordersByStatus,
|
|
149
|
+
totalRevenue,
|
|
150
|
+
averageOrderValue,
|
|
151
|
+
|
|
152
|
+
// Actions
|
|
153
|
+
fetchOrders,
|
|
154
|
+
fetchOrder,
|
|
155
|
+
fetchReturns,
|
|
156
|
+
submitReturn,
|
|
157
|
+
fetchTransactions,
|
|
158
|
+
fetchInvoices,
|
|
159
|
+
fetchCreditMemos
|
|
160
|
+
}
|
|
161
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
import type { Product, ProductState } from '@/types/product';
|
|
3
|
+
|
|
4
|
+
export const useProductStore = defineStore('product', {
|
|
5
|
+
state: (): ProductState => ({
|
|
6
|
+
products: [],
|
|
7
|
+
selectedProduct: null,
|
|
8
|
+
isLoading: false
|
|
9
|
+
}),
|
|
10
|
+
actions: {
|
|
11
|
+
async fetchProducts() {
|
|
12
|
+
this.isLoading = true;
|
|
13
|
+
try {
|
|
14
|
+
const response = await $fetch<Product[]>('/api/products'); // Update API endpoint
|
|
15
|
+
this.products = response;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error('Error fetching products:', error);
|
|
18
|
+
} finally {
|
|
19
|
+
this.isLoading = false;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
selectProduct(product: Product) {
|
|
23
|
+
this.selectedProduct = product;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
File without changes
|
|
File without changes
|