@reactionary/provider-medusa 0.3.15 → 0.3.17
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/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-medusa",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@medusajs/js-sdk": "^2.13.0",
|
|
9
|
-
"@reactionary/core": "0.3.
|
|
9
|
+
"@reactionary/core": "0.3.17",
|
|
10
10
|
"debug": "^4.4.3",
|
|
11
11
|
"@medusajs/types": "^2.11.0",
|
|
12
12
|
"zod": "4.1.9"
|
|
@@ -26,14 +26,14 @@ class MedusaPriceProvider extends PriceProvider {
|
|
|
26
26
|
this.config = config;
|
|
27
27
|
}
|
|
28
28
|
async getListPrice(payload) {
|
|
29
|
-
const result = await this.getBySKU(payload);
|
|
29
|
+
const result = await this.getBySKU(payload, "list");
|
|
30
30
|
return success(result);
|
|
31
31
|
}
|
|
32
32
|
async getCustomerPrice(payload) {
|
|
33
|
-
const result = await this.getBySKU(payload);
|
|
33
|
+
const result = await this.getBySKU(payload, "customer");
|
|
34
34
|
return success(result);
|
|
35
35
|
}
|
|
36
|
-
async getBySKU(payload) {
|
|
36
|
+
async getBySKU(payload, mode) {
|
|
37
37
|
const sku = payload.variant.sku;
|
|
38
38
|
if (debug.enabled) {
|
|
39
39
|
debug(`Fetching price for SKU: ${sku}`);
|
|
@@ -54,7 +54,7 @@ class MedusaPriceProvider extends PriceProvider {
|
|
|
54
54
|
}
|
|
55
55
|
return this.createEmptyPriceResult(sku);
|
|
56
56
|
}
|
|
57
|
-
return this.parseSingle(variant);
|
|
57
|
+
return this.parseSingle(variant, mode);
|
|
58
58
|
} catch (error) {
|
|
59
59
|
if (debug.enabled) {
|
|
60
60
|
debug(
|
|
@@ -64,7 +64,7 @@ class MedusaPriceProvider extends PriceProvider {
|
|
|
64
64
|
return this.createEmptyPriceResult(sku);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
parseSingle(variant) {
|
|
67
|
+
parseSingle(variant, mode) {
|
|
68
68
|
const identifier = {
|
|
69
69
|
variant: {
|
|
70
70
|
sku: variant.sku || ""
|
|
@@ -72,9 +72,14 @@ class MedusaPriceProvider extends PriceProvider {
|
|
|
72
72
|
};
|
|
73
73
|
const calculatedPrice = variant.calculated_price;
|
|
74
74
|
let unitPrice;
|
|
75
|
+
let isOnSale = false;
|
|
75
76
|
if (calculatedPrice) {
|
|
77
|
+
const priceToUse = mode === "customer" ? calculatedPrice.calculated_amount : calculatedPrice.original_amount;
|
|
78
|
+
if (mode === "customer") {
|
|
79
|
+
isOnSale = calculatedPrice.calculated_price?.price_list_type === "sale";
|
|
80
|
+
}
|
|
76
81
|
unitPrice = {
|
|
77
|
-
value:
|
|
82
|
+
value: priceToUse || 0,
|
|
78
83
|
currency: calculatedPrice.currency_code?.toUpperCase() || this.context.languageContext.currencyCode
|
|
79
84
|
};
|
|
80
85
|
} else {
|
|
@@ -86,7 +91,8 @@ class MedusaPriceProvider extends PriceProvider {
|
|
|
86
91
|
const result = {
|
|
87
92
|
identifier,
|
|
88
93
|
tieredPrices: [],
|
|
89
|
-
unitPrice
|
|
94
|
+
unitPrice,
|
|
95
|
+
onSale: isOnSale
|
|
90
96
|
};
|
|
91
97
|
return result;
|
|
92
98
|
}
|
|
@@ -8,7 +8,7 @@ export declare class MedusaPriceProvider extends PriceProvider {
|
|
|
8
8
|
constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI);
|
|
9
9
|
getListPrice(payload: ListPriceQuery): Promise<Result<Price>>;
|
|
10
10
|
getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<Price>>;
|
|
11
|
-
protected getBySKU(payload: ListPriceQuery | CustomerPriceQuery): Promise<Price>;
|
|
12
|
-
protected parseSingle(variant: StoreProductVariant): Price;
|
|
11
|
+
protected getBySKU(payload: ListPriceQuery | CustomerPriceQuery, mode: 'list' | 'customer'): Promise<Price>;
|
|
12
|
+
protected parseSingle(variant: StoreProductVariant, mode: 'list' | 'customer'): Price;
|
|
13
13
|
protected getResourceName(): string;
|
|
14
14
|
}
|