Skip to content

Instantly share code, notes, and snippets.

@OlegShchavelev
Created December 30, 2016 13:37
Show Gist options
  • Save OlegShchavelev/191dd8bad8fd2df4f60a560322d5d7dd to your computer and use it in GitHub Desktop.
Save OlegShchavelev/191dd8bad8fd2df4f60a560322d5d7dd to your computer and use it in GitHub Desktop.
Бесплатная доставка с определенный суммы в Minishop 2
<?php
if (!class_exists('msDeliveryInterface')) {
require_once MODX_CORE_PATH . 'components/minishop2/model/minishop2/msdeliveryhandler.class.php';
}
//Важно: при изменении названия файла, вот в этом месте также нужно изменить класс
class mscustomdeliveryhandler extends msDeliveryHandler implements msDeliveryInterface {
public function getCost(msOrderInterface $order, msDelivery $delivery, $cost = 0) {
$cart = $this->ms2->cart->status();
// Подключаем ClientConfig
$path = $this->modx->getOption('clientconfig.core_path', null, $this->modx->getOption('core_path') . 'components/clientconfig/');
$path .= 'model/clientconfig/';
$clientConfig = $this->modx->getService('clientconfig','ClientConfig', $path);
$settings = $clientConfig->getSettings();
$value = $this->modx->getOption('deliverys', $settings);
if ($cart['total_cost'] < $value) {
$add_price = $delivery->get('price');
if (preg_match('/%$/', $add_price)) {
$add_price = str_replace('%', '', $add_price);
$add_price = $cost / 100 * $add_price;
}
$cost += $add_price;
}
return $cost;
}
}
@pakimov
Copy link

pakimov commented Dec 30, 2016

Круто!

@pakimov
Copy link

pakimov commented Dec 30, 2016

регистрирация службу по этому адресу выполнив код ниже в сниппете или в Console:

if ($miniShop2 = $modx->getService('miniShop2')) {
$miniShop2->addService('delivery', 'MskDelivery',
'{core_path}components/minishop2/custom/msdeliveryhandler.class.php'
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment