Answer the question
In order to leave comments, you need to log in
Cart, delivery method and price, post method, transfer to the database when ordering, how to transfer the delivery price?
Hello. (lack of knowledge).
There is a basket, it has a choice of delivery, delivery options have a price.
From the basket, I transfer the choice of delivery, but I can’t transfer the price of delivery yet.
Conclusion of delivery methods and selection.
<h2>Выберите способ доставки</h2>
<ul class="ac-custom ac-radio crzsm">
<?php foreach (ORM::factory('Delivery')->find_all() as $del) : ?>
<li><input type="radio" name="delivery" id="radio<?= $del->id ?>" value="<?= $del->name ?>"><label for="radio<?= $del->id ?>"><?= $del->name ?>
<? if ($del->cost > 0) : ?>
- <b><?= $del->cost ?> </b> руб
<?php endif ?></label></li>
<?php endforeach ?>
</ul>
$delivery = Arr::get($_POST, 'delivery');
подключаюсь к таблице и прикрепляюсь к выбранному варианту доставки $delivery, чтоб с этого варианта вытянуть цену
$del = ORM::factory('Delivery', $delivery);
Вывожу цену
$del['cost'];
$order->set('deliveryСost', $del['cost']);
Answer the question
In order to leave comments, you need to log in
How I solved the problem.
<ul class="ac-custom ac-radio crzsm">
<input type="hidden" id="deliveryCost" name="deliveryCost" value="">
<?php foreach (ORM::factory('Delivery')->find_all() as $del) : ?>
<li><input type="radio" name="delivery" id="radio<?= $del->id ?>" data-price="<?= $del->cost ?>" value="<?= $del->name ?>"><label for="radio<?= $del->id ?>"><?= $del->name ?>
<?php if ($del->cost): ?>
- <b><?= $del->cost ?></b> руб
<?php endif ?></label>
</li>
<?php endforeach ?>
</ul>
<script>
const $deliveryCost = data => document.querySelector('#deliveryCost').value = data;
let $selectors = document.querySelectorAll('.crzsm input[type="radio"]');
$selectors.forEach($radio => {
$radio.addEventListener('change', function() {
$deliveryCost(this.getAttribute('data-price'));
});
});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question