K
K
KamilFo2014-03-24 00:53:51
PHP
KamilFo, 2014-03-24 00:53:51

OpenCart - how to transfer prices from the product card when adding to cart?

Hello!
Please help with the following issue.
The task is to display several price options on the product card depending on the number of items in the order. Several quantity options were displayed with different quantities. Using Jquery, depending on the option, the price on the product card changes.
Now a question. Naturally, by default, a product is added with the price that is in the admin panel. How, when clicking on the "Add to Cart" button, to transfer the price value selected by the user?
I started digging into the code, and it turned out that the "button-cart" element calls the add() function in checkout/cart.php, but I didn't understand where to intercept the price value in this particular order.
Please, prompt in what direction to dig.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2014-03-24
@KamilFo

checkout/cart.php is the controller that takes the input from the form. Next, there is a request to the library/cart.php library, from there the information is written to the session.
Accordingly, if you have several prices that depend on the quantity of goods, then you either need to store all prices in the database, or have an algorithm that will allow you to determine the price, depending on the specific quantity of goods (1 product - 100% of the price, more than 5 products - 90% of the price, etc.). In this case, it is enough to receive the quantity of goods on the client and on the server and determine the price using the developed algorithm (we calculate the desired price from 100% of the price indicated in the admin panel).
Accordingly, the quantity of goods in the form of the variable $quantity is transferred to the controller, and the price of the goods (or several) is drawn from the database through the product model, which is loaded in the controller.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question