Plugin Directory

Changeset 3205693


Ignore:
Timestamp:
12/10/2024 01:51:39 PM (16 months ago)
Author:
eshoplogistic
Message:

Добавлена опция сохранения доп. услуг

Location:
eshoplogisticru/trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • eshoplogisticru/trunk/Http/Controllers/OptionsController.php

    r3028864 r3205693  
    266266
    267267    /**
     268     * @param string $key
     269     *
     270     * @return ResponseInterface
     271     */
     272    public function saveAddFieldForm($addField) {
     273        if(empty($addField)) return $this->json(['status' => 'error', 'msg' => __('Название пустое', WC_ESL_DOMAIN)]);
     274
     275        $this->options->save([
     276            'wc_esl_shipping' => [
     277                'add_field_form' => $addField
     278            ]
     279        ]);
     280
     281        return $this->json([
     282            'status' => 'success',
     283            'msg'    => __('Данные по выгрузке успешно сохранены', WC_ESL_DOMAIN),
     284            'data'   => $this->options->getOption('wc_esl_shipping_add_field_form')
     285        ]);
     286    }
     287
     288    /**
    268289     * @param string $data
    269290     *
  • eshoplogisticru/trunk/Modules/Ajax.php

    r3199345 r3205693  
    7474        add_action('wp_ajax_wc_esl_shipping_unloading_status_update', [$this, 'unloadingStatusUpdate']);
    7575        add_action('wp_ajax_wc_esl_shipping_unloading_delete', [$this, 'unloadingDelete']);
    76 
     76        add_action('wp_ajax_wc_esl_shipping_get_add_field', [$this, 'getAddField']);
     77        add_action('wp_ajax_wc_esl_shipping_save_add_field', [$this, 'saveAddField']);
    7778    }
    7879
     
    253254        $response->send();
    254255    }
     256
     257    public function saveAddField()
     258    {
     259        $addField = !empty($_POST['result']) ? wc_clean($_POST['result']) : [];
     260        $type = !empty($_POST['type']) ? wc_clean($_POST['type']) : [];
     261        $addField = stripslashes(html_entity_decode($addField));
     262        $addField = json_decode($addField, true);
     263
     264        $optionsRepository = new OptionsRepository();
     265        $result = $optionsRepository->getOption('wc_esl_shipping_add_field_form');
     266
     267        foreach ($addField as $value){
     268            if(isset($value['name']))
     269                $result[$type][$value['name']] = $value['value'];
     270        }
     271
     272        $optionsController = new OptionsController();
     273        $response = $optionsController->saveAddFieldForm($result);
     274
     275        $response->send();
     276    }
     277
    255278
    256279    public function searchCities()
     
    737760    }
    738761
     762    public function getAddField()
     763    {
     764        $type = isset($_POST['type']) ? wc_clean($_POST['type']) : null;
     765
     766        $optionsRepository = new OptionsRepository();
     767        $apiKey = $optionsRepository->getOption('wc_esl_shipping_api_key');
     768
     769        $additional = array(
     770            'key'     => $apiKey,
     771            'service' => mb_strtolower( $type ),
     772            'detail'  => true
     773        );
     774
     775        $eshopLogisticApi = new EshopLogisticApi( new WpHttpClient() );
     776        $additionalFields = $eshopLogisticApi->apiExportAdditional( $additional );
     777        if ( $additionalFields->hasErrors() ) {
     778            $html = '<p>Ошибка при получении дополнительных услуг</p>';
     779        } else {
     780            $additionalFields = $additionalFields->data();
     781            if ( $additionalFields ){
     782                $additionalFieldsRu = array(
     783                    'packages'  => 'Упаковка',
     784                    'cargo'     => 'Груз',
     785                    'recipient' => 'Получатель',
     786                    'other'     => 'Другие услуги',
     787
     788                );
     789                $type = mb_strtolower( $type );
     790                $optionsRepository = new OptionsRepository();
     791                $addFieldSaved = $optionsRepository->getOption('wc_esl_shipping_add_field_form');
     792
     793                $html = '<form action="/" method="post" id="eslAddFieldForm" data-type="'.$type.'"><div class="esl-box_add">';
     794                foreach ( $additionalFields as $key => $value) {
     795                    $title = ( $additionalFieldsRu[ $key ] ) ?? $key;
     796                    $html .= '<p>'. $title. '</p>';
     797                    foreach ( $value as $k => $v ){
     798                        if(!isset($v['name']))
     799                            continue;
     800
     801                        $valueSaved = '0';
     802                        if(isset($addFieldSaved[$type][$k]) && $addFieldSaved[$type][$k] != '0'){
     803                            $valueSaved = $addFieldSaved[$type][$k];
     804                        }
     805                        $html .= '<div class="form-field_add">';
     806                        $html .= '<label class="label" for="'.$k.'">'.$v['name'].'</label>';
     807                        if ( $v['type'] === 'integer' ){
     808                            $html .= '<input class="form-value_add" type="number" name="'.$k.'" value="'.$valueSaved.'" max="'.$v['max_value'].'">';
     809                        }else{
     810                            $check = '';
     811                            if($valueSaved != '0')
     812                                $check = 'checked="checked"';
     813
     814                            $html .= '<input class="form-value_add" name="'.$k.'" type="checkbox" '.$check.'>';
     815                        }
     816                        $html .= '</div>';
     817                    }
     818                }
     819                $html .= '</div></div>';
     820            }else{
     821                $html = '<p>Дополнительные услуги отсутствуют.</p>';
     822            }
     823
     824        }
     825
     826        wp_send_json([
     827            'success' => true,
     828            'data' => $html,
     829            'msg' => __("", WC_ESL_DOMAIN)
     830        ]);
     831    }
     832
    739833}
  • eshoplogisticru/trunk/Modules/AssetsLoader.php

    r3171498 r3205693  
    175175            );
    176176
     177            wp_enqueue_style(
     178                'wc_esl_modal_css',
     179                WC_ESL_PLUGIN_URL . 'assets/css/modal.css',
     180                [],
     181                WC_ESL_VERSION
     182            );
     183
    177184            wp_enqueue_script(
    178185                'wc_esl_bootstrap_js',
     
    221228                filemtime( WC_ESL_PLUGIN_DIR . 'assets/js/html5sortable.js' ),
    222229                false
     230            );
     231
     232            wp_enqueue_script(
     233                'wc_esl_modal_js',
     234                WC_ESL_PLUGIN_URL . 'assets/js/modal.js',
     235                [ 'jquery' ],
     236                WC_ESL_VERSION,
     237                true
    223238            );
    224239        }
  • eshoplogisticru/trunk/Modules/OptionsPage.php

    r2936599 r3205693  
    8080            'status_form'     => $this->option->getOption('wc_esl_shipping_plugin_status_form'),
    8181            'status_wp'     => $this->unloading->getStatusWp(),
     82            'add_field_form'     => $this->option->getOption('wc_esl_shipping_add_field_form'),
    8283        );
    8384    }
  • eshoplogisticru/trunk/Modules/Unloading.php

    r3201100 r3205693  
    304304                }
    305305
     306                $optionsRepository = new OptionsRepository();
     307                $addFieldSaved = $optionsRepository->getOption('wc_esl_shipping_add_field_form');
     308
     309
    306310                echo View::render( 'unloading-form', [
    307311                    'orderData'          => $orderData,
     
    316320                    'fieldDelivery'      => $fieldDelivery,
    317321                    'orderShippingId'    => $orderShippingId,
    318                     'infoApi'            => $infoApi
     322                    'infoApi'            => $infoApi,
     323                    'addFieldSaved'   => $addFieldSaved
    319324                ] );
    320325            }
  • eshoplogisticru/trunk/assets/css/admin.css

    r2939928 r3205693  
    6161    width: 100%;
    6262    max-width: 315px;
     63    z-index: 999999;
    6364}
    6465
     
    263264    color: rgba(236, 0, 0, 0.66);
    264265}
     266
     267.modal-esl-frame {
     268    display: none;
     269    position: fixed;
     270    left: 0;
     271    top: 0;
     272    width: 100%;
     273    height: 100%;
     274    overflow: auto;
     275    background-color: rgba(0,0,0,0.6);
     276    z-index: 9999;
     277}
     278.modal-esl-frame .modal_content {
     279    background-color: #fefefe;
     280    margin: 10% auto;
     281    padding: 20px;
     282    border: 1px solid #888;
     283    width: 80%;
     284    z-index: 99999;
     285}
     286.modal-esl-frame .modal_content .close_modal_window {
     287    color: #aaa;
     288    float: right;
     289    font-size: 28px;
     290    font-weight: bold;
     291    cursor: pointer;
     292}
     293
     294.modal-esl-frame .title {
     295    padding-bottom: 45px;
     296}
     297
     298.modal-esl-frame #buttonModalAddField{
     299    position: relative;
     300    left: 50%;
     301    transform: translate(-50%, 0);
     302    height: auto;
     303    color: #fff;
     304    background-color: #489afa;
     305    border-color: #0062cc;
     306    margin-top: 15px;
     307}
     308
     309.modal-esl-frame #buttonModalAddField:hover{
     310    background-color: #086be1;
     311    border-color: #0062cc;
     312}
     313
     314
     315#modal-esl-add-field .label{
     316    position: static;
     317}
     318
     319#modal-esl-add-field input{
     320    border: black !important;
     321    height: 15px;
     322    margin-left: 2px;
     323}
     324
     325#modal-esl-add-field input[type=checkbox]:checked::before {
     326    float: unset;
     327}
     328
     329#modal-esl-add-field input[type=checkbox] {
     330    float: unset;
     331    height: 15px;
     332    width: 15px !important;
     333    border: 1px solid rgba(0, 0, 0, 0.14) !important;
     334    margin: 2px auto;
     335}
     336
     337#modal-esl-add-field .form-field_add {
     338    margin: 10px;
     339    display: inline-grid;
     340}
  • eshoplogisticru/trunk/assets/js/checkout_frame_v2.js

    r3171498 r3205693  
    1 if(document.getElementById('wc_esl_billing_terminal').value){
    2     window.keyDelivery = 'terminal'
    3 }else if(document.getElementById('wc_esl_shipping_terminal').value){
    4     window.keyDelivery = 'terminal'
     1if(document.getElementById('wc_esl_billing_terminal')){
     2    if(document.getElementById('wc_esl_billing_terminal').value){
     3        window.keyDelivery = 'terminal'
     4    }else if(document.getElementById('wc_esl_shipping_terminal').value){
     5        window.keyDelivery = 'terminal'
     6    }else{
     7        window.keyDelivery = 'door'
     8    }
    59}else{
    610    window.keyDelivery = 'door'
    711}
     12
    813
    914window.widgetInit = false
  • eshoplogisticru/trunk/assets/js/settings.js

    r2999459 r3205693  
    11window.addEventListener('load', function(event) {
    22    eslRun()
     3
     4    let modalAddField = document.getElementById("modal-esl-add-field")
     5    let contentAjax = document.getElementById("content-add-field_ajax")
     6    let span = document.getElementsByClassName("close_modal_window")[0]
     7
     8    span.onclick = function () {
     9        modalAddField.style.display = "none"
     10    }
     11
     12    window.onclick = function (event) {
     13        if (event.target === modalAddField) {
     14            modalAddField.style.display = "none"
     15        }
     16    }
     17
     18    let bindEvents = {
     19        clickOnAddField: function (event) {
     20            console.log(event)
     21            let data = [];
     22            data['action'] = 'wc_esl_shipping_get_add_field';
     23            data['type'] = 'sdek';
     24
     25            HttpClientEsl.post(data, function(result){
     26                console.log(result)
     27                if(result.success === true){
     28                    contentAjax.innerHTML = result.data;
     29                }
     30            });
     31            modalAddField.style.display = "block"
     32        },
     33        onCloseModal: function () {
     34            console.log('closeModal')
     35        },
     36    }
     37
     38    let els_add_buttons = document.getElementsByClassName('wc-esl-add__button')
     39    if (els_add_buttons) {
     40        for (let i = 0; i < els_add_buttons.length; i++) {
     41            els_add_buttons[i].addEventListener('click', bindEvents.clickOnAddField, false);
     42        }
     43
     44    }
    345});
    446
     
    3274        enableFrameCheckbox: document.getElementById('enableFrame'),
    3375        statusSave: document.getElementById('statusSave'),
     76        eslAddFieldForm: 'eslAddFieldForm',
     77        buttonAddFieldForm: document.getElementById('buttonModalAddField'),
     78        eslAddFieldSelector: '.modal-esl-frame .modal_content',
    3479
    3580        init: function () {
     
    99144                }));
    100145            }
     146            if(this.buttonAddFieldForm){
     147                this.buttonAddFieldForm.addEventListener('click', this.submitAddFieldForm.bind({
     148                    _self: this
     149                }));
     150            }
     151        },
     152
     153        submitAddFieldForm: function (event) {
     154            event.preventDefault();
     155
     156            let _self = this._self;
     157            let form = document.getElementById(_self.eslAddFieldForm);
     158            let type = form.getAttribute('data-type');
     159            let result = [];
     160            let data = new FormData(form);
     161            for (let [key, value] of data) {
     162                result.push({name:key, value:value});
     163            }
     164
     165            PreloaderEsl.show(_self.eslAddFieldSelector);
     166            _self.changeAddField(result, type);
     167        },
     168
     169        changeAddField: function (result, type) {
     170            let data = [];
     171
     172            data['action'] = 'wc_esl_shipping_save_add_field';
     173            data['result'] = JSON.stringify(result);
     174            data['type'] = type;
     175
     176            HttpClientEsl.post(data, this.callbackChangeAddField.bind({
     177                _self: this
     178            }));
     179        },
     180
     181        callbackChangeAddField: function (response) {
     182            let _self = this._self;
     183            PushEsl.addItem(response.status, response.msg);
     184            PreloaderEsl.hide(_self.eslAddFieldSelector);
     185            console.log(response);
    101186        },
    102187
     
    592677    elem.parentNode.remove();
    593678}
     679
    594680
    595681(function( $ ) {
  • eshoplogisticru/trunk/readme.txt

    r3202478 r3205693  
    44Requires at least: 5.3
    55Tested up to: 6.6
    6 Stable tag: 2.1.43
     6Stable tag: 2.1.44
    77License: GPLv2
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • eshoplogisticru/trunk/views/settings.php

    r3186394 r3205693  
    15611561                    <?php endif; ?>
    15621562
     1563                    <?php if ( $moduleVersion ): ?>
     1564                        <div class="card wc-esl-settings-status esl-section_add_field">
     1565                            <div class="card-header">
     1566                                <?php echo __( 'Дополнительные услуги', WC_ESL_DOMAIN ) ?>
     1567                            </div>
     1568
     1569                            <div class="card-body" id="eslAddFormField">
     1570                                <div class="form-group row align-items-center mb-3">
     1571                                    <div class="col-sm-12">
     1572
     1573                                        <div class="row">
     1574                                            <div class="esl-inner_add col-sm-6">
     1575                                                <button type="button" class="wc-esl-add__button" data-mode="sdek">Настройки для СДЭК</button>
     1576                                            </div>
     1577                                        </div>
     1578
     1579                                    </div>
     1580                                </div>
     1581                            </div>
     1582
     1583                            <div id="modal-esl-add-field" class="modal-esl-frame">
     1584                                <div class="modal_content">
     1585                                    <div class="title">
     1586                                        <span class="close_modal_window">×</span>
     1587                                        <p><strong>Дополнительные услуги</strong><br></p>
     1588                                    </div>
     1589                                    <div id="content-add-field_ajax"></div>
     1590                                    <div class="footer">
     1591                                        <input id="buttonModalAddField" class="btn btn-primary" type="button"  value="Сохранить">
     1592                                    </div>
     1593                                </div>
     1594                            </div>
     1595
     1596                        </div>
     1597                    <?php endif; ?>
     1598
    15631599                </div>
    15641600            </div>
  • eshoplogisticru/trunk/views/unloading-form.php

    r3202478 r3205693  
    2323$orderShippingId    = isset( $orderShippingId ) ? $orderShippingId : '';
    2424$infoApi            = isset( $infoApi ) ? $infoApi : '';
     25$addFieldSaved      = isset( $addFieldSaved ) ? $addFieldSaved : array();
    2526
    2627$fulfillment = false;
     
    300301                                        if(!isset($v['name']))
    301302                                            continue;
     303
     304                                        $type = mb_strtolower( $typeMethod['name']);
     305                                        $valueSaved = '0';
     306                                        if(isset($addFieldSaved[$type][$k]) && $addFieldSaved[$type][$k] != '0'){
     307                                            $valueSaved = $addFieldSaved[$type][$k];
     308                                        }
    302309                                        ?>
    303310                                        <div class="form-field_add">
     
    305312                                            <?php if ( $v['type'] === 'integer' ): ?>
    306313                                                <input class="form-value_add" name="<?php echo $k ?>" type="number"
    307                                                        value="0" max="<?php echo $v['max_value'] ?>">
    308                                             <?php else: ?>
    309                                                 <input class="form-value_add" name="<?php echo $k ?>" type="checkbox">
     314                                                       value="<?php echo $valueSaved ?>" max="<?php echo $v['max_value'] ?>">
     315                                            <?php else:
     316                                                $check = '';
     317                                                if($valueSaved != '0')
     318                                                    $check = 'checked="checked"';
     319                                                ?>
     320                                                <input class="form-value_add" name="<?php echo $k ?>" type="checkbox" <?php echo $check ?>>
    310321                                            <?php endif; ?>
    311322                                        </div>
  • eshoplogisticru/trunk/wc-eshop-logistic.php

    r3202478 r3205693  
    66 *
    77 * @link              https://wp.eshoplogistic.ru/
    8  * @since             2.1.43
     8 * @since             2.1.44
    99 * @package           WC_Eshop_Logistic
    1010 *
     
    1313 * Plugin URI:        https://wp.eshoplogistic.ru/
    1414 * Description:       Несколько служб доставки в одной интеграции: CDEK, DPD, Boxberry, IML, Почта России, Деловые Линии, ПЭК, Dostavista, GTD, Байкал Сервис и др.
    15  * Version:           2.1.43
     15 * Version:           2.1.44
    1616 * Author:            eShopLogistic
    1717 * Author URI:        https://eshoplogistic.ru/p747575
     
    4141define( 'WC_ESL_PLUGIN_DIR', plugin_dir_path(__FILE__) );
    4242
    43 define( 'WC_ESL_VERSION', '2.1.43' );
     43define( 'WC_ESL_VERSION', '2.1.44' );
    4444
    4545define( 'WC_ESL_DOMAIN', 'wc-esl' );
Note: See TracChangeset for help on using the changeset viewer.