M
M
Merry Cay2021-09-23 11:37:44
JavaScript
Merry Cay, 2021-09-23 11:37:44

Changing the price of an item depending on the TOTAL quantity of the item in the cart?

Good day everyone. Situation:

In the online store, in the product catalog, the items have a price depending on the quantity: from 3 pcs, from 7 pcs, from 11 pcs. Now the price is
calculated for a specific product, that is, if I put 15 pieces of Dresses 1 and 4 pieces of Dresses 2 in the basket, then the price is calculated as follows: the price of Dresses 1 from 11 pieces * 15 + the price of Dresses 2 * 4

their prices depend on the quantity of a particular item in the basket.

The code that is now left in the comments

The client wished that, at the already set prices of specific products, the final price in the basket was calculated based on the TOTAL number of products added.

That is, even if there are 5 specific goods, but the total quantity is 12, then the price for both goods is taken from 11:
Dress 1 5 pcs + Dress 2 7 pcs = price of dress 1 from 11 pcs *5 + price of dress 2 for 11 pcs * 7

Tell me, is it possible to implement this at all, and if so, how? Maybe you can make changes to the existing code? I'm not strong in JS, please help.

Site made on Tilda

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-09-23
@sergiks

everything remains the same,
only the quantity is taken not from the position of the next Product, but from the total in the Basket.
Change one line in the code that I have not seen yet)
ps I saw this sheet from hell. Nunaf, to understand such pasta :) - freelance.
You will have to rewrite more than one line, because now changing the price of one product affects the recalculation of all products in the cart.
Now we have added a product / changed the number of products - its price has been recalculated, the cart totals have been updated.
It will be necessary differently: added-changed the product; recalculated the total number of goods in the basket, received the prices at which to count each product; the cost of each item of each product; summed up the total.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question