Created
December 30, 2016 13:37
-
-
Save OlegShchavelev/191dd8bad8fd2df4f60a560322d5d7dd to your computer and use it in GitHub Desktop.
Бесплатная доставка с определенный суммы в Minishop 2
This file contains 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 | |
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; | |
} | |
} |
регистрирация службу по этому адресу выполнив код ниже в сниппете или в 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
Круто!