Opencart 3 Система доставки Omniva JS ошибка - листовка. js: 5 Uncaught TypeError: Невозможно прочитать свойство 'addLayer' из null - PullRequest
0 голосов
/ 02 мая 2020

Я установил систему доставки Omniva для Opencart 3.0.3.2. На странице проверки по умолчанию все, кажется, работает хорошо, но когда я попытался использовать его с одной страницей проверки, она не работает правильно - при щелчке переключателя, выберите область показывает и сразу скрыть. В инструментах разработчика появилась ошибка

leaflet.js:5 Uncaught TypeError: Cannot read property 'addLayer' of null
at e.addTo (leaflet.js:5)
at initMap (omniva-map.min.js:1)
at n.fn.init.$.fn.omniva (omniva-map.min.js:1)
at HTMLInputElement.<anonymous> (index.php?route=checkout/uni_checkout:967)
at HTMLDocument.dispatch (jquery-2.1.1.min.js:3)
at HTMLDocument.r.handle (jquery-2.1.1.min.js:3)

Это мои темы shipping.twig

<div class="heading"><span>{{text_delivery_methods}}</span></div>
    <div class="shipping-method">
    {% if error_warning %}
      <div class="alert alert-warning"><i class="fa fa-exclamation-circle"></i> 
{{error_warning}}</div>
{% endif %}
{% if shipping_methods %}
    {% for shipping_method in shipping_methods %}
    {{shipping_method.title}} 
        {% if not shipping_method.error %}
            {% for quote in shipping_method.quote %}
                <div class="radio">
                    <label class="input">
                        {% if quote.code == code or not code %}
                            {% set code = quote.code %}
                            <input type="radio" name="shipping_method" value="{{quote.code}}" id="{{quote.code}}" checked="checked" />
                        {% else %}
                            <input type="radio" name="shipping_method" value="{{quote.code}}" id="{{quote.code}}" />
                        {% endif %}
                        <span></span>
                        <span class="methods"><span class="method">{{quote.title}}:</span><span class="method">{{quote.text}}</span></span>
                    </label>
                    {% if quote.description is not empty %}{{quote.description}}{% endif %}
                </div>
            {% endfor %}
        {% else %}
            <div class="alert alert-danger">{{shipping_method.error}}</div>
        {% endif %}
    {% endfor %}
{% endif %}

И вот здесь я сделал модификацию для этой ветки

<file path="catalog/view/theme/unishop2/template/checkout/uni_shipping.twig" error="log">
<operation>
    <search><![CDATA[{% for shipping_method in shipping_methods %}]]></search>
    <add position="replace"><![CDATA[{% for method_key, shipping_method in shipping_methods %}]]></add>
</operation>
<operation>
    <search><![CDATA[{{shipping_method.title}}]]></search>
    <add position="after"><![CDATA[
    {% if method_key == "omnivalt" %}
    <script>
    var omniva_current_country = '{{omniva_country}}';
    var omnivaTerminals = {{ omniva_terminals|json_encode() }};
    </script>
    <script>
    $(document).ready(function () {
  var omnivaModuleReady = false;
  $(document).on('click', 'input[type="radio"][name="shipping_method"]', function (e) {
    if ($(this).val() === 'fake.parcel_terminal' && !omnivaModuleReady) {
        omnivaModuleReady = $(this).omniva({
            terminals: omnivaTerminals,
            country_code: omniva_current_country,

            callback: function (id) {
              omnivaModuleReady.val('omnivalt.parcel_terminal_' + id);
            },
            translate: omniva_map_translation
        });
        omnivaModuleReady.trigger('omniva.show');

        // with default template this should be enough even if user changes postcode (as he needs to press continue button)
        var sameShipping = $('input[name="shipping_address"]');
        if (sameShipping.length > 0 && sameShipping.is(':checked')) {
            omnivaModuleReady.trigger('omniva.postcode', [$('#input-payment-postcode').val()]);
        } else {
            omnivaModuleReady.trigger('omniva.postcode', [$('#input-shipping-postcode').val()]);
        }
    } else {
        if (omnivaModuleReady) {
          if ($(this).is(omnivaModuleReady)) {
              omnivaModuleReady.trigger('omniva.show');
          } else {
              omnivaModuleReady.trigger('omniva.hide');
          }
        }
    }
  });
});
</script>
{% endif %}
    ]]></add>
</operation>
<operation>
    <search><![CDATA[{% for quote in shipping_method.quote %}]]></search>
    <add position="replace"><![CDATA[
    {% for quote in shipping_method.quote if not (quote.code starts with 'omnivalt.parcel') %}
    ]]></add>
</operation>

Если есть необходимость в других частях кода, пожалуйста, спросите!

...