Skip to content

Commit 5553d36

Browse files
author
Artem
committed
Sanitize the out of stock error for checkout as well
1 parent b3942cd commit 5553d36

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

demo/peacock/src/components/cart/cart.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ class Cart extends Component {
160160
return acc;
161161
}, []);
162162

163-
return `Products ${products.join(', ')} are out of stock. Please remove them to complete the checkout.`;
163+
return (
164+
<span>
165+
Products <strong>{products.join(', ')}</strong> are out of stock. Please remove them to complete the checkout.
166+
</span>
167+
);
164168
}
165169

166170
return sanitizeAll(err);

demo/peacock/src/pages/checkout/checkout.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
.place-order-button {
8282
border-radius: 0;
8383
}
84+
85+
.error-alerts {
86+
margin-left: 15px;
87+
}
8488
}
8589

8690
@media (--large) {

demo/peacock/src/pages/checkout/checkout.jsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,26 @@ class Checkout extends Component {
118118

119119
@autobind
120120
sanitizeError(error) {
121-
if (error && error.startsWith('Not enough onHand units')) {
122-
return 'Unable to checkout — item is out of stock';
121+
if (/Following SKUs are out/.test(error)) {
122+
const skus = error.split('.')[0].split(':')[1].split(',');
123+
124+
const products = _.reduce(skus, (acc, outOfStock) => {
125+
const sku = _.find(this.props.cart.skus, { sku: outOfStock.trim() });
126+
if (sku) {
127+
return [
128+
...acc,
129+
sku.name,
130+
];
131+
}
132+
133+
return acc;
134+
}, []);
135+
136+
return (
137+
<span>
138+
Products <strong>{products.join(', ')}</strong> are out of stock. Please remove them to complete the checkout.
139+
</span>
140+
);
123141
} else if (/is blacklisted/.test(error)) {
124142
return 'Your account has been blocked from making purchases on this site';
125143
}
@@ -293,6 +311,7 @@ class Checkout extends Component {
293311
<ErrorAlerts
294312
sanitizeError={this.sanitizeError}
295313
error={props.checkoutState.err}
314+
styleName="error-alerts"
296315
/>
297316
{this.content}
298317
</div>

0 commit comments

Comments
 (0)