Skip to content

Commit 785c876

Browse files
committed
Fix "Avoid assignments in operands"
1 parent 885842b commit 785c876

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

utils/functions/functions.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,36 @@ export const getFormattedCart = (data) => {
6060

6161
let i = 0;
6262
givenProducts.forEach(() => {
63-
const givenProduct = givenProducts[parseInt(i,10)].product;
63+
const givenProduct = givenProducts[parseInt(i, 10)].product;
6464
const product = {};
6565
// Convert price to a float value
66-
const convertedCurrency = givenProducts[parseInt(i,10)].total.replace(/[^0-9.-]+/g, '');
66+
const convertedCurrency = givenProducts[parseInt(i, 10)].total.replace(
67+
/[^0-9.-]+/g,
68+
''
69+
);
6770

6871
product.productId = givenProduct.productId;
69-
product.cartKey = givenProducts[parseInt(i,10)].key;
72+
product.cartKey = givenProducts[parseInt(i, 10)].key;
7073
product.name = givenProduct.name;
71-
product.qty = givenProducts[parseInt(i,10)].quantity;
74+
product.qty = givenProducts[parseInt(i, 10)].quantity;
7275
product.price = convertedCurrency / product.qty;
73-
product.totalPrice = givenProducts[parseInt(i,10)].total;
76+
product.totalPrice = givenProducts[parseInt(i, 10)].total;
7477
// Ensure we can add products without images to the cart
75-
givenProduct.image
76-
? (product.image = {
77-
sourceUrl: givenProduct.image.sourceUrl,
78-
srcSet: givenProduct.image.srcSet,
79-
title: givenProduct.image.title,
80-
})
81-
: (product.image = {
82-
sourceUrl: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
83-
srcSet: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
84-
title: givenProduct.name,
85-
});
86-
87-
totalProductsCount += givenProducts[parseInt(i,10)].quantity;
78+
if (givenProduct.image) {
79+
product.image = {
80+
sourceUrl: givenProduct.image.sourceUrl,
81+
srcSet: givenProduct.image.srcSet,
82+
title: givenProduct.image.title,
83+
};
84+
} else {
85+
product.image = {
86+
sourceUrl: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
87+
srcSet: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
88+
title: givenProduct.name,
89+
};
90+
}
91+
92+
totalProductsCount += givenProducts[parseInt(i, 10)].quantity;
8893
// Push each item into the products array.
8994
formattedCart.products.push(product);
9095
i++;

0 commit comments

Comments
 (0)