forked from forcedotcom/commerce-on-lightning-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproductPricing.js
More file actions
214 lines (191 loc) · 5.35 KB
/
productPricing.js
File metadata and controls
214 lines (191 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* For full license text, see the LICENSE file in the repo
* root or https://opensource.org/licenses/apache-2-0/
*/
import { LightningElement, api } from 'lwc';
import { Labels } from './labels';
import displayOriginalPriceEvaluator from './productPricingUtils';
export default class ProductPricing extends LightningElement {
static renderMode = 'light';
/**
* The desired layout of price text.
* horizontal will display on single line, with original/list price first (if visible)
* vertical will display on 2 lines, with original/list price last (if visible)
* @type {?('horizontal' | 'vertical')}
*/
@api
layout;
/**
* The localized negotiated price label for the item.
* @type {?string}
*/
@api
negotiatedPriceLabel;
/**
* The localized original price label for the item.
* @type {?string}
*/
@api
originalPriceLabel;
/**
* The localized label to display when no pricing is available
* @type {?string}
*/
@api
unavailablePriceLabel;
/**
* The localized negotiated price of the item.
* @type {?string}
*/
@api
negotiatedPrice;
/**
* The localized original price of the item.
* @type {?string}
*/
@api
originalPrice;
/**
* The ISO 4217 currency code for the product detail page
* @type {?string}
*/
@api
currencyCode;
/**
* Whether to display the negotiated price
* @type {boolean}
*/
@api
showNegotiatedPrice = false;
/**
* Whether to display the original price
* @type {boolean}
*/
@api
showOriginalPrice = false;
/**
* Whether to display the tax included text
* @type {boolean}
*/
@api
showTaxIndication = false;
/**
* The Tax Included label text.
* @type {?string}
*/
@api
taxIncludedLabel;
/**
* Tax locale type for the product.
* Possible values are "Gross" and "Net"
* @type {?('Gross' | 'Net')}
*/
@api
taxLocaleType;
/**
* Tax rate for the product.
* When a given product is exempt, taxRate will be 0
* @type {?number}
*/
@api
taxRate;
/**
* Assistive text, required because screen-readers do not read out strikethrough styling
* @type {string}
* @private
* @readonly
*/
get strikethroughAssistiveText() {
return Labels.strikethroughAssistiveText;
}
/**
* Gets whether Tax Information can be shown. Will only be true
* when taxLocaleType is "Gross", showTaxIndication is configured to be shown and
* taxRate is not 0 or when taxRate is undefined (this scenario occurs when CommerceTax perm is not enabled)
* @type {boolean}
* @readonly
* @private
*/
get taxInfoVisible() {
return this.showTaxIndication && this.isPriceAvailable && this.taxLocaleType === 'Gross' && this.taxRate !== 0;
}
/**
* Whether to display the original price
* @returns {boolean} true if the original (list) price should be displayed, otherwise false
* @readonly
* @private
*/
get displayOriginalPrice() {
return displayOriginalPriceEvaluator(
this.showNegotiatedPrice,
this.showOriginalPrice,
this.negotiatedPrice,
this.originalPrice
);
}
/**
* Whether to display the negotiated price
* @returns {boolean}
* true if negotiated price is available and option to display it is also true
* @readonly
* @private
*/
get displayNegotiatedPrice() {
return this.showNegotiatedPrice && !!this.negotiatedPrice;
}
/**
* Whether to display the assistive text for strike-through text
* @returns {boolean}
* true if both negotiated and original prices are displayed
* @private
* @readonly
*/
get displayAssistiveText() {
return this.displayNegotiatedPrice && this.displayOriginalPrice;
}
/**
* Whether the pricing information is available
* @returns {boolean}
* true if negotiated price exists and needs to be shown, otherwise false
* @private
* @readonly
*/
get isPriceAvailable() {
return this.showNegotiatedPrice && !!this.negotiatedPrice;
}
/**
* Whether there is a negotiated price label to display.
* @returns {boolean}
* true if a negotiated price label has been supplied, otherwise false
* @private
* @readonly
*/
get hasNegotiatedPriceLabel() {
return !!this.negotiatedPriceLabel;
}
/**
* Whether there is an original price label to display.
* @returns {boolean}
* true if an original (list) price label has been supplied, otherwise false
* @private
* @readonly
*/
get hasOriginalPriceLabel() {
return !!this.originalPriceLabel;
}
/**
* Gets classes based on horizontal or vertical layout.
* Note: for horizontal it reverses display so that originalPrice is first.
* @type {string}
* @private
* @readonly
*/
get layoutClass() {
return `slds-grid price-container ${
this.layout === 'horizontal' ? 'slds-grid_reverse slds-grid_align-end' : 'slds-grid_vertical'
}`;
}
}