Created
January 26, 2017 00:39
-
-
Save OlegShchavelev/4bdfc2ad7aa94c587faffd205e7e7baf to your computer and use it in GitHub Desktop.
Подключаем бесплатную доставку c определенной суммы заказа в minishop2
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment