shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ebay_item_link.twig (21689B)


      1 {{ header }}{{ column_left }}
      2 <div id="content">
      3   <div class="page-header">
      4     <div class="container-fluid">
      5       <div class="pull-right">
      6         <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a>
      7       </div>
      8       <h1>{{ heading_title }}</h1>
      9       <ul class="breadcrumb">
     10         {% for breadcrumb in breadcrumbs %}
     11         <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
     12         {% endfor %}
     13       </ul>
     14     </div>
     15   </div>
     16   <div class="container-fluid">
     17     <div class="alert alert-info">
     18       <p>{{ text_link_desc1 }}</p>
     19       <p>{{ text_link_desc2 }}</p>
     20       <p>{{ text_link_desc3 }}</p>
     21       <p>{{ text_link_desc4 }}</p>
     22     </div>
     23     <div class="panel panel-default">
     24       <div class="panel-heading">
     25         <h1 class="panel-title"><i class="fa fa-unlink fa-lg"></i> {{ text_unlinked_items }}</h1>
     26       </div>
     27       <div class="panel-body">
     28         <p>{{ text_text_unlinked_desc }}</p>
     29         <div class="well">
     30           <div class="row">
     31             <div class="col-sm-4">
     32               <div class="form-group">
     33                 <label class="control-label" for="filter_title">{{ text_filter_title }}</label>
     34                 <input type="text" name="filter_title" value="" placeholder="{{ text_filter_title }}" id="filter_title" class="form-control" />
     35               </div>
     36             </div>
     37             <div class="col-sm-4">
     38               <div class="form-group">
     39                 <label class="control-label">{{ text_filter_range }}</label>
     40                 <div class="row">
     41                   <div class="col-sm-6">
     42                     <input type="text" name="filter_qty_min" value="" class="form-control" placeholder="{{ text_filter_range_from }}" id="filter-qty-min" />
     43                   </div>
     44                   <div class="col-sm-6">
     45                     <input type="text" name="filter_qty_max" value=""  class="form-control" placeholder="{{ text_filter_range_to }}" id="filter-qty-max" />
     46                   </div>
     47                 </div>
     48               </div>
     49             </div>
     50             <div class="col-sm-4">
     51               <div class="form-group">
     52                 <label class="control-label">{{ text_filter_var }}</label>
     53                 <select name="filter_variant" class="form-control" id="filter-variant">
     54                   <option value="1">{{ text_yes }}</option>
     55                   <option value="0">{{ text_no }}</option>
     56                 </select>
     57               </div>
     58             </div>
     59           </div>
     60         </div>
     61         <table class="table table-bordered table-hover">
     62           <thead>
     63             <tr>
     64               <th class="text-left"></th>
     65               <th class="text-left">{{ column_item_id }}</th>
     66               <th class="text-left">{{ column_listing_title }}</th>
     67               <th class="text-left">{{ column_product_auto }}</th>
     68               <th class="text-center">{{ column_stock_available }}</th>
     69               <th class="text-center">{{ column_allocated }}</th>
     70               <th class="text-center">{{ column_ebay_stock }}</th>
     71               <th class="text-center">{{ column_variants }}</th>
     72               <th class="text-center">{{ column_action }}</th>
     73             </tr>
     74           </thead>
     75           <tbody id="ebay-listings">
     76             <tr id="fetching-ebay-items">
     77               <td class="text-center" colspan="9">{{ text_text_unlinked_info }}</td>
     78             </tr>
     79           </tbody>
     80         </table>
     81         <div class="buttons"> <a class="btn btn-primary" id="check-unlinked-items">{{ button_check_unlinked }}</a>
     82           <input type="hidden" name="unlinked_page" id="unlinked-page" value="1" />
     83         </div>
     84       </div>
     85     </div>
     86     <div class="panel panel-default">
     87       <div class="panel-heading">
     88         <h1 class="panel-title"><i class="fa fa-link fa-lg"></i> {{ text_linked_items }}</h1>
     89       </div>
     90       <div class="panel-body">
     91         <p>{{ text_text_linked_desc }}</p>
     92         <table class="table table-bordered table-hover">
     93           <thead>
     94             <tr>
     95               <th class="text-left">{{ column_product }}</th>
     96               <th class="text-center">{{ column_item_id }}</th>
     97               <th class="text-center">{{ column_allocated }}</th>
     98               <th class="text-center">{{ column_stock_available }}</th>
     99               <th class="text-center">{{ column_stock_reserve }}</th>
    100               <th class="text-center">{{ column_ebay_stock }}</th>
    101               <th class="text-center">{{ column_variants }}</th>
    102               <th class="text-center">{{ column_status }}</th>
    103               <th class="text-center">{{ column_action }}</th>
    104             </tr>
    105           </thead>
    106           <tr>
    107             <td class="text-left" colspan="9" id="checking-linked-items"><a class="btn btn-primary" id="load-usage"><i class="fa fa-cog fa-lg fa-spin"></i> {{ text_text_loading_items }}</a></td>
    108           </tr>
    109           <tbody style="display:none;" id="show-linked-items">
    110             {% for id, item in linked_items %}
    111               <input type="hidden" name="ebay_qty_{{ id }}" value="" id="ebay-qty-{{ id }}" />
    112               <input type="hidden" name="store_qty_{{ id }}" value="{{ item.qty }}" id="store-qty-{{ id }}" />
    113               <input type="hidden" name="reserve_qty_{{ id }}" value="{{ item.reserve }}" id="reserve-qty-{{ id }}" />
    114               <input type="hidden" name="item_id[]" id="item-id-{{ id }}" value="{{ id }}" class="item-id"  />
    115               <input type="hidden" name="product_id[]" id="product-id-{{ id }}" value="{{ item.product_id }}" />
    116               <input type="hidden" name="options" id="options-{{ id }}" value={{ item.options }}" />
    117               <tr id="row-{{ id }}">
    118                 <td class="text-left"><a href="{{ item.link_edit }}" target="_BLANK">{{ item.name }}</a></td>
    119                 <td class="text-center"><a href="{{ item.link_ebay }}" target="_BLANK">{{ id }}</a></td>
    120                 {% if item.options == 0 %}
    121                   <td class="text-center">{{ item.allocated }}</td>
    122                   <td class="text-center">{{ item.qty }}</td>
    123                   <td class="text-center">{{ item.reserve }}</td>
    124                   <td id="text-qty-{{ id }}" class="text-center"></td>
    125                   <td class="text-center"><span class="label label-danger">{{ text_no }}</span></td>
    126                 {% else %}
    127                   <td class="text-center">-</td>
    128                   <td class="text-center">{% for option in item.options %}{{ option.stock }} x {{ option.combination }}<br />{% endfor %}</td>
    129                   <td></td>
    130                   <td id="text-qty-{{ id }}" class="text-center"></td>
    131                   <td class="text-center" align="center"><span class="label label-success">{{ text_yes }}</span></td>
    132                 {% endif %}
    133                 <td class="text-center" id="text-status-{{ id }}"></td>
    134                 <td class="text-center"><div class="pull-right" id="text-buttons-{{ id }}"></div></td>
    135               </tr>
    136             {% endfor %}
    137           </tbody>
    138         </table>
    139         <div class="pagination">{{ pagination }}</div>
    140       </div>
    141     </div>
    142   </div>
    143 </div>
    144 <script type="text/javascript"><!--
    145   function checkLinkedItems() {
    146       $.ajax({
    147           url: 'index.php?route=extension/openbay/ebay/loadLinkedStatus&user_token={{ user_token }}',
    148           data: $('.item-id').serialize(),
    149           type: 'POST',
    150           dataType: 'json',
    151           success: function(json) {
    152             if (json.data == '') {
    153               $('#checking-linked-items').hide();
    154               $('.pagination').hide();
    155               $('#show-linked-items').html('<tr><td colspan="9" class="text-center">{{ error_no_listings }}</td></tr>').show();
    156             } else {
    157               $.each (json.data, function(key, val) {
    158                 key                 = String(key);
    159                 var product_id      = $('#product-id-' + key).val();
    160                 var store_qty       = $('#store-qty-' + key).val();
    161                 var reserve_qty     = $('#reserve-qty-' + key).val();
    162                 var html_inj        = '';
    163 
    164                 if (val.variants == 0) {
    165                   $('#text-qty-' + key).text(val.qty);
    166                   $('#ebay-qty-' + key).val(val.qty);
    167 
    168                   if (val.status == 1) {
    169                     $('#text-buttons-' + key).html('<a href="{{ edit_url }}' + product_id + '" class="btn btn-primary" data-toggle="tooltip" title="{{ button_edit }}"><i class="fa fa-pencil"></i></a>');
    170 
    171                     if (val.qty == store_qty || val.qty == reserve_qty) {
    172                       $('#text-status-' + key).text('OK');
    173                       $('#row-' + key + ' > td').css('background-color', '#E3FFC8');
    174                     } else {
    175                       $('#text-status-' + key).text('{{ text_stock_error }}');
    176                       $('#row-' + key + ' > td').css('background-color', '#FFD4D4');
    177                       $('#text-buttons-' + key).append('<a onclick="updateLink(' + key + ',' + val.qty + ',' + product_id + ', ' + store_qty + ', ' + reserve_qty + ');" class="btn btn-primary"><span>{{ button_resync }}</a>');
    178                     }
    179                   } else {
    180                     $('#text-status-' + key).text('{{ text_listing_ended }}');
    181                     $('#row-' + key + ' > td').css('background-color', '#FFD4D4');
    182                     $('#text-buttons-' + key).html('<a onclick="removeLink(' + product_id + ', ' + key + ');" class="btn btn-danger"><i class="fa fa-minus-circle fa-lg"></i> {{ button_remove_link }}</a>');
    183                   }
    184                 } else {
    185                   $.each (val.variants, function(key1, val1) {
    186                     html_inj += val1.qty + ' x ';
    187                     $.each (val1.nv.NameValueList, function(key2, val2) {
    188                         html_inj += val2.Value + ' > ';
    189                     });
    190                     html_inj += '<br />';
    191                   });
    192 
    193                   $('#text-qty-' + key).html(html_inj);
    194 
    195                   if (val.status == 0) {
    196                     $('#text-status-' + key).text('{{ text_listing_ended }}');
    197                     $('#row-' + key + ' > td').css('background-color', '#FFD4D4');
    198                     $('#text-buttons-' + key).html('<a onclick="removeLink(' + product_id + ', ' + key + ');" class="btn btn-danger"><i class="fa fa-minus-circle fa-lg"></i> {{ button_remove_link }}</a>');
    199                   } else {
    200                     $('#text-buttons-' + key).html('<a href="{{ edit_url }}' + product_id + '" class="btn btn-primary" data-toggle="tooltip" title="{{ button_edit }}"><i class="fa fa-pencil"></i></a>');
    201                   }
    202                 }
    203               });
    204 
    205               $('#checking-linked-items').hide();
    206               $('#show-linked-items').show();
    207             }
    208           },
    209           failure: function() {
    210               $('#errorBox').text('{{ error_ajax_load }}').fadeIn();
    211           },
    212           error: function() {
    213               $('#errorBox').text('{{ error_ajax_load }}').fadeIn();
    214           }
    215       });
    216   }
    217 
    218   function removeLink(product_id, id) {
    219       $.ajax({
    220           type: 'GET',
    221           url: 'index.php?route=extension/openbay/ebay/removeItemLink&user_token={{ user_token }}&product_id=' + product_id,
    222           dataType: 'json',
    223           success: function(json) {
    224               $('#row-' + id).fadeOut('slow');
    225           },
    226           error: function (xhr, ajaxOptions, thrownError) {
    227           if (xhr.status != 0) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }
    228         }
    229       });
    230   }
    231 
    232   function updateLink(item_id, qty, product_id, store_qty, reserve_qty) {
    233       var r = confirm("{{ text_alert_stock_local }}");
    234       var button_old = $('#text-buttons-' + item_id).html();
    235 
    236       $('#text-buttons-' + item_id).html('<p class="text-center"><i class="fa fa-cog fa-lg fa-spin"></i></p>');
    237 
    238       if (r == true) {
    239           $.ajax({
    240               type: 'GET',
    241               url: 'index.php?route=extension/openbay/ebay/setProductStock&user_token={{ user_token }}&product_id=' + product_id,
    242               dataType: 'json',
    243               success: function(json) {
    244                   if (json.error == false) {
    245                       $('#text-status-' + item_id).text('OK');
    246                       $('#text-buttons-' + item_id).empty().html('<a href="{{ edit_url }}' + product_id + '" class="btn btn-primary">{{ button_edit }}</a>');
    247                       $('#row-' + item_id + ' > td').css('background-color', '#E3FFC8');
    248                       $('#l-' + item_id + '-qty-input').val(qty);
    249                       $('#l-' + item_id + '-qty').val(qty);
    250                       if (reserve_qty > 0) {
    251                         $('#text-qty-' + item_id).text(reserve_qty);
    252                       } else {
    253                         $('#text-qty-' + item_id).text(store_qty);
    254                       }
    255                       $('#reserve-qty-' + item_id).text(reserve_qty);
    256                   } else {
    257                       $('#text-buttons-' + item_id).html(button_old);
    258                       alert(json.msg);
    259                   }
    260               },
    261               failure: function() {
    262                   $('#text-buttons-' + item_id).html(button_old);
    263                   alert('{{ error_ajax_load }}');
    264               },
    265               error: function() {
    266                   $('#text-buttons-' + item_id).html(button_old);
    267                   alert('{{ error_ajax_load }}');
    268               }
    269           });
    270       }
    271   }
    272 
    273   function saveListingLink(id) {
    274       var product_id      = $('#l-' + id + '-pid').val();
    275       var qty             = $('#l-' + id + '-qty-input').val();
    276       var ebayqty         = $('#l-' + id + '-qtyebayinput').val();
    277       var variants        = $('#l-' + id + '-variants').val();
    278 
    279       if (product_id === '') {
    280           alert('{{ error_link_value }}');
    281           return false;
    282       }
    283 
    284       if (qty < 1) {
    285           alert('{{ error_link_no_stock }}');
    286           return false;
    287       }
    288 
    289       $.ajax({
    290           url: 'index.php?route=extension/openbay/ebay/saveItemLink&user_token={{ user_token }}&pid=' + product_id + '&itemId=' + id + '&qty=' + qty + '&ebayqty=' + ebayqty + '&variants=' + variants,
    291           type: 'post',
    292           dataType: 'json',
    293           beforeSend: function() {
    294             $('#l-' + id + '-save-button').html('<i class="fa fa-cog fa-lg fa-spin"></i>');
    295           },
    296           success: function(json) {
    297             $('#row' + id).fadeOut('slow');
    298             $('#l-' + id + '-save-button').hide();
    299           },
    300           error: function (xhr, ajaxOptions, thrownError) {
    301             if (xhr.status != 0) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }
    302           }
    303       });
    304   }
    305 
    306   function getProductStock(id, element_id) {
    307       $.ajax({
    308           type:'GET',
    309           dataType: 'json',
    310           url: 'index.php?route=extension/openbay/ebay/getProductStock&user_token={{ user_token }}&pid=' + id,
    311           success: function(data) {
    312               if (data.variant == 0) {
    313                   $('#' + element_id + '-qty').text(data.qty);
    314                   $('#' + element_id + '-qty-input').val(data.qty);
    315                   $('#' + element_id + '-allocated').text(data.allocated);
    316                   $('#' + element_id + '-allocatedinput').val(data.allocated);
    317                   $('#' + element_id + '-subtractinput').val(data.subtract);
    318                   $('#' + element_id + '-save-button').show();
    319               } else {
    320                   var html_inj = '';
    321                   $.each (data.variant, function(key, val) {
    322                     html_inj += val.stock + ' x ' + val.combination + '<br />';
    323                   });
    324                   $('#' + element_id + '-qty').html(html_inj);
    325                   $('#' + element_id + '-save-button').show();
    326               }
    327           }
    328       });
    329   }
    330 
    331   $('#check-unlinked-items').bind('click', function() {
    332     var unlinked_page = $('#unlinked-page').val();
    333 
    334     $.ajax({
    335       url: 'index.php?route=extension/openbay/ebay/loadUnlinked&user_token={{ user_token }}&page=' + unlinked_page,
    336       type: 'POST',
    337       data: { 'filter_title' : $('#filter_title').val(), 'filter_qty_min' : $('#filter-qty-min').val(), 'filter_qty_max' : $('#filter-qty-max').val(), 'filter_variant' : $('#filter-variant').val() },
    338       dataType: 'json',
    339       beforeSend: function() {
    340         $('#fetching-ebay-items').hide();
    341         $('#check-unlinked-items').empty().html('<i class="fa fa-cog fa-lg fa-spin"></i>').attr('disabled','disabled');
    342         $('.alert-warning').remove();
    343       },
    344       success: function(json) {
    345         if (json.data.items === null) {
    346           $('#ebay-listings').append('<tr><td colspan="7"><p>{{ error_no_listings }}</p></td></tr>');
    347         } else {
    348           var html_inj;
    349 
    350           $.each (json.data.items, function(key, val) {
    351             html_inj = '';
    352             html_inj += '<tr class="listing" id="row' + key + '">';
    353             html_inj += '<td class="text-center">';
    354             if (val.img != '') {
    355               html_inj += '<img src="' + val.img + '" />';
    356             }
    357             html_inj += '</td>';
    358             html_inj += '<td class="text-left">' + key + '<input type="hidden" id="l-' + key + '_val" val="' + key + '" /></td>';
    359             html_inj += '<td class="text-left">' + val.name + '</td>';
    360             html_inj += '<td class="text-left"><input type="text" class="product-search form-control" placeholder="{{ column_product_auto }}" id="l-' + key + '" /><input type="hidden" id="l-' + key + '-pid" /></td>';
    361 
    362             if (val.variants == 0) {
    363                 html_inj += '<td class="text-center"><span id="l-' + key + '-qty"></span><input type="hidden" id="l-' + key + '-qtyinput" /></td>';
    364                 html_inj += '<td class="text-center"><span id="l-' + key + '-allocated"></span><input type="hidden" id="l-' + key + '-allocatedinput" /><input type="hidden" id="l-' + key + '-subtractinput" /></td>';
    365                 html_inj += '<td class="text-center"><span id="l-' + key + '-qtyebay">' + val.qty + '</span><input type="hidden" id="l-' + key + '-qtyebayinput" value="' + val.qty + '" /></td>';
    366                 html_inj += '<input type="hidden" name="variants" id="l-' + key + '-variants" value="0" />';
    367                 html_inj += '<td class="text-center"><span class="label label-danger">{{ text_no }}</span></td>';
    368             } else {
    369                 html_inj += '<td class="text-center"><span id="l-' + key + '-qty"></span></td>';
    370                 html_inj += '<td class="text-center">-</td>';
    371                 html_inj += '<td class="text-center">';
    372                 $.each (val.variants, function(key1, val1) {
    373                     html_inj += val1.qty + ' x ';
    374                     $.each (val1.nv.NameValueList, function(key2, val2) {
    375                         html_inj += val2.Value + ' > ';
    376                     });
    377                     html_inj += '<br />';
    378                 });
    379                 html_inj += '</td>';
    380                 html_inj += '<input type="hidden" name="variants" id="l-' + key + '-variants" value="1" />';
    381                 html_inj += '<td class="text-center"><span class="label label-success">{{ text_yes }}</span></td>';
    382             }
    383             html_inj += '<td class="text-center"><a class="btn btn-primary" style="display:none;" onclick="saveListingLink(' + key + '); return false;" id="l-' + key + '-save-button"><span>{{ button_save }}</span></a></td>';
    384             html_inj += '</tr>';
    385 
    386             $('#ebay-listings').append(html_inj);
    387           });
    388         }
    389 
    390         $('#ebay-listings').show();
    391 
    392         if (json.data.more_pages == 1) {
    393           $('#check-unlinked-items').empty().html('{{ button_check_unlinked }}').removeAttr('disabled');
    394         } else {
    395           $('#check-unlinked-items').hide();
    396         }
    397 
    398         if (json.data.break == 1) {
    399           $('#check-unlinked-items').before('<div class="alert alert-warning">{{ text_limit_reached }}</div>');
    400         }
    401 
    402         $('#unlinked-page').val(json.data.next_page);
    403       },
    404       error: function (xhr, ajaxOptions, thrownError) {
    405         $('#check-unlinked-items').empty().removeClass('btn-primary').addClass('btn-danger').html('{{ text_failed }}').removeAttr('disabled');
    406         if (xhr.status != 0) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }
    407       }
    408     });
    409   });
    410 
    411   $(document).on('keydown', '.product-search', function() {
    412     var element_id = $(this).attr('id');
    413 
    414     $(this).autocomplete({
    415       source: function(request, response) {
    416         $.ajax({
    417           url: 'index.php?route=catalog/product/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
    418           dataType: 'json',
    419           success: function(json) {
    420             response($.map(json, function(item) {
    421               return {
    422                 label: item['name'],
    423                 value: item['product_id']
    424               }
    425             }));
    426           }
    427         });
    428       },
    429       select: function(item) {
    430         $('#' + element_id).val(item['label']);
    431         getProductStock(item['value'], element_id);
    432         $('#' + element_id + '-pid').val(item['value']);
    433         return false;
    434       }
    435     });
    436   });
    437 
    438   $(document).ready(function() {
    439       checkLinkedItems();
    440   });
    441 //--></script>
    442 {{ footer }}