D
D
darksladen2017-08-04 12:04:17
PHP
darksladen, 2017-08-04 12:04:17

How to make a price change when selecting product properties?

Hello! I'm making an online store and the problem arose to dynamically change the prices of goods. , black ink, 2 - green, blue ink, 3 - white, black ink. I decided to pass all the data needed for this processing:
array:2 [▼
0 => array:3 [▼
"id" => 1
"price" => 15
"options" => array:2 [▼
" color" => "Red"
"capacity" => "30ml"
"id" => 2
"price" => 18
"options" => array:2 [▼
"color" => "Red"
"capacity" => "50ml"
]
]
]
But I don't understand how to process them so that get what I need ((( That is, I need to correctly generate selects .. When choosing a combination, its id will be recorded in a hidden field, which I then need to send to the server .. Please help, I already broke my head!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-08-04
@webinar

You can add a data attribute to each option in the first select, for example:

<select>
<option value="0" data-color="красная, синяя">Черные</option>
<option value="1" data-color="красная, белая">Красные</option>
</select>

At the selection event, form an option for the second select, based on the data-color of the selected option, you can also put some data-dop-price there to increase the base cost by data-dop-price.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question