@evershop/evershop 1.1.0 → 1.2.1
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/bin/build/index.js +24 -0
- package/bin/extension/index.js +2 -2
- package/bin/lib/addDefaultMiddlewareFuncs.js +7 -2
- package/bin/lib/buildEntry.js +20 -2
- package/bin/lib/onListening.js +7 -4
- package/bin/lib/startUp.js +6 -0
- package/package.json +9 -1
- package/src/components/admin/catalog/productEdit/category/CategoryItem.jsx +2 -7
- package/src/components/admin/catalog/productEdit/category/CategoryTree.jsx +14 -7
- package/src/components/admin/catalog/productEdit/category/CategoryTree.scss +10 -0
- package/src/components/admin/catalog/productEdit/variants/CreateVariant.jsx +2 -2
- package/src/components/admin/catalog/productEdit/variants/CreateVariantGroup.jsx +1 -1
- package/src/components/admin/catalog/productEdit/variants/EditVariant.jsx +1 -1
- package/src/components/admin/catalog/productEdit/variants/New.jsx +2 -2
- package/src/components/admin/catalog/productEdit/variants/Search.jsx +1 -1
- package/src/components/admin/catalog/productEdit/variants/SearchModal.jsx +1 -1
- package/src/components/admin/catalog/productEdit/variants/VariantModal.jsx +6 -6
- package/src/components/admin/catalog/productGrid/rows/ThumbnailRow.jsx +1 -1
- package/src/components/admin/checkout/shippingSetting/Method.jsx +6 -6
- package/src/components/admin/checkout/shippingSetting/MethodForm.jsx +4 -4
- package/src/components/admin/checkout/shippingSetting/Methods.jsx +3 -3
- package/src/components/admin/checkout/shippingSetting/PriceBasedPrice.jsx +2 -2
- package/src/components/admin/checkout/shippingSetting/WeightBasedPrice.jsx +2 -2
- package/src/components/admin/checkout/shippingSetting/Zone.jsx +7 -7
- package/src/components/admin/checkout/shippingSetting/ZoneForm.jsx +1 -1
- package/src/components/admin/cms/Card.jsx +3 -3
- package/src/components/admin/cms/PageHeading.jsx +3 -3
- package/src/components/admin/cms/widget/WidgetTypes.jsx +28 -0
- package/src/components/admin/cms/widget/grid/WidgetTypeRow.jsx +29 -0
- package/src/components/admin/oms/orderEdit/items/ItemVariantOptions.jsx +1 -1
- package/src/components/admin/oms/orderEdit/items/Name.jsx +1 -1
- package/src/components/admin/oms/orderGrid/headers/OrderDateColumnHeader.jsx +1 -1
- package/src/components/admin/promotion/couponEdit/AttributeGroupSelector.jsx +3 -3
- package/src/components/admin/promotion/couponEdit/BuyXGetY.jsx +2 -2
- package/src/components/admin/promotion/couponEdit/CategorySelector.jsx +6 -6
- package/src/components/admin/promotion/couponEdit/CollectionSelector.jsx +3 -3
- package/src/components/admin/promotion/couponEdit/ProductSkuSelector.jsx +4 -4
- package/src/components/admin/promotion/couponEdit/RequireProducts.jsx +2 -2
- package/src/components/admin/promotion/couponEdit/Setting.jsx +1 -1
- package/src/components/admin/promotion/couponEdit/TargetProducts.jsx +4 -4
- package/src/components/admin/tax/taxSetting/Rate.jsx +6 -6
- package/src/components/admin/tax/taxSetting/RateForm.jsx +5 -5
- package/src/components/admin/tax/taxSetting/Rates.jsx +6 -6
- package/src/components/admin/tax/taxSetting/TaxClass.jsx +3 -3
- package/src/components/admin/tax/taxSetting/TaxClassForm.jsx +1 -1
- package/src/components/admin/widgets/BasicMenuSetting.jsx +614 -0
- package/src/components/admin/widgets/BasicMenuSetting.scss +19 -0
- package/src/components/admin/widgets/CollectionProductsSetting.jsx +203 -0
- package/src/components/admin/widgets/TextBlockSetting.jsx +70 -0
- package/src/components/common/Area.jsx +31 -8
- package/src/components/common/Badge.jsx +1 -1
- package/src/components/common/Editor.jsx +193 -0
- package/src/components/common/Notification.scss +1 -0
- package/src/components/common/SimplePagination.jsx +2 -2
- package/src/components/common/form/Form.jsx +1 -1
- package/src/components/common/form/fields/Checkbox.jsx +1 -1
- package/src/components/common/form/fields/Ckeditor.jsx +11 -11
- package/src/components/common/form/fields/Editor.jsx +326 -0
- package/src/components/common/form/fields/Editor.scss +33 -0
- package/src/components/common/form/fields/Radio.jsx +1 -1
- package/src/components/common/form/fields/editor/FileBrowser.jsx +419 -0
- package/src/components/common/form/fields/editor/FileBrowser.scss +37 -0
- package/src/components/common/form/fields/editor/GetColumnClasses.jsx +14 -0
- package/src/components/common/form/fields/editor/GetRowClasses.jsx +18 -0
- package/src/components/common/form/fields/editor/RowTemplates.jsx +154 -0
- package/src/components/common/grid/Pagination.jsx +4 -4
- package/src/components/common/grid/headers/FromTo.jsx +1 -1
- package/src/components/common/grid/headers/Sortable.jsx +1 -1
- package/src/components/common/grid/rows/ThumbnailRow.jsx +1 -1
- package/src/components/common/list/Filter.jsx +1 -1
- package/src/components/common/modal/Alert.jsx +1 -1
- package/src/components/common/modal/Modal.jsx +1 -1
- package/src/components/frontStore/catalog/categoryView/filter/AttributeFilter.jsx +2 -2
- package/src/components/frontStore/catalog/categoryView/filter/CategoryFilter.jsx +3 -2
- package/src/components/frontStore/catalog/categoryView/filter/CategoryFilter.scss +5 -0
- package/src/components/frontStore/catalog/product/list/List.jsx +4 -4
- package/src/components/frontStore/catalog/product/list/Pagination.jsx +1 -1
- package/src/components/frontStore/catalog/product/list/Sorting.jsx +2 -2
- package/src/components/frontStore/catalog/product/list/item/Name.jsx +1 -1
- package/src/components/frontStore/checkout/cart/Empty.jsx +3 -3
- package/src/components/frontStore/checkout/cart/items/ItemOptions.jsx +1 -1
- package/src/components/frontStore/checkout/cart/items/ItemVariantOptions.jsx +1 -1
- package/src/components/frontStore/checkout/cart/items/Items.jsx +20 -21
- package/src/components/frontStore/checkout/cart/items/Items.scss +47 -0
- package/src/components/frontStore/checkout/cart/items/Quantity.jsx +154 -0
- package/src/components/frontStore/checkout/checkout/StepTitle.jsx +1 -1
- package/src/components/frontStore/checkout/checkout/payment/paymentStep/StepContent.jsx +5 -5
- package/src/components/frontStore/checkout/checkout/shipment/StepContent.jsx +1 -1
- package/src/components/frontStore/checkout/checkout/summary/Cart.jsx +10 -12
- package/src/components/frontStore/checkout/checkout/summary/Items.jsx +9 -9
- package/src/components/frontStore/checkout/checkout/summary/cart/Total.jsx +6 -6
- package/src/components/frontStore/checkout/success/summary/items/ItemOptions.jsx +1 -1
- package/src/components/frontStore/checkout/success/summary/items/Items.jsx +9 -6
- package/src/components/frontStore/checkout/success/summary/order/OrderSummary.jsx +9 -13
- package/src/components/frontStore/checkout/success/summary/order/Total.jsx +5 -5
- package/src/components/frontStore/customer/address/addressForm/AddressFormLoadingSkeleton.jsx +2 -2
- package/src/components/frontStore/customer/address/addressForm/NameAndTelephone.jsx +1 -1
- package/src/components/frontStore/customer/address/addressForm/ProvinceAndPostcode.jsx +1 -1
- package/src/components/frontStore/customer/checkout/Edit.jsx +2 -2
- package/src/components/frontStore/customer/detail/Order.jsx +4 -4
- package/src/components/frontStore/stripe/checkout/CheckoutForm.jsx +2 -2
- package/src/components/frontStore/stripe/checkout/TestCards.jsx +1 -1
- package/src/components/frontStore/widgets/BasicMenu.jsx +129 -0
- package/src/{modules/catalog/pages/frontStore/homepage/FeaturedProducts.jsx → components/frontStore/widgets/CollectionProducts.jsx} +40 -32
- package/src/components/frontStore/widgets/TextBlock.jsx +46 -0
- package/src/lib/componee/getComponentsByRoute.js +15 -2
- package/src/lib/event/event-manager.js +1 -1
- package/src/lib/middleware/tests/app/modules/404page/pages/frontStore/product/route.json +2 -1
- package/src/lib/middlewares/static.js +3 -1
- package/src/lib/response/render.js +5 -6
- package/src/lib/router/Router.js +1 -1
- package/src/lib/router/loadModuleRoutes.js +3 -0
- package/src/lib/router/registerAdminRoute.js +9 -1
- package/src/lib/router/registerFrontStoreRoute.js +2 -0
- package/src/lib/router/scanForRoutes.js +1 -0
- package/src/lib/router/tests/unit/unit.validateRoute.test.js +7 -1
- package/src/lib/util/defaultPaginationFilters.js +19 -17
- package/src/lib/util/getEnabledWidgets.js +34 -0
- package/src/lib/util/merge.js +67 -14
- package/src/lib/util/tests/unit/util.merge.test.js +21 -4
- package/src/lib/util/validateConfiguration.js +83 -0
- package/src/lib/webpack/createBaseConfig.js +4 -1
- package/src/lib/webpack/dev/createConfigClient.js +10 -2
- package/src/lib/webpack/loaders/AreaLoader.js +16 -6
- package/src/lib/webpack/util/keyGenerator.js +9 -0
- package/src/lib/webpack/util/parseGraphql.js +30 -16
- package/src/lib/webpack/util/parseGraphqlByFile.js +16 -2
- package/src/modules/auth/pages/admin/adminLogin/LoginForm.jsx +54 -21
- package/src/modules/auth/pages/admin/all/AdminUser.jsx +3 -3
- package/src/modules/base/bootstrap.js +79 -0
- package/src/modules/base/graphql/types/Route/Route.admin.graphql +15 -0
- package/src/modules/base/graphql/types/Route/Route.admin.resolvers.js +10 -0
- package/src/modules/base/pages/global/response[errorHandler].js +25 -1
- package/src/modules/catalog/bootstrap.js +125 -5
- package/src/modules/catalog/graphql/types/Category/Category.graphql +4 -3
- package/src/modules/catalog/graphql/types/Category/Category.resolvers.js +34 -0
- package/src/modules/catalog/graphql/types/Collection/Collection.graphql +2 -2
- package/src/modules/catalog/graphql/types/Collection/Collection.resolvers.js +34 -0
- package/src/modules/catalog/graphql/types/Product/Attribute/ProductAttribute.resolvers.js +1 -0
- package/src/modules/catalog/graphql/types/Product/Product.graphql +1 -1
- package/src/modules/catalog/graphql/types/Product/Product.resolvers.js +34 -0
- package/src/modules/catalog/graphql/types/Widget/CollectionProductsWidget/CollectionProductsWidget.graphql +11 -0
- package/src/modules/catalog/graphql/types/Widget/CollectionProductsWidget/CollectionProductsWidget.resolvers.js +8 -0
- package/src/modules/catalog/migration/Version-1.0.0.js +1 -0
- package/src/modules/catalog/migration/Version-1.0.7.js +10 -0
- package/src/modules/catalog/pages/admin/attributeEdit+attributeNew/FormContent.jsx +4 -4
- package/src/modules/catalog/pages/admin/attributeEdit+attributeNew/General.jsx +5 -5
- package/src/modules/catalog/pages/admin/attributeGrid/Grid.jsx +2 -2
- package/src/modules/catalog/pages/admin/categoryEdit/Products.jsx +4 -4
- package/src/modules/catalog/pages/admin/categoryEdit+categoryNew/FormContent.jsx +4 -4
- package/src/modules/catalog/pages/admin/categoryEdit+categoryNew/General.jsx +16 -18
- package/src/modules/catalog/pages/admin/categoryEdit+categoryNew/Image.jsx +1 -2
- package/src/modules/catalog/pages/admin/categoryEdit+categoryNew/Status.jsx +16 -1
- package/src/modules/catalog/pages/admin/categoryGrid/Grid.jsx +3 -3
- package/src/modules/catalog/pages/admin/collectionEdit/Products.jsx +4 -4
- package/src/modules/catalog/pages/admin/collectionEdit+collectionNew/FormContent.jsx +2 -2
- package/src/modules/catalog/pages/admin/collectionEdit+collectionNew/General.jsx +2 -2
- package/src/modules/catalog/pages/admin/collectionGrid/Grid.jsx +3 -3
- package/src/modules/catalog/pages/admin/productEdit/Collection.jsx +7 -7
- package/src/modules/catalog/pages/admin/productEdit+productNew/Attributes.jsx +8 -3
- package/src/modules/catalog/pages/admin/productEdit+productNew/CustomOptions.jsss +4 -4
- package/src/modules/catalog/pages/admin/productEdit+productNew/FormContent.jsx +4 -4
- package/src/modules/catalog/pages/admin/productEdit+productNew/General.jsx +15 -17
- package/src/modules/catalog/pages/admin/productGrid/Grid.jsx +3 -3
- package/src/modules/catalog/pages/frontStore/catalogSearch/General.jsx +2 -2
- package/src/modules/catalog/pages/frontStore/catalogSearch/Products.jsx +1 -1
- package/src/modules/catalog/pages/frontStore/catalogSearch/route.json +2 -1
- package/src/modules/catalog/pages/frontStore/categoryView/CategoryView.jsx +19 -2
- package/src/modules/catalog/pages/frontStore/categoryView/Filter.scss +1 -0
- package/src/modules/catalog/pages/frontStore/categoryView/General.jsx +6 -8
- package/src/modules/catalog/pages/frontStore/categoryView/General.scss +0 -2
- package/src/modules/catalog/pages/frontStore/categoryView/Pagination.jsx +6 -0
- package/src/modules/catalog/pages/frontStore/categoryView/Products.jsx +8 -1
- package/src/modules/catalog/pages/frontStore/categoryView/route.json +2 -1
- package/src/modules/catalog/pages/frontStore/productView/Description.jsx +15 -4
- package/src/modules/catalog/pages/frontStore/productView/Form.jsx +4 -4
- package/src/modules/catalog/pages/frontStore/productView/Form.scss +1 -0
- package/src/modules/catalog/pages/frontStore/productView/GeneralInfo.jsx +1 -1
- package/src/modules/catalog/pages/frontStore/productView/Images.jsx +1 -1
- package/src/modules/catalog/pages/frontStore/productView/Layout.jsx +1 -1
- package/src/modules/catalog/pages/frontStore/productView/Options.jsx +7 -3
- package/src/modules/catalog/pages/frontStore/productView/Variants.jsx +6 -6
- package/src/modules/catalog/pages/frontStore/productView/route.json +2 -1
- package/src/modules/catalog/services/AttributeCollection.js +10 -10
- package/src/modules/catalog/services/AttributeGroupCollection.js +10 -10
- package/src/modules/catalog/services/CategoryCollection.js +10 -10
- package/src/modules/catalog/services/CollectionCollection.js +10 -10
- package/src/modules/catalog/services/registerCartItemProductUrlField.js +35 -0
- package/src/modules/catalog/services/registerCartItemVariantOptionsField.js +51 -0
- package/src/modules/catalog/services/registerDefaultCategoryCollectionFilters.js +16 -0
- package/src/modules/checkout/api/addShippingNote/[context]bodyParser[auth].js +5 -0
- package/src/modules/checkout/api/addShippingNote/payloadSchema.json +15 -0
- package/src/modules/checkout/api/addShippingNote/route.json +5 -0
- package/src/modules/checkout/api/addShippingNote/saveShippingNote.js +50 -0
- package/src/modules/checkout/api/createCart/createNewCart.js +28 -3
- package/src/modules/checkout/api/updateCartItemQty/[bodyParser]updateQty.js +49 -0
- package/src/modules/checkout/api/updateCartItemQty/[context]bodyParser[auth].js +5 -0
- package/src/modules/checkout/api/updateCartItemQty/payloadSchema.json +21 -0
- package/src/modules/checkout/api/updateCartItemQty/route.json +5 -0
- package/src/modules/checkout/api/updateMineCartItemQty/[context]bodyParser[auth].js +5 -0
- package/src/modules/checkout/api/updateMineCartItemQty/[detectCurrentCart]updateQty.js +51 -0
- package/src/modules/checkout/api/updateMineCartItemQty/[getCurrentCustomer]detectCurrentCart.js +32 -0
- package/src/modules/checkout/api/updateMineCartItemQty/payloadSchema.json +21 -0
- package/src/modules/checkout/api/updateMineCartItemQty/route.json +5 -0
- package/src/modules/checkout/bootstrap.js +27 -0
- package/src/modules/checkout/graphql/types/Cart/Cart.graphql +22 -3
- package/src/modules/checkout/graphql/types/Cart/Cart.resolvers.js +18 -2
- package/src/modules/checkout/graphql/types/CheckoutSetting/CheckoutSetting.graphql +3 -0
- package/src/modules/checkout/graphql/types/CheckoutSetting/CheckoutSetting.resolvers.js +7 -0
- package/src/modules/checkout/migration/Version-1.0.0.js +14 -0
- package/src/modules/checkout/migration/Version-1.0.6.js +201 -0
- package/src/modules/checkout/pages/admin/shippingSetting/ShippingSetting.jsx +2 -2
- package/src/modules/checkout/pages/frontStore/all/[context]detectCurrentCart[auth].js +5 -0
- package/src/modules/checkout/pages/frontStore/cart/ShoppingCart.jsx +20 -12
- package/src/modules/checkout/pages/frontStore/cart/Summary.jsx +34 -23
- package/src/modules/checkout/pages/frontStore/cart/route.json +2 -1
- package/src/modules/checkout/pages/frontStore/checkout/Checkout.jsx +5 -5
- package/src/modules/checkout/pages/frontStore/checkout/Checkout.scss +4 -0
- package/src/modules/checkout/pages/frontStore/checkout/ShippingMethods.jsx +2 -2
- package/src/modules/checkout/pages/frontStore/checkout/ShippingNote.jsx +105 -0
- package/src/modules/checkout/pages/frontStore/checkout/Summary.jsx +14 -14
- package/src/modules/checkout/pages/frontStore/checkout/SummaryMobile.jsx +12 -15
- package/src/modules/checkout/pages/frontStore/checkout/route.json +2 -1
- package/src/modules/checkout/pages/frontStore/checkoutSuccess/CheckoutSuccess.jsx +1 -1
- package/src/modules/checkout/pages/frontStore/checkoutSuccess/CheckoutSuccess.scss +4 -0
- package/src/modules/checkout/pages/frontStore/checkoutSuccess/CustomerInfo.jsx +30 -32
- package/src/modules/checkout/pages/frontStore/checkoutSuccess/ShippingNote.jsx +47 -0
- package/src/modules/checkout/pages/frontStore/checkoutSuccess/Summary.jsx +12 -15
- package/src/modules/checkout/pages/frontStore/checkoutSuccess/route.json +2 -1
- package/src/modules/checkout/services/cart/Cart.js +31 -27
- package/src/modules/checkout/services/cart/registerCartBaseFields.js +133 -41
- package/src/modules/checkout/services/cart/registerCartItemBaseFields.js +300 -374
- package/src/modules/checkout/services/toPrice.js +1 -1
- package/src/modules/checkout/tests/basicSetup.js +85 -0
- package/src/modules/checkout/tests/coupons.js +82 -0
- package/src/modules/checkout/tests/products.js +67 -0
- package/src/modules/checkout/tests/taxRates.js +3 -0
- package/src/modules/checkout/tests/unit/discountAmount.test.js +60 -0
- package/src/modules/checkout/tests/unit/grandTotal.test.js +83 -0
- package/src/modules/checkout/tests/unit/lineTotal.test.js +92 -0
- package/src/modules/checkout/tests/unit/lineTotalWithDiscount.test.js +103 -0
- package/src/modules/checkout/tests/unit/productPrice.test.js +69 -0
- package/src/modules/checkout/tests/unit/subTotal.test.js +85 -0
- package/src/modules/checkout/tests/unit/subTotalWithDiscount.test.js +117 -0
- package/src/modules/checkout/tests/unit/taxAmount.test.js +68 -0
- package/src/modules/checkout/tests/unit/taxAmountRounding.test.js +277 -0
- package/src/modules/cms/api/createWidget/[context]bodyParser[auth].js +5 -0
- package/src/modules/cms/api/createWidget/createWidget[finish].js +17 -0
- package/src/modules/cms/api/createWidget/finish[apiResponse].js +27 -0
- package/src/modules/cms/api/createWidget/payloadSchema.json +18 -0
- package/src/modules/cms/api/createWidget/route.json +5 -0
- package/src/modules/cms/api/deleteWidget/deleteWidget.js +27 -0
- package/src/modules/cms/api/deleteWidget/route.json +5 -0
- package/src/modules/cms/api/updateWidget/[context]bodyParser[auth].js +5 -0
- package/src/modules/cms/api/updateWidget/finish[apiResponse].js +27 -0
- package/src/modules/cms/api/updateWidget/payloadSchema.json +18 -0
- package/src/modules/cms/api/updateWidget/route.json +5 -0
- package/src/modules/cms/api/updateWidget/updateWidget[finish].js +17 -0
- package/src/modules/cms/bootstrap.js +223 -3
- package/src/modules/cms/graphql/types/CmsPage/CmsPage.graphql +1 -2
- package/src/modules/cms/graphql/types/CmsPage/CmsPage.resolvers.js +35 -1
- package/src/modules/cms/graphql/types/Widget/Widget.graphql +91 -0
- package/src/modules/cms/graphql/types/Widget/Widget.resolvers.js +142 -0
- package/src/modules/cms/migration/Version-1.1.0.js +22 -0
- package/src/modules/cms/migration/Version-1.1.1.js +103 -0
- package/src/modules/cms/pages/admin/adminNotFound/NotFound.jsx +4 -4
- package/src/modules/cms/pages/admin/all/CmsMenuGroup.jsx +12 -4
- package/src/modules/cms/pages/admin/all/Notification.scss +1 -1
- package/src/modules/cms/pages/admin/all/search/NoResult.jsx +2 -2
- package/src/modules/cms/pages/admin/all/search/Results.jsx +3 -3
- package/src/modules/cms/pages/admin/cmsPageEdit+cmsPageNew/FormContent.jsx +7 -9
- package/src/modules/cms/pages/admin/cmsPageEdit+cmsPageNew/General.jsx +3 -3
- package/src/modules/cms/pages/admin/cmsPageEdit+cmsPageNew/Seo.jsx +1 -1
- package/src/modules/cms/pages/admin/cmsPageEdit+cmsPageNew/Status.jsx +40 -0
- package/src/modules/cms/pages/admin/cmsPageGrid/Grid.jsx +3 -4
- package/src/modules/cms/pages/admin/dashboard/Layout.jsx +3 -3
- package/src/modules/cms/pages/admin/widgetEdit/WidgetForm.jsx +52 -0
- package/src/modules/cms/pages/admin/widgetEdit/index.js +36 -0
- package/src/modules/cms/pages/admin/widgetEdit/route.json +4 -0
- package/src/modules/cms/pages/admin/widgetEdit+widgetNew/FormContent.jsx +69 -0
- package/src/modules/cms/pages/admin/widgetEdit+widgetNew/FormContent.scss +7 -0
- package/src/modules/cms/pages/admin/widgetEdit+widgetNew/General.jsx +185 -0
- package/src/modules/cms/pages/admin/widgetEdit+widgetNew/PageHeading.jsx +37 -0
- package/src/modules/cms/pages/admin/widgetEdit+widgetNew/Setting.jsx +55 -0
- package/src/modules/cms/pages/admin/widgetGrid/Grid.jsx +415 -0
- package/src/modules/cms/pages/admin/widgetGrid/Heading.jsx +11 -0
- package/src/modules/cms/pages/admin/widgetGrid/NewWidgetButton.jsx +52 -0
- package/src/modules/cms/pages/admin/widgetGrid/index.js +15 -0
- package/src/modules/cms/pages/admin/widgetGrid/route.json +4 -0
- package/src/modules/cms/pages/admin/widgetNew/WidgetNewForm.jsx +60 -0
- package/src/modules/cms/pages/admin/widgetNew/index.js +11 -0
- package/src/modules/cms/pages/admin/widgetNew/route.json +4 -0
- package/src/modules/cms/pages/admin/widgetNew/typeValidate.js +21 -0
- package/src/modules/cms/pages/frontStore/all/Breadcrumb.jsx +1 -1
- package/src/modules/cms/pages/frontStore/all/Footer.jsx +2 -2
- package/src/modules/cms/pages/frontStore/all/Layout.jsx +3 -3
- package/src/modules/cms/pages/frontStore/all/Layout.scss +13 -0
- package/src/modules/cms/pages/frontStore/all/Logo.jsx +2 -2
- package/src/modules/cms/pages/frontStore/all/Logo.scss +2 -4
- package/src/modules/cms/pages/frontStore/all/Notification.scss +1 -1
- package/src/modules/cms/pages/frontStore/cmsPageView/Layout.jsx +2 -2
- package/src/modules/cms/pages/frontStore/cmsPageView/View.jsx +5 -3
- package/src/modules/cms/pages/frontStore/cmsPageView/index.js +6 -12
- package/src/modules/cms/pages/frontStore/cmsPageView/route.json +2 -1
- package/src/modules/cms/pages/frontStore/homepage/route.json +2 -1
- package/src/modules/cms/pages/frontStore/notFound/NotFound.jsx +4 -4
- package/src/modules/cms/pages/frontStore/notFound/route.json +2 -1
- package/src/modules/cms/pages/frontStore/staticAsset/[context]staticAssets[auth].js +1 -1
- package/src/modules/cms/services/CMSPageCollection.js +10 -10
- package/src/modules/cms/services/WidgetCollection.js +62 -0
- package/src/modules/cms/services/getWidgetsBaseQuery.js +7 -0
- package/src/modules/cms/services/page/createPage.js +1 -2
- package/src/modules/cms/services/page/pageDataSchema.json +0 -4
- package/src/modules/cms/services/registerDefaultWidgetCollectionFilters.js +62 -0
- package/src/modules/cms/services/tailwind.admin.config.js +22 -107
- package/src/modules/cms/services/tailwind.frontStore.config.js +23 -108
- package/src/modules/cms/services/widget/createWidget.js +73 -0
- package/src/modules/cms/services/widget/deleteWidget.js +49 -0
- package/src/modules/cms/services/widget/loadWidgetInstances.js +54 -0
- package/src/modules/cms/services/widget/updateWidget.js +86 -0
- package/src/modules/cms/services/widget/widgetDataSchema.json +29 -0
- package/src/modules/cod/pages/admin/paymentSetting/CODSetting.jsx +2 -2
- package/src/modules/cod/pages/frontStore/checkout/CashOnDelivery.jsx +1 -1
- package/src/modules/customer/bootstrap.js +21 -4
- package/src/modules/customer/pages/admin/customerEdit/CustomerEditForm.jsx +3 -3
- package/src/modules/customer/pages/admin/customerEdit+customerNew/OrderHistory.jsx +1 -1
- package/src/modules/customer/pages/admin/customerGrid/Grid.jsx +3 -3
- package/src/modules/customer/pages/frontStore/account/AccountDetails.jsx +3 -3
- package/src/modules/customer/pages/frontStore/account/Layout.jsx +3 -3
- package/src/modules/customer/pages/frontStore/account/OrderHistory.jsx +1 -1
- package/src/modules/customer/pages/frontStore/account/route.json +2 -1
- package/src/modules/customer/pages/frontStore/login/LoginForm.jsx +2 -2
- package/src/modules/customer/pages/frontStore/login/route.json +2 -1
- package/src/modules/customer/pages/frontStore/register/RegisterForm.jsx +2 -2
- package/src/modules/customer/pages/frontStore/register/route.json +2 -1
- package/src/modules/customer/pages/frontStore/resetPasswordPage/ResetPasswordForm.jsx +2 -2
- package/src/modules/customer/pages/frontStore/resetPasswordPage/route.json +2 -1
- package/src/modules/customer/pages/frontStore/updatePasswordPage/UpdatePasswordForm.jsx +3 -3
- package/src/modules/customer/pages/frontStore/updatePasswordPage/route.json +2 -1
- package/src/modules/customer/services/CustomerCollection.js +10 -10
- package/src/modules/customer/services/CustomerGroupCollection.js +10 -10
- package/src/modules/graphql/pages/global/[bodyParser]buildQuery[graphql].js +241 -6
- package/src/modules/graphql/pages/global/[buildQuery]graphql[notification].js +12 -8
- package/src/modules/oms/bootstrap.js +87 -3
- package/src/modules/oms/graphql/types/Order/Order.graphql +11 -2
- package/src/modules/oms/graphql/types/Order/Order.resolvers.js +7 -1
- package/src/modules/oms/pages/admin/dashboard/Bestsellers.jsx +2 -2
- package/src/modules/oms/pages/admin/dashboard/Lifetimesales.jsx +5 -5
- package/src/modules/oms/pages/admin/orderEdit/AddTrackingButton.jsx +1 -1
- package/src/modules/oms/pages/admin/orderEdit/Items.jsx +7 -7
- package/src/modules/oms/pages/admin/orderEdit/Layout.jsx +3 -3
- package/src/modules/oms/pages/admin/orderEdit/Payment.jsx +6 -6
- package/src/modules/oms/pages/admin/orderEdit/ShipButton.jsx +1 -1
- package/src/modules/oms/pages/admin/orderGrid/Grid.jsx +3 -3
- package/src/modules/oms/services/OrderCollection.js +10 -10
- package/src/modules/paypal/api/paypalCreateOrder/[bodyParser]createOrder.js +55 -24
- package/src/modules/paypal/pages/admin/paymentSetting/PaypalSetting.jsx +6 -6
- package/src/modules/paypal/pages/frontStore/checkout/Paypal.jsx +3 -4
- package/src/modules/promotion/bootstrap.js +19 -101
- package/src/modules/promotion/pages/admin/couponEdit+couponNew/DiscountType.jsx +1 -1
- package/src/modules/promotion/pages/admin/couponEdit+couponNew/FormContent.jsx +5 -5
- package/src/modules/promotion/pages/admin/couponGrid/Grid.jsx +3 -3
- package/src/modules/promotion/pages/frontStore/cart/Coupon.jsx +2 -2
- package/src/modules/promotion/services/CouponCollection.js +10 -10
- package/src/modules/promotion/services/couponValidator.js +4 -7
- package/src/modules/promotion/services/discountCalculator.js +2 -7
- package/src/modules/promotion/services/registerCartItemPromotionFields.js +80 -0
- package/src/modules/promotion/services/registerCartPromotionFields.js +128 -0
- package/src/modules/promotion/services/registerDefaultCalculators.js +48 -20
- package/src/modules/promotion/services/registerDefaultValidators.js +16 -4
- package/src/modules/setting/pages/admin/paymentSetting/PaymentSetting.jsx +2 -2
- package/src/modules/setting/pages/admin/storeSetting/StoreSetting.jsx +98 -35
- package/src/modules/stripe/pages/admin/paymentSetting/StripePayment.jsx +5 -5
- package/src/modules/stripe/pages/frontStore/checkout/Stripe.jsx +1 -1
- package/src/modules/tax/bootstrap.js +40 -5
- package/src/modules/tax/graphql/types/Product/Price/ProductPrice.resolvers.js +6 -39
- package/src/modules/tax/graphql/types/TaxSetting/TaxSetting.graphql +1 -2
- package/src/modules/tax/graphql/types/TaxSetting/TaxSetting.resolvers.js +1 -8
- package/src/modules/tax/pages/admin/taxSetting/TaxSetting.jsx +4 -4
- package/src/modules/tax/services/TaxClassCollection.js +10 -10
- package/src/modules/tax/services/calculateTaxAmount.js +12 -9
- package/src/modules/tax/services/registerCartItemTaxPercentField.js +76 -0
- package/src/modules/auth/services/adminSessionMiddleware.js +0 -0
- package/src/modules/catalog/pages/frontStore/homepage/FeaturedCategories.jsx +0 -58
- package/src/modules/cms/pages/admin/cmsPageEdit+cmsPageNew/StatusAndLayout.jsx +0 -61
- package/src/modules/cms/pages/frontStore/all/Menu.jsx +0 -46
- package/src/modules/cms/pages/frontStore/all/Menu.scss +0 -7
- package/src/modules/cms/pages/frontStore/all/MobileMenu.jsx +0 -73
- package/src/modules/cms/pages/frontStore/all/MobileMenu.scss +0 -35
- package/src/modules/cms/pages/frontStore/homepage/MainBanner.jsx +0 -31
- package/src/modules/cms/pages/frontStore/homepage/MainBanner.scss +0 -48
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
const { select } = require('@evershop/postgres-query-builder');
|
|
2
|
+
const { pool } = require('../../lib/postgres/connection');
|
|
1
3
|
const {
|
|
2
4
|
defaultPaginationFilters
|
|
3
5
|
} = require('../../lib/util/defaultPaginationFilters');
|
|
4
6
|
const { addProcessor } = require('../../lib/util/registry');
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const {
|
|
8
|
+
registerCartItemPromotionFields
|
|
9
|
+
} = require('./services/registerCartItemPromotionFields');
|
|
10
|
+
const {
|
|
11
|
+
registerCartPromotionFields
|
|
12
|
+
} = require('./services/registerCartPromotionFields');
|
|
8
13
|
const {
|
|
9
14
|
registerDefaultCalculators
|
|
10
15
|
} = require('./services/registerDefaultCalculators');
|
|
@@ -14,106 +19,19 @@ const {
|
|
|
14
19
|
} = require('./services/registerDefaultValidators');
|
|
15
20
|
|
|
16
21
|
module.exports = () => {
|
|
17
|
-
addProcessor('cartFields', (fields) =>
|
|
18
|
-
fields.concat(
|
|
19
|
-
/** Adding fields to the Cart object */
|
|
20
|
-
[
|
|
21
|
-
{
|
|
22
|
-
key: 'coupon',
|
|
23
|
-
resolvers: [
|
|
24
|
-
async function resolver(coupon) {
|
|
25
|
-
if (coupon) {
|
|
26
|
-
const check = await validateCoupon(this, coupon);
|
|
27
|
-
if (check === true) {
|
|
28
|
-
return coupon;
|
|
29
|
-
} else {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
dependencies: ['items'] // TODO: Add customer id and customer group id as a dependency
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
key: 'discount_amount',
|
|
41
|
-
resolvers: [
|
|
42
|
-
async function resolver() {
|
|
43
|
-
const coupon = this.getData('coupon');
|
|
44
|
-
const items = this.getItems();
|
|
45
|
-
if (!coupon) {
|
|
46
|
-
await Promise.all(
|
|
47
|
-
items.map(async (item) => {
|
|
48
|
-
item.setData('discount_amount', 0);
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
// Start calculate discount amount
|
|
54
|
-
await calculateDiscount(this, coupon);
|
|
55
|
-
let discountAmount = 0;
|
|
56
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
57
|
-
for (const item of items) {
|
|
58
|
-
discountAmount += item.getData('discount_amount');
|
|
59
|
-
}
|
|
60
|
-
return discountAmount;
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
dependencies: ['coupon']
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
key: 'grand_total',
|
|
67
|
-
resolvers: [
|
|
68
|
-
async function resolver(previousValue) {
|
|
69
|
-
return previousValue - this.getData('discount_amount');
|
|
70
|
-
}
|
|
71
|
-
],
|
|
72
|
-
dependencies: ['discount_amount']
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
key: 'shipping_fee_excl_tax', // This is to make sure the shipping fee is calculated after the coupon validation
|
|
76
|
-
resolvers: [],
|
|
77
|
-
dependencies: ['coupon']
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
|
|
83
22
|
addProcessor(
|
|
84
|
-
'
|
|
85
|
-
(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const requestedField = this.getTriggeredField();
|
|
94
|
-
const requestedValue = this.getRequestedValue();
|
|
95
|
-
if (requestedField === 'discount_amount') {
|
|
96
|
-
return toPrice(requestedValue);
|
|
97
|
-
} else {
|
|
98
|
-
return 0;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
key: 'total',
|
|
105
|
-
resolvers: [
|
|
106
|
-
async function resolver(previousValue) {
|
|
107
|
-
return previousValue - this.getData('discount_amount');
|
|
108
|
-
}
|
|
109
|
-
],
|
|
110
|
-
dependencies: ['discount_amount']
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
),
|
|
114
|
-
11
|
|
23
|
+
'couponLoaderFunction',
|
|
24
|
+
() => async (couponCode) => {
|
|
25
|
+
const coupon = await select()
|
|
26
|
+
.from('coupon')
|
|
27
|
+
.where('coupon', '=', couponCode)
|
|
28
|
+
.load(pool);
|
|
29
|
+
return coupon;
|
|
30
|
+
},
|
|
31
|
+
0
|
|
115
32
|
);
|
|
116
|
-
|
|
33
|
+
addProcessor('cartFields', registerCartPromotionFields, 0);
|
|
34
|
+
addProcessor('cartItemFields', registerCartItemPromotionFields, 11);
|
|
117
35
|
addProcessor('couponValidatorFunctions', registerDefaultValidators);
|
|
118
36
|
addProcessor('discountCalculatorFunctions', registerDefaultCalculators);
|
|
119
37
|
|
|
@@ -10,7 +10,7 @@ export default function FormContent({ gridUrl }) {
|
|
|
10
10
|
const { state } = useFormContext();
|
|
11
11
|
return (
|
|
12
12
|
<>
|
|
13
|
-
<div className="grid grid-cols-1 gap-
|
|
13
|
+
<div className="grid grid-cols-1 gap-8">
|
|
14
14
|
<Card title="General">
|
|
15
15
|
<Card.Session>
|
|
16
16
|
<Area id="couponEditGeneral" noOuter />
|
|
@@ -21,15 +21,15 @@ export default function FormContent({ gridUrl }) {
|
|
|
21
21
|
<Area id="couponEditDiscountType" noOuter />
|
|
22
22
|
</Card.Session>
|
|
23
23
|
</Card>
|
|
24
|
-
<div className="grid grid-cols-3 gap-x-
|
|
25
|
-
<div className="col-span-2 grid grid-cols-1 gap-
|
|
24
|
+
<div className="grid grid-cols-3 gap-x-8 grid-flow-row ">
|
|
25
|
+
<div className="col-span-2 grid grid-cols-1 gap-8 auto-rows-max">
|
|
26
26
|
<Card title="Order conditions">
|
|
27
27
|
<Card.Session>
|
|
28
28
|
<Area id="couponEditLeft" noOuter className="col-8" />
|
|
29
29
|
</Card.Session>
|
|
30
30
|
</Card>
|
|
31
31
|
</div>
|
|
32
|
-
<div className="col-span-1 grid grid-cols-1 gap-
|
|
32
|
+
<div className="col-span-1 grid grid-cols-1 gap-8 auto-rows-max">
|
|
33
33
|
<Card title="Customer conditions">
|
|
34
34
|
<Card.Session>
|
|
35
35
|
<Area id="couponEditRight" className="col-4" noOuter />
|
|
@@ -38,7 +38,7 @@ export default function FormContent({ gridUrl }) {
|
|
|
38
38
|
</div>
|
|
39
39
|
</div>
|
|
40
40
|
</div>
|
|
41
|
-
<div className="form-submit-button flex border-t border-divider mt-
|
|
41
|
+
<div className="form-submit-button flex border-t border-divider mt-6 pt-6 justify-between">
|
|
42
42
|
<Button
|
|
43
43
|
title="Cancel"
|
|
44
44
|
variant="critical"
|
|
@@ -123,7 +123,7 @@ function Actions({ coupons = [], selectedIds = [] }) {
|
|
|
123
123
|
{selectedIds.length > 0 && (
|
|
124
124
|
<td style={{ borderTop: 0 }} colSpan="100">
|
|
125
125
|
<div className="inline-flex border border-divider rounded justify-items-start">
|
|
126
|
-
<a href="#" className="font-semibold pt-
|
|
126
|
+
<a href="#" className="font-semibold pt-3 pb-3 pl-6 pr-6">
|
|
127
127
|
{selectedIds.length} selected
|
|
128
128
|
</a>
|
|
129
129
|
{actions.map((action) => (
|
|
@@ -133,7 +133,7 @@ function Actions({ coupons = [], selectedIds = [] }) {
|
|
|
133
133
|
e.preventDefault();
|
|
134
134
|
action.onAction();
|
|
135
135
|
}}
|
|
136
|
-
className="font-semibold pt-
|
|
136
|
+
className="font-semibold pt-3 pb-3 pl-6 pr-6 block border-l border-divider self-center"
|
|
137
137
|
>
|
|
138
138
|
<span>{action.name}</span>
|
|
139
139
|
</a>
|
|
@@ -173,7 +173,7 @@ export default function CouponGrid({
|
|
|
173
173
|
<Card.Session
|
|
174
174
|
title={
|
|
175
175
|
<Form submitBtn={false}>
|
|
176
|
-
<div className="flex gap-
|
|
176
|
+
<div className="flex gap-8 justify-center items-center">
|
|
177
177
|
<Area
|
|
178
178
|
id="couponGridFilter"
|
|
179
179
|
noOuter
|
|
@@ -11,7 +11,7 @@ export default function CouponForm({ cart: { applyCouponApi } }) {
|
|
|
11
11
|
const AppContextDispatch = useAppDispatch();
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
|
-
<div className="mt-
|
|
14
|
+
<div className="mt-16">
|
|
15
15
|
<Form
|
|
16
16
|
method="POST"
|
|
17
17
|
isJSON
|
|
@@ -34,7 +34,7 @@ export default function CouponForm({ cart: { applyCouponApi } }) {
|
|
|
34
34
|
id="couponForm"
|
|
35
35
|
>
|
|
36
36
|
<p style={{ fontWeight: 600 }}>{_('Promotion code?')}</p>
|
|
37
|
-
<div className="grid grid-cols-3 gap-
|
|
37
|
+
<div className="grid grid-cols-3 gap-8" style={{ width: '300px' }}>
|
|
38
38
|
<div className="col-span-2">
|
|
39
39
|
<Field
|
|
40
40
|
type="text"
|
|
@@ -17,16 +17,16 @@ class CouponCollection {
|
|
|
17
17
|
);
|
|
18
18
|
|
|
19
19
|
couponCollectionFilters.forEach((filter) => {
|
|
20
|
-
const check = filters.find(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
const check = filters.find(
|
|
21
|
+
(f) => f.key === filter.key && filter.operation.includes(f.operation)
|
|
22
|
+
);
|
|
23
|
+
if (filter.key === '*' || check) {
|
|
24
|
+
filter.callback(
|
|
25
|
+
this.baseQuery,
|
|
26
|
+
check?.operation,
|
|
27
|
+
check?.value,
|
|
28
|
+
currentFilters
|
|
29
|
+
);
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const { pool } = require('@evershop/evershop/src/lib/postgres/connection');
|
|
1
|
+
const { info } = require('@evershop/evershop/src/lib/log/logger');
|
|
3
2
|
const { getValueSync } = require('@evershop/evershop/src/lib/util/registry');
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -10,11 +9,9 @@ const { getValueSync } = require('@evershop/evershop/src/lib/util/registry');
|
|
|
10
9
|
*/
|
|
11
10
|
async function validateCoupon(cart, couponCode) {
|
|
12
11
|
const validatorFunctions = getValueSync('couponValidatorFunctions', []);
|
|
12
|
+
const couponLoader = getValueSync('couponLoaderFunction');
|
|
13
13
|
let flag = true;
|
|
14
|
-
const coupon = await
|
|
15
|
-
.from('coupon')
|
|
16
|
-
.where('coupon', '=', couponCode)
|
|
17
|
-
.load(pool);
|
|
14
|
+
const coupon = await couponLoader(couponCode);
|
|
18
15
|
if (!coupon) {
|
|
19
16
|
return false;
|
|
20
17
|
}
|
|
@@ -27,11 +24,11 @@ async function validateCoupon(cart, couponCode) {
|
|
|
27
24
|
flag = false;
|
|
28
25
|
}
|
|
29
26
|
} catch (e) {
|
|
27
|
+
info(e);
|
|
30
28
|
flag = false;
|
|
31
29
|
}
|
|
32
30
|
})
|
|
33
31
|
);
|
|
34
|
-
|
|
35
32
|
return flag;
|
|
36
33
|
}
|
|
37
34
|
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
const { pool } = require('@evershop/evershop/src/lib/postgres/connection');
|
|
2
1
|
const { getValueSync } = require('@evershop/evershop/src/lib/util/registry');
|
|
3
|
-
const { select } = require('@evershop/postgres-query-builder');
|
|
4
2
|
|
|
5
3
|
exports.calculateDiscount = async function calculateDiscount(
|
|
6
4
|
cart,
|
|
7
5
|
couponCode = null
|
|
8
6
|
) {
|
|
9
7
|
const calculatorFunctions = getValueSync('discountCalculatorFunctions', []);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
.where('coupon', '=', couponCode)
|
|
13
|
-
.load(pool);
|
|
14
|
-
|
|
8
|
+
const couponLoader = getValueSync('couponLoaderFunction');
|
|
9
|
+
const coupon = await couponLoader(couponCode);
|
|
15
10
|
// Calling calculator functions
|
|
16
11
|
for (let i = 0; i < calculatorFunctions.length; i += 1) {
|
|
17
12
|
await calculatorFunctions[i](cart, coupon);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');
|
|
2
|
+
const { toPrice } = require('../../checkout/services/toPrice');
|
|
3
|
+
|
|
4
|
+
module.exports = exports = {};
|
|
5
|
+
module.exports.registerCartItemPromotionFields =
|
|
6
|
+
function registerCartItemPromotionFields(fields) {
|
|
7
|
+
const newFields = fields.concat(
|
|
8
|
+
/** Adding fields to the Cart Item object */
|
|
9
|
+
[
|
|
10
|
+
{
|
|
11
|
+
key: 'discount_amount',
|
|
12
|
+
resolvers: [
|
|
13
|
+
async function resolver() {
|
|
14
|
+
const requestedField = this.getTriggeredField();
|
|
15
|
+
const requestedValue = this.getRequestedValue();
|
|
16
|
+
if (requestedField === 'discount_amount') {
|
|
17
|
+
return toPrice(requestedValue);
|
|
18
|
+
} else {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: 'line_total_with_discount',
|
|
26
|
+
resolvers: [
|
|
27
|
+
async function resolver() {
|
|
28
|
+
const priceIncludingTax = getConfig(
|
|
29
|
+
'pricing.tax.price_including_tax',
|
|
30
|
+
false
|
|
31
|
+
);
|
|
32
|
+
if (!priceIncludingTax) {
|
|
33
|
+
return (
|
|
34
|
+
this.getData('line_total') - this.getData('discount_amount')
|
|
35
|
+
);
|
|
36
|
+
} else {
|
|
37
|
+
return (
|
|
38
|
+
this.getData('line_total_incl_tax') -
|
|
39
|
+
this.getData('discount_amount') -
|
|
40
|
+
this.getData('tax_amount')
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
dependencies: ['line_total', 'line_total_incl_tax', 'tax_amount']
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: 'line_total_with_discount_incl_tax',
|
|
49
|
+
resolvers: [
|
|
50
|
+
async function resolver() {
|
|
51
|
+
const priceIncludingTax = getConfig(
|
|
52
|
+
'pricing.tax.price_including_tax',
|
|
53
|
+
false
|
|
54
|
+
);
|
|
55
|
+
if (!priceIncludingTax) {
|
|
56
|
+
return toPrice(
|
|
57
|
+
this.getData('line_total') -
|
|
58
|
+
this.getData('discount_amount') +
|
|
59
|
+
this.getData('tax_amount')
|
|
60
|
+
);
|
|
61
|
+
} else {
|
|
62
|
+
return toPrice(
|
|
63
|
+
this.getData('line_total_incl_tax') -
|
|
64
|
+
this.getData('discount_amount')
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
dependencies: [
|
|
70
|
+
'line_total_incl_tax',
|
|
71
|
+
'line_total',
|
|
72
|
+
'qty',
|
|
73
|
+
'tax_amount',
|
|
74
|
+
'discount_amount'
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
);
|
|
79
|
+
return newFields;
|
|
80
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');
|
|
2
|
+
const { validateCoupon } = require('./couponValidator');
|
|
3
|
+
const { calculateDiscount } = require('./discountCalculator');
|
|
4
|
+
const { toPrice } = require('../../checkout/services/toPrice');
|
|
5
|
+
|
|
6
|
+
module.exports = exports = {};
|
|
7
|
+
module.exports.registerCartPromotionFields =
|
|
8
|
+
function registerCartPromotionFields(fields) {
|
|
9
|
+
const newFields = fields.concat(
|
|
10
|
+
/** Adding fields to the Cart object */
|
|
11
|
+
[
|
|
12
|
+
{
|
|
13
|
+
key: 'coupon',
|
|
14
|
+
resolvers: [
|
|
15
|
+
async function resolver(coupon) {
|
|
16
|
+
if (coupon) {
|
|
17
|
+
const check = await validateCoupon(this, coupon);
|
|
18
|
+
if (check === true) {
|
|
19
|
+
return coupon;
|
|
20
|
+
} else {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
dependencies: ['items'] // TODO: Add customer id and customer group id as a dependency
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: 'discount_amount',
|
|
32
|
+
resolvers: [
|
|
33
|
+
async function resolver() {
|
|
34
|
+
const coupon = this.getData('coupon');
|
|
35
|
+
const items = this.getItems();
|
|
36
|
+
if (!coupon) {
|
|
37
|
+
await Promise.all(
|
|
38
|
+
items.map(async (item) => {
|
|
39
|
+
item.setData('discount_amount', 0);
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
// Start calculate discount amount
|
|
45
|
+
await calculateDiscount(this, coupon);
|
|
46
|
+
let discountAmount = 0;
|
|
47
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
48
|
+
for (const item of items) {
|
|
49
|
+
discountAmount += item.getData('discount_amount');
|
|
50
|
+
}
|
|
51
|
+
return discountAmount;
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
dependencies: ['coupon', 'sub_total', 'sub_total_incl_tax']
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: 'tax_amount',
|
|
58
|
+
resolvers: [
|
|
59
|
+
async function resolver(previousValue) {
|
|
60
|
+
return previousValue;
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
dependencies: ['discount_amount']
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: 'sub_total_with_discount',
|
|
67
|
+
resolvers: [
|
|
68
|
+
async function resolver() {
|
|
69
|
+
const priceIncludingTax = getConfig(
|
|
70
|
+
'pricing.tax.price_including_tax',
|
|
71
|
+
false
|
|
72
|
+
);
|
|
73
|
+
if (!priceIncludingTax) {
|
|
74
|
+
return toPrice(
|
|
75
|
+
this.getData('sub_total') - this.getData('discount_amount')
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
return toPrice(
|
|
79
|
+
this.getData('sub_total_incl_tax') -
|
|
80
|
+
this.getData('discount_amount') -
|
|
81
|
+
this.getData('tax_amount')
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
dependencies: [
|
|
87
|
+
'sub_total',
|
|
88
|
+
'sub_total_incl_tax',
|
|
89
|
+
'discount_amount',
|
|
90
|
+
'tax_amount'
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: 'sub_total_with_discount_incl_tax',
|
|
95
|
+
resolvers: [
|
|
96
|
+
async function resolver() {
|
|
97
|
+
return toPrice(
|
|
98
|
+
this.getData('sub_total_with_discount') +
|
|
99
|
+
this.getData('tax_amount')
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
dependencies: ['sub_total_with_discount', 'tax_amount']
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
key: 'shipping_fee_excl_tax', // This is to make sure the shipping fee is calculated after the coupon validation
|
|
107
|
+
resolvers: [],
|
|
108
|
+
dependencies: ['coupon']
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
key: 'grand_total',
|
|
112
|
+
resolvers: [
|
|
113
|
+
async function resolver() {
|
|
114
|
+
return toPrice(
|
|
115
|
+
this.getData('sub_total_with_discount_incl_tax') +
|
|
116
|
+
this.getData('shipping_fee_incl_tax')
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
dependencies: [
|
|
121
|
+
'sub_total_with_discount_incl_tax',
|
|
122
|
+
'shipping_fee_incl_tax'
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
);
|
|
127
|
+
return newFields;
|
|
128
|
+
};
|