Выберите способ доставки
delivery->get_enabled_methods();
$all_payment_methods = $netshop->payment->get_enabled_methods();
$params = array(
'f_City' => isset($f_City) ? $f_City : '',
'f_Address' => isset($f_Address) ? $f_Address : '',
'f_Zip' => isset($f_Zip) ? $f_Zip : '',
);
// Объекты, необходимые для дальнейших расчётов для способов доставки и оплаты:
$order = nc_netshop_order::from_post_data($params, $netshop);
$context = $netshop->get_condition_context();
$context->set_order($order);
// Загружать данные о стоимости и сроках доставки для способов с автоматизированным расчётом через AJAX (по умолчанию — true):
$use_ajax_to_load_delivery_estimate =
isset($cc_settings['delivery_ajax_loading']) ? $cc_settings['delivery_ajax_loading'] : true;
// Показывать недоступные методы доставки в списке способов доставки:
$show_unavailable_delivery_methods =
isset($cc_settings['show_all_delivery_methods']) ? $cc_settings['show_all_delivery_methods'] : false;
$available_delivery_methods = $all_delivery_methods->matching($context);
$methods_to_show = $show_unavailable_delivery_methods
? $all_delivery_methods->with_variants($order)
: $available_delivery_methods;
$num_methods_to_show = count($methods_to_show);
global $method_ids_to_load_with_ajax, $is_show_address;
$method_ids_to_load_with_ajax = array();
$is_show_address = false;
// --- НАЧАЛО ШАБЛОНА ВЫВОДА СПОСОБА ДОСТАВКИ ---
$print_delivery_method = function (nc_netshop_delivery_method $method, $options_block = '')
use (
$context,
$use_ajax_to_load_delivery_estimate,
$num_methods_to_show,
$show_unavailable_delivery_methods
) {
static $is_first = true; // флаг для пред-выбора первого элемента
global $method_ids_to_load_with_ajax, $delivery_variant_id, $is_show_address;
$order = $context->get_order();
$is_available = !$show_unavailable_delivery_methods || $method->evaluate_conditions($context);
$method_name = $method->get('name');
$method_id = $method->get_id();
$method_description = $method->get('description');
$method_type = $method->get('delivery_type');
if ($num_methods_to_show > 1) {
// Решаем, должен ли текущий пункт быть выбранным:
if ($is_available) {
// checked, если уже был указан метод доставки (возврат со страницы
// подтверждения), иначе — если это первый метод в списке:
$is_checked = isset($delivery_variant_id) ? $delivery_variant_id == $method_id : $is_first;
} else {
// недоступные методы никогда не являются выбранными
$is_checked = false;
}
} else {
$is_checked = true;
}
// Если выбранный метод это доставка курьером или по почте, то надо показывать форму для ввода адреса
if ($is_checked && ($method_type == nc_netshop_delivery::DELIVERY_TYPE_POST ||
$method_type == nc_netshop_delivery::DELIVERY_TYPE_COURIER)
) {
$is_show_address = true;
}
?>
if ($options_block): ?>
= $options_block ?>
endif ?>
where('delivery_type', nc_netshop_delivery::DELIVERY_TYPE_PICKUP);
if (count($pickup_delivery_methods)) {
// «Доставка до пункта выдачи»
echo "";
echo "
";
// Название города
$city = $order->get_location_name();
// --- КАРТА ---
if ($pickup_delivery_methods->any('has_delivery_points_with_coordinates', true)) {
// Готовим данные для карты
$map_settings = array(
'balloon_select_point_button_text' => NETCAT_MODULE_NETSHOP_DELIVERY_POINT_SELECT_BUTTON,
'balloon_price_prefix' => NETCAT_MODULE_NETSHOP_CHECKOUT_DELIVERY_ESTIMATE_PRICE,
'delivery_methods' => array(),
);
// На карте может быть показан адрес, введённый на предыдущем этапе
if ($f_Address) {
$map_settings['home_address'] = trim("$f_Zip $city $f_Address");
} else {
$map_settings['home_address'] = '';
}
/** @var nc_netshop_delivery_method $method */
foreach ($pickup_delivery_methods as $method) {
$map_settings['delivery_methods'][] = array(
'id' => $method->get_id(),
'name' => $method->get('name'),
'price' => $netshop->format_price($method->get_estimate($order)->get('price')),
'points' => $method->get_delivery_points($city)->to_array(true),
);
}
// Подключение и инициализация скриптов
?>
get_delivery_points($city)->sort_by_property_value('address');
$delivery_points_div = '';
if (count($delivery_points)) {
$delivery_points_div = "
";
/** @var nc_netshop_delivery_point $delivery_point */
foreach ($delivery_points as $delivery_point) {
$this_delivery_point_id = $delivery_point->get_id();
$delivery_points_div .=
"
" .
"
";
}
$delivery_points_div .= "
";
}
$print_delivery_method($method, $delivery_points_div);
}
echo "
";
}
unset($pickup_delivery_methods_delivery_methods);
// 2) ДОСТАВКА КУРЬЕРОМ
$courier_delivery_methods = $methods_to_show->where('delivery_type', nc_netshop_delivery::DELIVERY_TYPE_COURIER);
if (count($courier_delivery_methods)) {
// «Доставка курьером по указанному адресу»
echo "";
echo "
";
/** @var nc_netshop_delivery_method $method */
foreach ($courier_delivery_methods as $method) {
$print_delivery_method($method);
}
echo "
";
}
unset($courier_delivery_methods);
// 3) ДОСТАВКА В ПОЧТОВОЕ ОТДЕЛЕНИЕ
$post_delivery_methods = $methods_to_show->where('delivery_type', nc_netshop_delivery::DELIVERY_TYPE_POST);
if (count($post_delivery_methods)) {
// «Доставка в почтовое отделение»
echo "";
echo "
";
/** @var nc_netshop_delivery_method $method */
foreach ($post_delivery_methods as $method) {
$print_delivery_method($method);
}
echo "
";
}
unset($post_delivery_methods_delivery_methods);
// Показ дополнительных параметров доставки (выбор точки самовывоза) при выборе способа доставки (требуется jQuery!)
?>