1
0
mirror of synced 2025-02-21 01:13:13 +03:00

Merge pull request #2 from iyzoer/master

Button for upload
This commit is contained in:
Alex Lushpai 2017-06-14 13:13:35 +03:00 committed by GitHub
commit 5120740c83
2 changed files with 59 additions and 31 deletions

View File

@ -191,22 +191,59 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
'description' => 'Отметьте данный пункт, если хотите выгружать остатки товаров из CRM в магазин.'
);
$this->form_fields[] = array(
'title' => __( 'Настройки выгрузки', 'woocommerce' ),
'type' => 'title',
'description' => '',
'id' => 'upload_options'
);
$options = array_filter(get_option( 'woocommerce_integration-ecomlogic_settings' ));
$this->form_fields['uploadToCrm'] = array(
'label' => __( 'Выгрузить все заказы и клиентов', 'textdomain' ),
'title' => 'Выгрузка заказов и клиентов',
'class' => 'checkbox',
'type' => 'checkbox',
'description' => 'Поставьте галочку, и нажмите сохранить, чтобы выгрузить все существующие заказы и клиентов.'
);
if (!isset($options['uploads'])) {
$this->form_fields[] = array(
'title' => __( 'Выгрузка клиентов и заказов', 'woocommerce' ),
'type' => 'title',
'description' => '',
'id' => 'upload_options'
);
$this->form_fields['upload-button'] = array(
'label' => 'Выгрузить',
'title' => __( 'Выгрузка клиентов и заказов', 'woocommerce-integration-ecomlogic' ),
'type' => 'button',
'description' => __( 'Пакетная выгрузка существующих клиентов и заказов.', 'woocommerce-integration-ecomlogic' ),
'desc_tip' => true,
'id' => 'uploads-ecomlogic'
);
}
}
}
public function generate_button_html( $key, $data ) {
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
'class' => 'button-secondary',
'css' => '',
'custom_attributes' => array(),
'desc_tip' => false,
'description' => '',
'title' => '',
);
$data = wp_parse_args( $data, $defaults );
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['label'] ); ?></span></legend>
<button id="<?php echo $data['id']; ?>" class="<?php echo esc_attr( $data['class'] ); ?>" type="button" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo wp_kses_post( $data['label'] ); ?></button>
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
}
}
endif;

View File

@ -294,32 +294,23 @@ function upload_to_crm() {
$options = array_filter(get_option( 'woocommerce_integration-retailcrm_settings' ));
if ($options['uploadToCrm'] == 'yes' && !isset($options['uploaded'])) {
$options['uploadToCrm'] = 'no';
$options['uploaded'] = 'yes';
$orders = new WC_Retailcrm_Orders();
$customers = new WC_Retailcrm_Customers();
$customers->customersUpload();
$orders->ordersUpload();
$orders = new WC_Retailcrm_Orders();
$customers = new WC_Retailcrm_Customers();
$customers->customersUpload();
$orders->ordersUpload();
update_option('woocommerce_integration-retailcrm_settings', $options);
}
if (isset($options['uploaded'])) {
$options['uploadToCrm'] = 'no';
update_option('woocommerce_integration-retailcrm_settings', $options);
}
$options['uploads'] = 'yes';
update_option('woocommerce_integration-ecomlogic_settings', $options);
}
function ajax_upload() {
$ajax_url = admin_url('admin-ajax.php');
?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
$.ajax({
jQuery('#uploads-ecomlogic').bind('click', function() {
jQuery.ajax({
type: "POST",
url: "<?php echo $ajax_url; ?>?action=do_upload",
url: '<?php echo $ajax_url; ?>?action=do_upload',
success: function (response) {
console.log('AJAX response : ',response);
}