Forked from Sadykh/[miniShop2] Free shipment in delivery
Created
November 19, 2019 13:54
-
-
Save tatamos/b76abce284ba25aed1e877ad11cd4fe4 to your computer and use it in GitHub Desktop.
[miniShop2] Free shipment in delivery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Решение для магазина miniShop2. Проверялось на версии ms2 2.1.8-pl3, MODX Revo 2.3.1-pl. | |
| Простой способ делать зависимость цены доставки от общей суммы заказа. | |
| 1. Создаем файл (myDeliveryHandler.class.php) в каталоге /core/components/minishop2/custom/delivery/ | |
| 2. Получается файл c путем /core/components/minishop2/custom/delivery/myDeliveryHandler.class.php | |
| 3. Копируем содержимое в файл myDeliveryHandler.class.php | |
| 4. Теперь добавляем в настройки системы новый ключ. Я добавляю в настройки контекста. | |
| 5. Ключ - ms2_delivery_cost_free_1 . Цифра «1» - это ID способа доставки. В значении указываем нужную сумму. | |
| 6. У каждого способа доставки указываем класс-обработчик myDeliveryHandler. | |
| 7. В принципе всё. Учёт расстояния и веса убрано из кода для читабельности кода. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class myDeliveryHandler extends msDeliveryHandler { | |
| public function getCost(msOrderInterface $order, msDelivery $delivery, $cost = 0) { | |
| /** | |
| * @var $cart array - получаем корзину | |
| * @var $total_cost int - Цена товаров без учета доставки | |
| * @var $delivery_price int - Цена доставки | |
| */ | |
| $cart = $this->ms2->cart->status(); | |
| $total_cost = $cart['total_cost']; | |
| $delivery_price = $delivery->get('price'); | |
| /** | |
| * @var $free_sum int Сумма, при которой доставка бесплатная. По-умолчанию - 0. | |
| */ | |
| $free_sum = $this->modx->getOption('ms2_delivery_cost_free_' . $delivery->get('id'), null, 0, true); | |
| /** | |
| * Если сумма бесплатной доставки равна нулю, | |
| * или общая сумма товаров в корзине меньше | |
| * суммы бесплатной доставки — добавляем цену доставки. | |
| */ | |
| if ($free_sum == 0 OR $total_cost < $free_sum) { | |
| $cost += $delivery_price; | |
| } | |
| return $cost; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment