Skip to content

Commit

Permalink
Наимнование файлов/функций/переменных. Файл readme.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnekler committed May 25, 2018
1 parent dd02674 commit 15dab5a
Show file tree
Hide file tree
Showing 10 changed files with 477 additions and 392 deletions.
37 changes: 0 additions & 37 deletions CalculateDeliveryCdek__inc.php

This file was deleted.

42 changes: 42 additions & 0 deletions CargoDeliveryServiceCDEK.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/*
Plugin Name: Cargo Delivery Service CDEK
Plugin URI: http://mint-studio.org
Description: Плагин рассчитывает стоимость доставки товара службой "Сдэк"
Version: 1.0
Author: Mint Studio
Author URI: http://mint-studio.org
*/

/**
* Register the scripts for the public-facing side of the site.
*
* @since 1.0.0
*
*/

if ( ! defined( 'MY_PlUGIN_URL' ) )
define( 'MY_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
if ( ! defined( 'MY_PLUGIN_PATH' ) )
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );

// Include script for the front end
function cds_cdek_include_frontend_js()
{
if ( is_cart() || is_checkout() ) {
wp_enqueue_script('jquery-ui-1.12.1', MY_PLUGIN_URL . 'assets/js/jquery-ui-1.12.1.min.js', array( 'jquery' ), '1.12.1');
wp_enqueue_script('cds_cdek_script', MY_PLUGIN_URL . 'assets/js/CDS_CDEK_script.js', array('jquery' ), '1.0');
}
}
add_action( 'wp_enqueue_scripts', 'cds_cdek_include_frontend_js', 10);

// Include script for the admin
function cds_cdek_include_admin_js() {
wp_enqueue_script( 'cds_cdek_admin_script', MY_PLUGIN_URL . 'assets/js/CDS_CDEK_script.js', array('jquery', 'jquery-ui-core'), '1.0', true );
}
add_action('admin_enqueue_scripts', 'cds_cdek_include_admin_js', 5);

// Include main function file
include_once(MY_PLUGIN_PATH . 'inc/CDS_CDEK_function.php');

?>
93 changes: 93 additions & 0 deletions assets/js/CDS_CDEK_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
jQuery(document).ready(function($){
$('#billing_city_field').attr('style','position: relative;margin: 0; padding: 0;height: 0;background: none;opacity: 0;z-index: -1;')

var apiUrl = "http://api.cdek.ru/city/getListByTerm/jsonp.php?callback=?";

if (window.location.protocol == 'https:'){
apiUrl = "https://api.cdek.ru/city/getListByTerm/jsonp.php?callback=?";
}

// Получаем код города ( От клиента ) на странице оформления заказа
$("#city_cdek").autocomplete({
source: function(request,response) {
$.ajax({
url: apiUrl,
dataType: "jsonp",
data: {
q: function () { return $("#city_cdek").val() },
name_startsWith: function () { return $("#city_cdek").val() }
},
success: function(data) {
response($.map(data.geonames, function(item) {
return {
label: item.name,
value: item.name,
id: item.id
}
}));
}
});
},
minLength: 1,
select: function(event,ui) {
$('#billing_city').val(ui.item.id);
$(document.body).trigger("update_checkout");
}
});

// Получаем код города ( От администратора ) в карточке товара
$("#cdek_shipping_option_city_of_dispatch").autocomplete({
source: function(request,response) {
$.ajax({
url: apiUrl,
dataType: "jsonp",
data: {
q: function () { return $("#cdek_shipping_option_city_of_dispatch").val() },
name_startsWith: function () { return $("#cdek_shipping_option_city_of_dispatch").val() }
},
success: function(data) {
response($.map(data.geonames, function(item) {
return {
label: item.name,
value: item.name,
id: item.id
}
}));
}
});
},
minLength: 1,
select: function(event,ui) {
$('#cdek_shipping_option_city_code').val(ui.item.id);
}
});

// Получаем код города ( От администратора ) на странице настройки плагина
$("#woocommerce_cdek-method_from_city").autocomplete({
source: function(request,response) {
$.ajax({
url: apiUrl,
dataType: "jsonp",
data: {
q: function () { return $("#woocommerce_cdek-method_from_city").val() },
name_startsWith: function () { return $("#woocommerce_cdek-method_from_city").val() }
},
success: function(data) {
response($.map(data.geonames, function(item) {
return {
label: item.name,
value: item.name,
id: item.id
}
}));
}
});
},
minLength: 1,
select: function(event,ui) {
$('#woocommerce_cdek-method_from_city_code').val(ui.item.id);
}
});

});

92 changes: 0 additions & 92 deletions assets/js/сdek-script.js

This file was deleted.

40 changes: 40 additions & 0 deletions inc/CDS_CDEK_admin_function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
add_action( 'woocommerce_product_options_shipping', 'cds_cdek_add_custom_shipping_fields' );
add_action( 'woocommerce_process_product_meta', 'cds_cdek_add_custom_shipping_fields_save' );

function cds_cdek_add_custom_shipping_fields() {
global $woocommerce, $post;

echo '<div class="options_group">';

woocommerce_wp_text_input(
array(
'id' => 'cds_cdek_shipping_option_city_of_dispatch',
'label' => 'Город отправки',
'placeholder' => 'Город отправки товара',
'desc_tip' => 'true',
'description' => 'Город откуда будет отправлен товар. По умолчанию - Краснодар. Используется для расчета стоимости доставки службой "СДЭК"'
)
);

woocommerce_wp_hidden_input(
array(
'id' => 'cds_cdek_shipping_option_city_code',
'value' => ''
)
);

echo '</div>';
}

function cds_cdek_add_custom_shipping_fields_save( $post_id ){

$cds_cdek_shipping_option_city_of_dispatch = $_POST['cds_cdek_shipping_option_city_of_dispatch'];
update_post_meta( $post_id, 'cds_cdek_shipping_option_city_of_dispatch', sanitize_text_field( $cds_cdek_shipping_option_city_of_dispatch ) );

$cds_cdek_shipping_option_city_code = $_POST['cds_cdek_shipping_option_city_code'];
update_post_meta( $post_id, 'cds_cdek_shipping_option_city_code', sanitize_text_field( $cds_cdek_shipping_option_city_code ) );

}

?>
Loading

0 comments on commit 15dab5a

Please sign in to comment.