Forked from Electrica/gist:075cc906489807318686dfd83ec53845
Created
March 4, 2020 14:21
-
-
Save Advanc8d/24d55a5b622090d934da7651df6b5d9c to your computer and use it in GitHub Desktop.
Вывод доставки отдельным столбцом
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 CustomOrder extends msOrderHandler{ | |
public function getCost($with_cart = true, $only_cost = false) { | |
$response = $this->ms2->invokeEvent('msOnBeforeGetOrderCost', array( | |
'order' => $this, | |
'cart' => $this->ms2->cart, | |
'with_cart' => $with_cart, | |
'only_cost' => $only_cost, | |
)); | |
if (!$response['success']) { | |
return $this->error($response['message']); | |
} | |
$cart = $this->ms2->cart->status(); | |
$cost = $with_cart | |
? $cart['total_cost'] | |
: 0; | |
/** @var msDelivery $delivery */ | |
if (!empty($this->order['delivery']) && $delivery = $this->modx->getObject('msDelivery', | |
$this->order['delivery']) | |
) { | |
$cost = $delivery->getCost($this, $cost); | |
$desliveryCost = $delivery->getCost($this, 0); | |
} | |
/** @var msPayment $payment */ | |
if (!empty($this->order['payment']) && $payment = $this->modx->getObject('msPayment', | |
$this->order['payment']) | |
) { | |
$cost = $payment->getCost($this, $cost); | |
} | |
$response = $this->ms2->invokeEvent('msOnGetOrderCost', array( | |
'order' => $this, | |
'cart' => $this->ms2->cart, | |
'with_cart' => $with_cart, | |
'only_cost' => $only_cost, | |
'cost' => $cost, | |
)); | |
if (!$response['success']) { | |
return $this->error($response['message']); | |
} | |
$cost = $response['data']['cost']; | |
//$this->log(1, print_r($response['data'])); | |
return $only_cost | |
? $cost | |
: $this->success('', array('cost' => $cost, 'deliveryCost' => $desliveryCost)); | |
} | |
} | |
// Добавить скрипт | |
miniShop2.Order.deliveryCost = '#ms2_delivery_cost'; | |
miniShop2.Callbacks.Order.getcost.response.success = function(response) { | |
var rdc = response.data['delivery_cost']; | |
if(rdc) $(miniShop2.Order.deliveryCost, miniShop2.Order.order).text(miniShop2.Utils.formatPrice(rdc)); | |
else $(miniShop2.Order.deliveryCost, miniShop2.Order.order).text('0'); | |
} | |
miniShop2.Callbacks.Order.getcost.response.error = function(response) { | |
var cost = response.data['cost']; | |
$(miniShop2.Order.orderCost).text(miniShop2.Utils.formatPrice(cost)); | |
$(miniShop2.Order.deliveryCost, miniShop2.Order.order).text('0'); | |
} | |
miniShop2.Callbacks.Order.add.response.success = function(response) { | |
miniShop2.Order.getcost(); | |
} | |
//в чанке вставить: | |
<span id="deliveryprice">Стоимость доставки: <span id="ms2_delivery_cost"></span> руб.</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment