@evershop/evershop 1.0.0 → 1.1.0
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/client/index.js +1 -1
- package/bin/build/complie.js +1 -1
- package/bin/build/index.js +1 -1
- package/bin/build/server/index.js +1 -1
- package/bin/build/server/useDDL.js +1 -1
- package/bin/dev/index.js +2 -1
- package/bin/evershop +8 -7
- package/bin/extension/index.js +1 -1
- package/bin/install/index.js +1 -1
- package/bin/lib/addDefaultMiddlewareFuncs.js +2 -2
- package/bin/lib/app.js +1 -1
- package/bin/lib/bootstrap/migrate.js +1 -1
- package/bin/lib/buildEntry.js +1 -1
- package/bin/lib/onError.js +1 -1
- package/bin/lib/onListening.js +1 -1
- package/bin/lib/startUp.js +10 -9
- package/bin/lib/watch/watchComponents.js +16 -26
- package/bin/lib/watch/watchMF.js +1 -1
- package/bin/lib/watch/watchMR.js +1 -1
- package/bin/lib/watch/watchSchema.js +1 -1
- package/bin/user/changePassword.js +1 -1
- package/bin/user/create.js +1 -1
- package/package.json +2 -2
- package/src/components/admin/catalog/productEdit/category/CategoryItem.jsx +1 -1
- package/src/components/admin/catalog/productEdit/category/CategoryTree.jsx +1 -1
- package/src/components/admin/catalog/productEdit/variants/CreateVariantGroup.jsx +3 -8
- package/src/components/admin/catalog/productEdit/variants/Variant.jsx +1 -1
- package/src/components/admin/catalog/productEdit/variants/VariantModal.jsx +62 -6
- package/src/components/admin/catalog/productEdit/variants/Variants.jsx +1 -1
- package/src/components/admin/checkout/shippingSetting/Method.jsx +130 -0
- package/src/components/admin/{oms → checkout}/shippingSetting/MethodForm.jsx +124 -13
- package/src/components/admin/{oms → checkout}/shippingSetting/Methods.jsx +2 -2
- package/src/components/admin/checkout/shippingSetting/PriceBasedPrice.jsx +101 -0
- package/src/components/admin/checkout/shippingSetting/WeightBasedPrice.jsx +101 -0
- package/src/components/admin/{oms → checkout}/shippingSetting/Zone.jsx +34 -4
- package/src/components/admin/{oms → checkout}/shippingSetting/Zones.jsx +6 -3
- package/src/components/admin/promotion/couponEdit/AttributeGroupSelector.jsx +5 -5
- package/src/components/admin/promotion/couponEdit/CategorySelector.jsx +5 -5
- package/src/components/admin/promotion/couponEdit/CollectionSelector.jsx +5 -5
- package/src/components/admin/promotion/couponEdit/ProductSkuSelector.jsx +27 -6
- package/src/components/common/context/checkout.jsx +8 -14
- package/src/components/common/form/Field.jsx +1 -1
- package/src/components/common/form/fields/Input.jsx +2 -1
- package/src/components/common/form/validator.js +6 -2
- package/src/components/common/grid/headers/Dummy.jsx +1 -1
- package/src/components/common/grid/headers/Sortable.jsx +148 -0
- package/src/components/common/grid/rows/StatusRow.jsx +1 -1
- package/src/components/common/list/Filter.jsx +83 -0
- package/src/components/common/list/Filter.scss +39 -0
- package/src/components/frontStore/catalog/categoryView/filter/AttributeFilter.jsx +19 -5
- package/src/components/frontStore/catalog/categoryView/filter/CategoryFilter.jsx +59 -52
- package/src/components/frontStore/catalog/categoryView/filter/PriceFilter.jsx +20 -11
- package/src/components/frontStore/catalog/product/list/SortOptions.jsx +4 -2
- package/src/components/frontStore/catalog/product/list/Sorting.jsx +5 -5
- package/src/components/frontStore/checkout/checkout/payment/paymentStep/StepContent.jsx +9 -6
- package/src/components/frontStore/stripe/checkout/CheckoutForm.jsx +8 -4
- package/src/lib/event/callSubscibers.js +14 -11
- package/src/lib/event/event-manager.js +1 -1
- package/src/lib/event/loadSubscribers.js +2 -2
- package/src/lib/helpers.js +3 -1
- package/src/lib/log/CustomColorize.js +22 -0
- package/src/lib/log/logger.js +153 -19
- package/src/lib/middleware/Handler.js +2 -3
- package/src/lib/middleware/async.js +5 -9
- package/src/lib/middleware/sync.js +5 -10
- package/src/lib/middleware/tests/app/app.js +1 -1
- package/src/lib/router/buildAbsoluteUrl.js +1 -1
- package/src/lib/util/buildFilterFromUrl.js +31 -64
- package/src/lib/util/defaultPaginationFilters.js +102 -0
- package/src/lib/util/filterOperationMapp.js +16 -0
- package/src/lib/util/registry.js +44 -6
- package/src/lib/webpack/dev/createConfigClient.js +2 -0
- package/src/lib/webpack/loaders/AreaLoader.js +1 -1
- package/src/lib/webpack/loaders/loadTranslationFromCsv.js +1 -1
- package/src/lib/webpack/plugins/Tailwindcss.js +1 -1
- package/src/modules/auth/graphql/types/AdminUser/AdminUser.admin.resolvers.js +6 -6
- package/src/modules/auth/pages/admin/adminLogin/LoginForm.jsx +1 -15
- package/src/modules/base/api/global/[apiResponse]apiErrorHandler.js +2 -2
- package/src/modules/base/pages/global/[response]errorHandler.js +2 -2
- package/src/modules/catalog/api/addProductToCategory/addProducts.js +1 -1
- package/src/modules/catalog/api/addProductToCollection/addProducts.js +35 -22
- package/src/modules/catalog/api/removeProductFromCollection/removeProducts.js +20 -5
- package/src/modules/catalog/bootstrap.js +63 -0
- package/src/modules/catalog/graphql/types/Attribute/Attribute.admin.graphql +2 -2
- package/src/modules/catalog/graphql/types/Attribute/Attribute.admin.resolvers.js +48 -276
- package/src/modules/catalog/graphql/types/Category/Category.graphql +15 -2
- package/src/modules/catalog/graphql/types/Category/Category.resolvers.js +2 -2
- package/src/modules/catalog/graphql/types/Collection/Collection.resolvers.js +2 -2
- package/src/modules/catalog/graphql/types/Product/Product.resolvers.js +1 -1
- package/src/modules/catalog/graphql/types/Product/Variant/Variant.graphql +2 -2
- package/src/modules/catalog/graphql/types/Product/Variant/Variant.resolvers.js +68 -92
- package/src/modules/catalog/pages/admin/attributeEdit+attributeNew/General.jsx +13 -9
- package/src/modules/catalog/pages/admin/attributeGrid/Grid.jsx +82 -39
- package/src/modules/catalog/pages/admin/attributeGrid/index.js +1 -1
- package/src/modules/catalog/pages/admin/categoryEdit/Products.jsx +5 -5
- package/src/modules/catalog/pages/admin/categoryGrid/Grid.jsx +48 -16
- package/src/modules/catalog/pages/admin/categoryGrid/index.js +1 -1
- package/src/modules/catalog/pages/admin/collectionEdit/Products.jsx +5 -5
- package/src/modules/catalog/pages/admin/collectionGrid/Grid.jsx +46 -5
- package/src/modules/catalog/pages/admin/collectionGrid/index.js +1 -1
- package/src/modules/catalog/pages/admin/productEdit+productNew/Attributes.jsx +28 -24
- package/src/modules/catalog/pages/admin/productGrid/Grid.jsx +158 -26
- package/src/modules/catalog/pages/admin/productGrid/index.js +1 -2
- package/src/modules/catalog/pages/frontStore/all/SearchBox.jsx +2 -1
- package/src/modules/catalog/pages/frontStore/catalogSearch/[index]filters.js +4 -59
- package/src/modules/catalog/pages/frontStore/catalogSearch/index.js +11 -0
- package/src/modules/catalog/pages/frontStore/categoryView/Filter.jsx +22 -6
- package/src/modules/catalog/pages/frontStore/categoryView/Filter.scss +2 -0
- package/src/modules/catalog/pages/frontStore/categoryView/[index]filters.js +5 -105
- package/src/modules/catalog/pages/frontStore/homepage/FeaturedProducts.jsx +1 -1
- package/src/modules/catalog/pages/frontStore/productView/Form.jsx +8 -3
- package/src/modules/catalog/pages/frontStore/productView/Variants.jsx +102 -40
- package/src/modules/catalog/services/AttributeCollection.js +59 -0
- package/src/modules/catalog/services/AttributeGroupCollection.js +100 -0
- package/src/modules/catalog/services/CategoryCollection.js +27 -84
- package/src/modules/catalog/services/CollectionCollection.js +24 -72
- package/src/modules/catalog/services/ProductCollection.js +50 -216
- package/src/modules/catalog/services/attribute/deleteProductAttribute.js +15 -0
- package/src/modules/catalog/services/getAttributeGroupsBaseQuery.js +3 -0
- package/src/modules/catalog/services/getAttributesBaseQuery.js +3 -0
- package/src/modules/catalog/services/getCollectionsBaseQuery.js +0 -1
- package/src/modules/catalog/services/product/updateProduct.js +8 -2
- package/src/modules/catalog/services/registerDefaultAttributeCollectionFilters.js +149 -0
- package/src/modules/catalog/services/registerDefaultCategoryCollectionFilters.js +85 -0
- package/src/modules/catalog/services/registerDefaultCollectionCollectionFilters.js +65 -0
- package/src/modules/catalog/services/registerDefaultProductCollectionFilters.js +219 -0
- package/src/modules/catalog/subscribers/category_created/buildUrlRewrite.js +1 -1
- package/src/modules/catalog/subscribers/category_deleted/deleteUrlRewrite.js +1 -1
- package/src/modules/catalog/subscribers/category_updated/builUrlRewrite.js +1 -1
- package/src/modules/catalog/subscribers/product_created/builUrlRewrite.js +1 -1
- package/src/modules/catalog/subscribers/product_deleted/deleteUrlRewrite.js +1 -1
- package/src/modules/catalog/subscribers/product_image_added/localGenerateProductImageVariant.js +3 -3
- package/src/modules/checkout/api/addCartShippingMethod/saveShippingMethod.js +6 -1
- package/src/modules/checkout/api/createCart/[context]bodyParser[auth].js +5 -0
- package/src/modules/checkout/api/createCart/createNewCart.js +92 -0
- package/src/modules/checkout/api/createCart/payloadSchema.json +44 -0
- package/src/modules/checkout/api/createCart/route.json +5 -0
- package/src/modules/checkout/api/deleteShippingZone/deleteShippingZone.js +58 -0
- package/src/modules/checkout/api/deleteShippingZone/route.json +5 -0
- package/src/modules/checkout/api/deleteShippingZoneMethod/deleteShippingZoneMethod.js +85 -0
- package/src/modules/checkout/api/deleteShippingZoneMethod/route.json +5 -0
- package/src/modules/checkout/api/getShippingMethods/sendMethods.js +37 -0
- package/src/modules/checkout/api/updateShippingMethod/[context]borderParser[auth].js +5 -0
- package/src/modules/checkout/api/updateShippingMethod/payloadSchema.json +12 -0
- package/src/modules/checkout/api/updateShippingMethod/route.json +5 -0
- package/src/modules/checkout/api/updateShippingMethod/updateShippingMethod.js +64 -0
- package/src/modules/checkout/api/updateShippingZoneMethod/payloadSchema.json +43 -1
- package/src/modules/checkout/api/updateShippingZoneMethod/updateShippingZoneMethod.js +17 -3
- package/src/modules/checkout/bootstrap.js +1 -1
- package/src/modules/checkout/graphql/types/ShippingMethod/ShippingMethod.graphql +1 -0
- package/src/modules/checkout/graphql/types/ShippingMethod/ShippingMethod.resolvers.js +4 -0
- package/src/modules/checkout/graphql/types/ShippingZone/ShippingZone.graphql +21 -1
- package/src/modules/checkout/graphql/types/ShippingZone/ShippingZone.resolvers.js +34 -4
- package/src/modules/checkout/graphql/types/Weight/Weight.resolvers.js +8 -11
- package/src/modules/checkout/migration/Version-1.0.5.js +28 -0
- package/src/modules/{oms → checkout}/pages/admin/shippingSetting/ShippingSetting.jsx +66 -43
- package/src/modules/checkout/pages/frontStore/all/[auth]addCustomerToCart.js +3 -3
- package/src/modules/checkout/pages/frontStore/checkout/PaymentStep.jsx +3 -2
- package/src/modules/checkout/pages/frontStore/checkout/ShippingMethods.jsx +23 -10
- package/src/modules/checkout/pages/frontStore/checkout/SummaryMobile.jsx +132 -0
- package/src/modules/checkout/pages/frontStore/checkout/SummaryMobile.scss +7 -0
- package/src/modules/checkout/services/cart/Cart.js +23 -7
- package/src/modules/checkout/services/cart/DataObject.js +3 -3
- package/src/modules/checkout/services/cart/registerCartBaseFields.js +32 -0
- package/src/modules/checkout/services/cart/registerCartItemBaseFields.js +3 -2
- package/src/modules/cms/bootstrap.js +17 -0
- package/src/modules/cms/graphql/types/CmsPage/CmsPage.resolvers.js +2 -11
- package/src/modules/cms/pages/admin/all/Layout.scss +3 -2
- package/src/modules/cms/pages/admin/all/SearchBox.jsx +1 -1
- package/src/modules/cms/pages/admin/cmsPageGrid/Grid.jsx +62 -9
- package/src/modules/cms/pages/admin/cmsPageGrid/index.js +1 -2
- package/src/modules/cms/services/CMSPageCollection.js +23 -70
- package/src/modules/cms/services/registerDefaultPageCollectionFilters.js +62 -0
- package/src/modules/cms/services/tailwind.admin.config.js +6 -1
- package/src/modules/customer/api/createCustomer/[bodyParser]createCustomer.js +2 -2
- package/src/modules/customer/api/resetPassword/[bodyParser]resetPassword.js +2 -2
- package/src/modules/customer/api/updatePassword/[bodyParser]updatePassword.js +2 -2
- package/src/modules/customer/bootstrap.js +29 -0
- package/src/modules/customer/graphql/types/Customer/Customer.admin.resolvers.js +2 -4
- package/src/modules/customer/pages/admin/customerGrid/Grid.jsx +108 -14
- package/src/modules/customer/pages/admin/customerGrid/index.js +1 -2
- package/src/modules/customer/pages/frontStore/login/LoginForm.jsx +0 -1
- package/src/modules/customer/services/CustomerCollection.js +23 -104
- package/src/modules/customer/services/CustomerGroupCollection.js +21 -70
- package/src/modules/customer/services/registerDefaultCustomerCollectionFilters.js +90 -0
- package/src/modules/customer/services/registerDefaultCustomerGroupCollectionFilters.js +50 -0
- package/src/modules/graphql/pages/global/[bodyParser]buildQuery[graphql].js +1 -1
- package/src/modules/graphql/pages/global/[buildQuery]graphql[notification].js +1 -1
- package/src/modules/graphql/services/graphqlMiddleware.js +1 -1
- package/src/modules/oms/bootstrap.js +17 -0
- package/src/modules/oms/graphql/types/Order/Order.admin.resolvers.js +1 -1
- package/src/modules/oms/graphql/types/Order/Order.resolvers.js +2 -1
- package/src/modules/oms/pages/admin/orderGrid/Grid.jsx +152 -51
- package/src/modules/oms/pages/admin/orderGrid/index.js +1 -2
- package/src/modules/oms/services/OrderCollection.js +19 -139
- package/src/modules/oms/services/registerDefaultOrderCollectionFilters.js +121 -0
- package/src/modules/promotion/bootstrap.js +16 -0
- package/src/modules/promotion/graphql/types/Coupon/Coupon.admin.resolvers.js +2 -7
- package/src/modules/promotion/pages/admin/couponGrid/Grid.jsx +157 -33
- package/src/modules/promotion/pages/admin/couponGrid/index.js +1 -2
- package/src/modules/promotion/services/CouponCollection.js +21 -130
- package/src/modules/promotion/services/registerDefaultCouponCollectionFilters.js +72 -0
- package/src/modules/stripe/api/stripeWebHook/[bodyJson]webhook.js +4 -2
- package/src/modules/tax/bootstrap.js +17 -0
- package/src/modules/tax/services/TaxClassCollection.js +22 -56
- package/src/modules/tax/services/registerDefaultTaxClassCollectionFilters.js +49 -0
- package/src/components/admin/oms/shippingSetting/Method.jsx +0 -73
- package/src/components/common/grid/headers/Basic.jsx +0 -55
- package/src/lib/log/debuger.js +0 -89
- package/src/modules/customer/pages/frontStore/login/LoginButton.jsx +0 -27
- /package/src/components/admin/{oms → checkout}/shippingSetting/ZoneForm.jsx +0 -0
- /package/src/modules/{oms → checkout}/pages/admin/all/ShippingSettingMenu.jsx +0 -0
- /package/src/modules/{oms → checkout}/pages/admin/shippingSetting/index.js +0 -0
- /package/src/modules/{oms → checkout}/pages/admin/shippingSetting/route.json +0 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
const uniqid = require('uniqid');
|
|
2
|
+
const { value } = require('@evershop/postgres-query-builder');
|
|
3
|
+
const {
|
|
4
|
+
OPERATION_MAP
|
|
5
|
+
} = require('@evershop/evershop/src/lib/util/filterOperationMapp');
|
|
6
|
+
const { getValueSync } = require('@evershop/evershop/src/lib/util/registry');
|
|
7
|
+
|
|
8
|
+
module.exports = async function registerDefaultProductCollectionFilters() {
|
|
9
|
+
// List of default supported filters
|
|
10
|
+
const defaultFilters = [
|
|
11
|
+
{
|
|
12
|
+
key: 'keyword',
|
|
13
|
+
operation: ['eq'],
|
|
14
|
+
callback: (query, operation, value, currentFilters) => {
|
|
15
|
+
const where = query.getWhere();
|
|
16
|
+
const bindingKey = `keyword_${uniqid()}`;
|
|
17
|
+
where.addRaw(
|
|
18
|
+
'AND',
|
|
19
|
+
`to_tsvector('simple', product_description.name || ' ' || product_description.description) @@ websearch_to_tsquery('simple', :${bindingKey})`,
|
|
20
|
+
{
|
|
21
|
+
[bindingKey]: value
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
currentFilters.push({
|
|
25
|
+
key: 'keyword',
|
|
26
|
+
operation,
|
|
27
|
+
value
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: 'min_price',
|
|
33
|
+
operation: ['eq'],
|
|
34
|
+
callback: (query, operation, value, currentFilters) => {
|
|
35
|
+
// Check if the value is a positive number
|
|
36
|
+
if (!Number.isNaN(parseFloat(value)) && parseFloat(value) > 0) {
|
|
37
|
+
query.andWhere('product.price', '>=', parseFloat(value));
|
|
38
|
+
currentFilters.push({
|
|
39
|
+
key: 'min_price',
|
|
40
|
+
operation,
|
|
41
|
+
value
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
key: 'max_price',
|
|
48
|
+
operation: ['eq'],
|
|
49
|
+
callback: (query, operation, value, currentFilters) => {
|
|
50
|
+
if (!Number.isNaN(parseFloat(value)) && parseFloat(value) > 0) {
|
|
51
|
+
query.andWhere('product.price', '<=', parseFloat(value));
|
|
52
|
+
currentFilters.push({
|
|
53
|
+
key: 'max_price',
|
|
54
|
+
operation,
|
|
55
|
+
value
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: 'name',
|
|
62
|
+
operation: ['like'],
|
|
63
|
+
callback: (query, operation, value, currentFilters) => {
|
|
64
|
+
query.andWhere(
|
|
65
|
+
'product_description.name',
|
|
66
|
+
OPERATION_MAP[operation],
|
|
67
|
+
`%${value}%`
|
|
68
|
+
);
|
|
69
|
+
currentFilters.push({
|
|
70
|
+
key: 'name',
|
|
71
|
+
operation,
|
|
72
|
+
value
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: 'qty',
|
|
78
|
+
operation: ['eq', 'gteq', 'lteq'],
|
|
79
|
+
callback: (query, operation, value, currentFilters) => {
|
|
80
|
+
query.andWhere(
|
|
81
|
+
'product_inventory.qty',
|
|
82
|
+
OPERATION_MAP[operation],
|
|
83
|
+
parseFloat(value) || 0
|
|
84
|
+
);
|
|
85
|
+
currentFilters.push({
|
|
86
|
+
key: 'qty',
|
|
87
|
+
operation,
|
|
88
|
+
value
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: 'sku',
|
|
94
|
+
operation: ['like', 'in'],
|
|
95
|
+
callback: (query, operation, value, currentFilters) => {
|
|
96
|
+
query.andWhere(
|
|
97
|
+
'product.sku',
|
|
98
|
+
OPERATION_MAP[operation],
|
|
99
|
+
value.split(',')
|
|
100
|
+
);
|
|
101
|
+
currentFilters.push({
|
|
102
|
+
key: 'sku',
|
|
103
|
+
operation,
|
|
104
|
+
value
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
key: 'status',
|
|
110
|
+
operation: ['eq'],
|
|
111
|
+
callback: (query, operation, value, currentFilters) => {
|
|
112
|
+
query.andWhere('product.status', OPERATION_MAP[operation], value);
|
|
113
|
+
currentFilters.push({
|
|
114
|
+
key: 'status',
|
|
115
|
+
operation,
|
|
116
|
+
value
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
key: 'type',
|
|
122
|
+
operation: ['eq'],
|
|
123
|
+
callback: (query, operation, value, currentFilters) => {
|
|
124
|
+
if (['simple', 'configurable'].includes(value)) {
|
|
125
|
+
switch (value) {
|
|
126
|
+
case 'simple':
|
|
127
|
+
query.andWhere('product.variant_group_id', 'IS NULL', null);
|
|
128
|
+
break;
|
|
129
|
+
case 'configurable':
|
|
130
|
+
query.andWhere('product.variant_group_id', 'IS NOT NULL', null);
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
currentFilters.push({
|
|
136
|
+
key: 'type',
|
|
137
|
+
operation,
|
|
138
|
+
value
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
key: 'cat',
|
|
145
|
+
operation: ['eq', 'in', 'nin'],
|
|
146
|
+
callback: (query, operation, value, currentFilters) => {
|
|
147
|
+
query.andWhere(
|
|
148
|
+
'product.category_id',
|
|
149
|
+
OPERATION_MAP[operation],
|
|
150
|
+
['in', 'nin'].includes(operation) ? value.split(',') : value
|
|
151
|
+
);
|
|
152
|
+
currentFilters.push({
|
|
153
|
+
key: 'cat',
|
|
154
|
+
operation,
|
|
155
|
+
value
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
key: 'ob',
|
|
161
|
+
operation: ['eq'],
|
|
162
|
+
callback: (query, operation, value, currentFilters) => {
|
|
163
|
+
const productSortBy = getValueSync(
|
|
164
|
+
'productCollectionSortBy',
|
|
165
|
+
{
|
|
166
|
+
price: (query) => query.orderBy('product.price'),
|
|
167
|
+
name: (query) => query.orderBy('product_description.name'),
|
|
168
|
+
qty: (query) => query.orderBy('product_inventory.qty'),
|
|
169
|
+
status: (query) => query.orderBy('product.status')
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
isAdmin
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
if (productSortBy[value]) {
|
|
177
|
+
productSortBy[value](query, operation);
|
|
178
|
+
currentFilters.push({
|
|
179
|
+
key: 'ob',
|
|
180
|
+
operation,
|
|
181
|
+
value
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
query.orderBy('product.product_id', 'DESC');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
const { filterableAttributes } = this;
|
|
191
|
+
const { isAdmin } = this;
|
|
192
|
+
// Attribute filters
|
|
193
|
+
filterableAttributes.forEach((attribute) => {
|
|
194
|
+
defaultFilters.push({
|
|
195
|
+
key: attribute.attribute_code,
|
|
196
|
+
operation: ['in'],
|
|
197
|
+
callback: (query, operation, val, currentFilters) => {
|
|
198
|
+
const alias = `attribute_${uniqid()}`;
|
|
199
|
+
// Split the value by comma and only get the positive integer
|
|
200
|
+
const values = val
|
|
201
|
+
.split(',')
|
|
202
|
+
.map((v) => parseInt(v, 10))
|
|
203
|
+
.filter((v) => v > 0);
|
|
204
|
+
query
|
|
205
|
+
.innerJoin('product_attribute_value_index', alias)
|
|
206
|
+
.on(`${alias}.product_id`, '=', 'product.product_id')
|
|
207
|
+
.and(`${alias}.attribute_id`, '=', value(attribute.attribute_id))
|
|
208
|
+
.and(`${alias}.option_id`, 'IN', value(values));
|
|
209
|
+
currentFilters.push({
|
|
210
|
+
key: attribute.attribute_code,
|
|
211
|
+
operation,
|
|
212
|
+
value: val
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
return defaultFilters;
|
|
219
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { error } = require('@evershop/evershop/src/lib/log/
|
|
1
|
+
const { error } = require('@evershop/evershop/src/lib/log/logger');
|
|
2
2
|
const { pool } = require('@evershop/evershop/src/lib/postgres/connection');
|
|
3
3
|
const { execute, select } = require('@evershop/postgres-query-builder');
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { error } = require('@evershop/evershop/src/lib/log/
|
|
1
|
+
const { error } = require('@evershop/evershop/src/lib/log/logger');
|
|
2
2
|
const { pool } = require('@evershop/evershop/src/lib/postgres/connection');
|
|
3
3
|
const { select, insertOnUpdate } = require('@evershop/postgres-query-builder');
|
|
4
4
|
|
|
@@ -7,6 +7,6 @@ module.exports = async function buildUrlReWrite(data) {
|
|
|
7
7
|
// Delete the url rewrite for the product
|
|
8
8
|
await execute(
|
|
9
9
|
pool,
|
|
10
|
-
`DELETE FROM url_rewrite WHERE entity_uuid = ${productUuid} AND entity_type = 'product'`
|
|
10
|
+
`DELETE FROM url_rewrite WHERE entity_uuid = '${productUuid}' AND entity_type = 'product'`
|
|
11
11
|
);
|
|
12
12
|
};
|
package/src/modules/catalog/subscribers/product_image_added/localGenerateProductImageVariant.js
CHANGED
|
@@ -5,7 +5,7 @@ const sharp = require('sharp');
|
|
|
5
5
|
const { update } = require('@evershop/postgres-query-builder');
|
|
6
6
|
const { pool } = require('@evershop/evershop/src/lib/postgres/connection');
|
|
7
7
|
const { CONSTANTS } = require('@evershop/evershop/src/lib/helpers');
|
|
8
|
-
const {
|
|
8
|
+
const { error } = require('@evershop/evershop/src/lib/log/logger');
|
|
9
9
|
|
|
10
10
|
module.exports = async function localGenerateProductImageVariant(data) {
|
|
11
11
|
if (getConfig('system.file_storage') === 'local') {
|
|
@@ -55,8 +55,8 @@ module.exports = async function localGenerateProductImageVariant(data) {
|
|
|
55
55
|
.where('product_image_product_id', '=', data.product_image_product_id)
|
|
56
56
|
.and('origin_image', '=', data.origin_image)
|
|
57
57
|
.execute(pool);
|
|
58
|
-
} catch (
|
|
59
|
-
|
|
58
|
+
} catch (e) {
|
|
59
|
+
error(e);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
};
|
|
@@ -4,6 +4,10 @@ const {
|
|
|
4
4
|
INTERNAL_SERVER_ERROR,
|
|
5
5
|
INVALID_PAYLOAD
|
|
6
6
|
} = require('@evershop/evershop/src/lib/util/httpStatus');
|
|
7
|
+
const { error } = require('@evershop/evershop/src/lib/log/logger');
|
|
8
|
+
const {
|
|
9
|
+
translate
|
|
10
|
+
} = require('@evershop/evershop/src/lib/locale/translate/translate');
|
|
7
11
|
const { getCartByUUID } = require('../../services/getCartByUUID');
|
|
8
12
|
const { saveCart } = require('../../services/saveCart');
|
|
9
13
|
|
|
@@ -37,10 +41,11 @@ module.exports = async (request, response, delegate, next) => {
|
|
|
37
41
|
next();
|
|
38
42
|
}
|
|
39
43
|
} catch (e) {
|
|
44
|
+
error(e);
|
|
40
45
|
response.status(INTERNAL_SERVER_ERROR);
|
|
41
46
|
response.json({
|
|
42
47
|
error: {
|
|
43
|
-
message:
|
|
48
|
+
message: translate('Failed to set shipping method'),
|
|
44
49
|
status: INTERNAL_SERVER_ERROR
|
|
45
50
|
}
|
|
46
51
|
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const {
|
|
2
|
+
INVALID_PAYLOAD,
|
|
3
|
+
INTERNAL_SERVER_ERROR,
|
|
4
|
+
OK
|
|
5
|
+
} = require('@evershop/evershop/src/lib/util/httpStatus');
|
|
6
|
+
const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');
|
|
7
|
+
const { error } = require('@evershop/evershop/src/lib/log/logger');
|
|
8
|
+
const {
|
|
9
|
+
translate
|
|
10
|
+
} = require('@evershop/evershop/src/lib/locale/translate/translate');
|
|
11
|
+
const { setContextValue } = require('../../../graphql/services/contextHelper');
|
|
12
|
+
const { saveCart } = require('../../services/saveCart');
|
|
13
|
+
const { Cart } = require('../../services/cart/Cart');
|
|
14
|
+
|
|
15
|
+
module.exports = async (request, response, delegate, next) => {
|
|
16
|
+
try {
|
|
17
|
+
const { items, customer_full_name, customer_email } = request.body;
|
|
18
|
+
const cartData = {
|
|
19
|
+
currency: getConfig('shop.currency', 'USD')
|
|
20
|
+
};
|
|
21
|
+
if (customer_full_name) {
|
|
22
|
+
cartData.customer_full_name = customer_full_name;
|
|
23
|
+
}
|
|
24
|
+
if (customer_email) {
|
|
25
|
+
cartData.customer_email = customer_email;
|
|
26
|
+
}
|
|
27
|
+
const cart = new Cart(cartData);
|
|
28
|
+
// Check if items is not an empty array
|
|
29
|
+
if (items.length === 0) {
|
|
30
|
+
response.status(INVALID_PAYLOAD);
|
|
31
|
+
response.json({
|
|
32
|
+
error: {
|
|
33
|
+
status: INVALID_PAYLOAD,
|
|
34
|
+
message: translate('Requires at least one item to create a cart')
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Maximum 100 items per cart
|
|
40
|
+
if (items.length > 100) {
|
|
41
|
+
response.status(INVALID_PAYLOAD);
|
|
42
|
+
response.json({
|
|
43
|
+
error: {
|
|
44
|
+
status: INVALID_PAYLOAD,
|
|
45
|
+
message: translate('Too many items requested')
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Loop through the items and group by sku
|
|
52
|
+
const groupedItems = items.reduce(
|
|
53
|
+
(acc, item) => {
|
|
54
|
+
if (acc.find((i) => i.sku === item.sku)) {
|
|
55
|
+
acc.find((i) => i.sku === item.sku).qty += item.qty;
|
|
56
|
+
} else {
|
|
57
|
+
acc.push(item);
|
|
58
|
+
}
|
|
59
|
+
return acc;
|
|
60
|
+
},
|
|
61
|
+
[{ sku: items[0].sku, qty: 0 }]
|
|
62
|
+
);
|
|
63
|
+
// Loop through the grouped items and add them to the cart
|
|
64
|
+
const cartItems = await Promise.all(
|
|
65
|
+
groupedItems.map(async (item) => {
|
|
66
|
+
const cartItem = await cart.addItem(item.sku, item.qty);
|
|
67
|
+
return cartItem;
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
await saveCart(cart);
|
|
71
|
+
// Set the new cart id to the context, so next middleware can use it
|
|
72
|
+
setContextValue(request, 'cartId', cart.getData('uuid'));
|
|
73
|
+
response.status(OK);
|
|
74
|
+
response.$body = {
|
|
75
|
+
data: {
|
|
76
|
+
items: cartItems.map((item) => item.export()),
|
|
77
|
+
count: cart.getItems().length,
|
|
78
|
+
cartId: cart.getData('uuid')
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
next();
|
|
82
|
+
} catch (e) {
|
|
83
|
+
error(e);
|
|
84
|
+
response.status(INTERNAL_SERVER_ERROR);
|
|
85
|
+
response.json({
|
|
86
|
+
error: {
|
|
87
|
+
status: INTERNAL_SERVER_ERROR,
|
|
88
|
+
message: e.message
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"properties": {
|
|
4
|
+
"customer_full_name": {
|
|
5
|
+
"type": "string"
|
|
6
|
+
},
|
|
7
|
+
"customer_email": {
|
|
8
|
+
"type": ["string"],
|
|
9
|
+
"format": "email",
|
|
10
|
+
"errorMessage": {
|
|
11
|
+
"type": "Email is invalid"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"items": {
|
|
15
|
+
"type": "array",
|
|
16
|
+
"items": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"properties": {
|
|
19
|
+
"sku": {
|
|
20
|
+
"type": "string"
|
|
21
|
+
},
|
|
22
|
+
"qty": {
|
|
23
|
+
"type": "integer"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": ["sku", "qty"],
|
|
27
|
+
"additionalProperties": true,
|
|
28
|
+
"errorMessage": {
|
|
29
|
+
"properties": {
|
|
30
|
+
"sku": "Sku is required",
|
|
31
|
+
"qty": "Qty is invalid"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"required": ["items"],
|
|
38
|
+
"errorMessage": {
|
|
39
|
+
"required": {
|
|
40
|
+
"items": "Must provide at least one item"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"additionalProperties": true
|
|
44
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
const {
|
|
3
|
+
rollback,
|
|
4
|
+
commit,
|
|
5
|
+
startTransaction,
|
|
6
|
+
del,
|
|
7
|
+
select
|
|
8
|
+
} = require('@evershop/postgres-query-builder');
|
|
9
|
+
const {
|
|
10
|
+
getConnection
|
|
11
|
+
} = require('@evershop/evershop/src/lib/postgres/connection');
|
|
12
|
+
const {
|
|
13
|
+
OK,
|
|
14
|
+
INTERNAL_SERVER_ERROR,
|
|
15
|
+
INVALID_PAYLOAD
|
|
16
|
+
} = require('@evershop/evershop/src/lib/util/httpStatus');
|
|
17
|
+
const { error } = require('@evershop/evershop/src/lib/log/logger');
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line no-unused-vars
|
|
20
|
+
module.exports = async (request, response, deledate, next) => {
|
|
21
|
+
const { id } = request.params;
|
|
22
|
+
const connection = await getConnection();
|
|
23
|
+
await startTransaction(connection);
|
|
24
|
+
try {
|
|
25
|
+
// Load the shipping zone
|
|
26
|
+
const shippingZone = await select()
|
|
27
|
+
.from('shipping_zone')
|
|
28
|
+
.where('uuid', '=', id)
|
|
29
|
+
.load(connection);
|
|
30
|
+
|
|
31
|
+
if (!shippingZone) {
|
|
32
|
+
response.status(INVALID_PAYLOAD);
|
|
33
|
+
response.json({
|
|
34
|
+
error: {
|
|
35
|
+
status: INVALID_PAYLOAD,
|
|
36
|
+
message: 'Invalid zone id'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
await del('shipping_zone').where('uuid', '=', id).execute(connection);
|
|
42
|
+
await commit(connection);
|
|
43
|
+
response.status(OK);
|
|
44
|
+
response.json({
|
|
45
|
+
data: shippingZone
|
|
46
|
+
});
|
|
47
|
+
} catch (e) {
|
|
48
|
+
error(e);
|
|
49
|
+
await rollback(connection);
|
|
50
|
+
response.status(INTERNAL_SERVER_ERROR);
|
|
51
|
+
response.json({
|
|
52
|
+
error: {
|
|
53
|
+
status: INTERNAL_SERVER_ERROR,
|
|
54
|
+
message: e.message
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
const {
|
|
3
|
+
rollback,
|
|
4
|
+
commit,
|
|
5
|
+
startTransaction,
|
|
6
|
+
select,
|
|
7
|
+
del
|
|
8
|
+
} = require('@evershop/postgres-query-builder');
|
|
9
|
+
const {
|
|
10
|
+
getConnection
|
|
11
|
+
} = require('@evershop/evershop/src/lib/postgres/connection');
|
|
12
|
+
const {
|
|
13
|
+
OK,
|
|
14
|
+
INTERNAL_SERVER_ERROR,
|
|
15
|
+
INVALID_PAYLOAD
|
|
16
|
+
} = require('@evershop/evershop/src/lib/util/httpStatus');
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line no-unused-vars
|
|
19
|
+
module.exports = async (request, response, deledate, next) => {
|
|
20
|
+
const { method_id, zone_id } = request.params;
|
|
21
|
+
const connection = await getConnection();
|
|
22
|
+
await startTransaction(connection);
|
|
23
|
+
try {
|
|
24
|
+
// Load the shipping zone
|
|
25
|
+
const shippingZone = await select()
|
|
26
|
+
.from('shipping_zone')
|
|
27
|
+
.where('uuid', '=', zone_id)
|
|
28
|
+
.load(connection, false);
|
|
29
|
+
|
|
30
|
+
if (!shippingZone) {
|
|
31
|
+
response.status(INVALID_PAYLOAD);
|
|
32
|
+
response.json({
|
|
33
|
+
error: {
|
|
34
|
+
status: INVALID_PAYLOAD,
|
|
35
|
+
message: 'Invalid zone id'
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const zoneMethodQuery = select().from('shipping_method');
|
|
42
|
+
zoneMethodQuery
|
|
43
|
+
.innerJoin('shipping_zone_method')
|
|
44
|
+
.on(
|
|
45
|
+
'shipping_method.shipping_method_id',
|
|
46
|
+
'=',
|
|
47
|
+
'shipping_zone_method.method_id'
|
|
48
|
+
);
|
|
49
|
+
zoneMethodQuery
|
|
50
|
+
.where('shipping_zone_method.zone_id', '=', shippingZone.shipping_zone_id)
|
|
51
|
+
.and('shipping_method.uuid', '=', method_id);
|
|
52
|
+
|
|
53
|
+
const zoneMethod = await zoneMethodQuery.load(connection, false);
|
|
54
|
+
if (!zoneMethod) {
|
|
55
|
+
response.status(INVALID_PAYLOAD);
|
|
56
|
+
response.json({
|
|
57
|
+
error: {
|
|
58
|
+
status: INVALID_PAYLOAD,
|
|
59
|
+
message: 'Invalid method id'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Delete the shipping zone method
|
|
66
|
+
await del('shipping_zone_method')
|
|
67
|
+
.where('method_id', '=', zoneMethod.shipping_method_id)
|
|
68
|
+
.and('zone_id', '=', shippingZone.shipping_zone_id)
|
|
69
|
+
.execute(connection);
|
|
70
|
+
await commit(connection);
|
|
71
|
+
response.status(OK);
|
|
72
|
+
response.json({
|
|
73
|
+
data: zoneMethod
|
|
74
|
+
});
|
|
75
|
+
} catch (e) {
|
|
76
|
+
await rollback(connection);
|
|
77
|
+
response.status(INTERNAL_SERVER_ERROR);
|
|
78
|
+
response.json({
|
|
79
|
+
error: {
|
|
80
|
+
status: INTERNAL_SERVER_ERROR,
|
|
81
|
+
message: e.message
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
@@ -131,6 +131,43 @@ module.exports = async (request, response, delegate, next) => {
|
|
|
131
131
|
...method,
|
|
132
132
|
cost: toPrice(jsonResponse.data.data.cost, true)
|
|
133
133
|
};
|
|
134
|
+
} else if (method.weight_based_cost) {
|
|
135
|
+
const totalWeight = cart.total_weight;
|
|
136
|
+
const weightBasedCost = method.weight_based_cost
|
|
137
|
+
.map(({ min_weight, cost }) => ({
|
|
138
|
+
min_weight: parseFloat(min_weight),
|
|
139
|
+
cost: toPrice(cost)
|
|
140
|
+
}))
|
|
141
|
+
.sort((a, b) => a.min_weight - b.min_weight);
|
|
142
|
+
|
|
143
|
+
let cost = 0;
|
|
144
|
+
for (let i = 0; i < weightBasedCost.length; i += 1) {
|
|
145
|
+
if (totalWeight >= weightBasedCost[i].min_weight) {
|
|
146
|
+
cost = weightBasedCost[i].cost;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
...method,
|
|
151
|
+
cost: toPrice(cost, true)
|
|
152
|
+
};
|
|
153
|
+
} else if (method.price_based_cost) {
|
|
154
|
+
const subTotal = toPrice(cart.sub_total);
|
|
155
|
+
const priceBasedCost = method.price_based_cost
|
|
156
|
+
.map(({ min_price, cost }) => ({
|
|
157
|
+
min_price: toPrice(min_price),
|
|
158
|
+
cost: toPrice(cost)
|
|
159
|
+
}))
|
|
160
|
+
.sort((a, b) => a.min_price - b.min_price);
|
|
161
|
+
let cost = 0;
|
|
162
|
+
for (let i = 0; i < priceBasedCost.length; i += 1) {
|
|
163
|
+
if (subTotal >= priceBasedCost[i].min_price) {
|
|
164
|
+
cost = priceBasedCost[i].cost;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
...method,
|
|
169
|
+
cost: toPrice(cost, true)
|
|
170
|
+
};
|
|
134
171
|
} else {
|
|
135
172
|
return {
|
|
136
173
|
...method,
|