function nhb_basket_function($atts) { define('NHB_BASKET_SHORTCODE_USED', TRUE); //extract(shortcode_atts(array("count" => get_option('posts_per_page')), $atts)); $nhb_basket = nhb_get_basket(); if (!file_exists(get_template_directory() . '/pistol88-cart/basket_shortcode.php')) { $template_path = NHB_DIR . '/views/basket_shortcode.php'; } else { $template_path = get_template_directory() . '/pistol88-cart/basket_shortcode.php'; } ob_start(); require $template_path; $return = ob_get_contents(); ob_end_clean(); return $return; }
<?php $client_fields = get_option('nhb_client_fields'); if (!empty($_POST)) { $json = array(); $nhb_basket = nhb_get_basket(); if (empty($nhb_basket['products'])) { $json['errors'][] = __('Пустой заказ не может быть обработан', 'nhb'); } $client_data = array_map('htmlspecialchars', $_POST['nhb_client']); $client_data = array_map('trim', $client_data); $_SESSION['nhb_client_data'] = $client_data; foreach ($client_data as $client_field_name => $client_field_value) { if (!isset($client_fields[$client_field_name])) { $json['errors'][] = __('Неизвестное поле: ', 'nhb') . htmlspecialchars($client_field_name); } elseif ($client_fields[$client_field_name]['require']) { if (trim($client_field_value) == '') { $json['errors'][] = __('Не заполнено обязательное поле: ', 'nhb') . htmlspecialchars($client_field_name); } } } $products = array(); foreach ($nhb_basket['products'] as $item_id => $product) { if ($product = get_post($product['id'])) { $products[] = $product; } } if (empty($products)) { $json['errors'][] = __('Неизвестная ошибка', 'nhb') . ' - 001'; } if (get_option('nhb_min_sum') && get_option('nhb_min_sum') > $nhb_basket['price']) {
<?php if (isset($_POST['id'])) { $json = array(); $id = (int) $_POST['id']; $count = (int) $_POST['count']; if ($count >= 0) { $_SESSION['nhb_basket'][$id]['count'] = $count; } else { unset($_SESSION['nhb_basket'][$id]); } $json = nhb_get_basket(true); echo json_encode($json); die; }