Jump to content

Edit History

jla290

jla290


error

12 hours ago, aixos said:

1. No has de copiar el contenido ps_shoppingcart.js

2. Pegarlo al final de siguiente archivo: themes/mitema/assets/js/custom.js

Este estaría adaptado para prestashop 8.1.7

document.addEventListener('DOMContentLoaded', function () {
  prestashop.blockcart = prestashop.blockcart || {};

  var showModal = prestashop.blockcart.showModal || function (modal) {
    document.body.insertAdjacentHTML('beforeend', modal);
    document.getElementById('blockcart-modal').addEventListener('click', function (event) {
      if (event.target.id === 'blockcart-modal') {
        event.target.remove();
      }
    });
  };

  prestashop.on('updateCart', function (event) {
    var blockcart = document.querySelector('.blockcart');
    var refreshURL = blockcart ? blockcart.dataset.refreshUrl : '';
    var requestData = {};

    if (event && event.reason) {
      requestData = {
        id_product_attribute: event.reason.idProductAttribute,
        id_product: event.reason.idProduct,
        action: event.reason.linkAction
      };
    }

    fetch(refreshURL, {
      method: 'POST',
      body: JSON.stringify(requestData),
      headers: {
        'Content-Type': 'application/json'
      }
    })
    .then(response => response.json())
    .then(function (resp) {
      if (blockcart) {
        blockcart.innerHTML = new DOMParser().parseFromString(resp.preview, 'text/html').querySelector('.blockcart').innerHTML;
      }
      if (resp.modal) {
        showModal(resp.modal);
      }
    })
    .catch(function (resp) {
      prestashop.emit('handleError', { eventType: 'updateShoppingCart', resp: resp });
    });
  });
});

3.Borrar caché desde parámetros avanzados / rendimiento

4. Borrar cookies del navegador

Hola, @aixos

Mi web corre con Prestashop 1.7.8.11 y el archivo ps_shoppingcart.js tiene el siguiente código que he copiado y pegado en el custom.js del tema, pero no funciona:

$(document).ready(function () {
  prestashop.blockcart = prestashop.blockcart || {};

  var showModal = prestashop.blockcart.showModal || function (modal) {
    var $body = $('body');
    $body.append(modal);
    $body.one('click', '#blockcart-modal', function (event) {
      if (event.target.id === 'blockcart-modal') {
        $(event.target).remove();
      }
    });
  };

  prestashop.on(
    'updateCart',
    function (event) {
      var refreshURL = $('.blockcart').data('refresh-url');
      var requestData = {};
      if (event && event.reason && typeof event.resp !== 'undefined' && !event.resp.hasError) {
        requestData = {
          id_customization: event.reason.idCustomization,
          id_product_attribute: event.reason.idProductAttribute,
          id_product: event.reason.idProduct,
          action: event.reason.linkAction
        };
      }
      if (event && event.resp && event.resp.hasError) {
        prestashop.emit('showErrorNextToAddtoCartButton', { errorMessage: event.resp.errors.join('<br/>')});
      }
      $.post(refreshURL, requestData).then(function (resp) {
        var html = $('<div />').append($.parseHTML(resp.preview));
        $('.blockcart').replaceWith($(resp.preview).find('.blockcart'));
        if (resp.modal) {
          showModal(resp.modal);
        }
      }).fail(function (resp) {
        prestashop.emit('handleError', { eventType: 'updateShoppingCart', resp: resp });
      });
    }
  );
});

 

jla290

jla290

2 hours ago, aixos said:

1. No has de copiar el contenido ps_shoppingcart.js

2. Pegarlo al final de siguiente archivo: themes/mitema/assets/js/custom.js

Este estaría adaptado para prestashop 8.1.7

document.addEventListener('DOMContentLoaded', function () {
  prestashop.blockcart = prestashop.blockcart || {};

  var showModal = prestashop.blockcart.showModal || function (modal) {
    document.body.insertAdjacentHTML('beforeend', modal);
    document.getElementById('blockcart-modal').addEventListener('click', function (event) {
      if (event.target.id === 'blockcart-modal') {
        event.target.remove();
      }
    });
  };

  prestashop.on('updateCart', function (event) {
    var blockcart = document.querySelector('.blockcart');
    var refreshURL = blockcart ? blockcart.dataset.refreshUrl : '';
    var requestData = {};

    if (event && event.reason) {
      requestData = {
        id_product_attribute: event.reason.idProductAttribute,
        id_product: event.reason.idProduct,
        action: event.reason.linkAction
      };
    }

    fetch(refreshURL, {
      method: 'POST',
      body: JSON.stringify(requestData),
      headers: {
        'Content-Type': 'application/json'
      }
    })
    .then(response => response.json())
    .then(function (resp) {
      if (blockcart) {
        blockcart.innerHTML = new DOMParser().parseFromString(resp.preview, 'text/html').querySelector('.blockcart').innerHTML;
      }
      if (resp.modal) {
        showModal(resp.modal);
      }
    })
    .catch(function (resp) {
      prestashop.emit('handleError', { eventType: 'updateShoppingCart', resp: resp });
    });
  });
});

3.Borrar caché desde parámetros avanzados / rendimiento

4. Borrar cookies del navegador

Hola, @aixos

Mi web coore con Prestashop 1.7.8.11 y el archivo ps_shoppingcart.js tiene el siguiente código que he copiado y pegado en el custom.js del tema, pero no funciona:

$(document).ready(function () {
  prestashop.blockcart = prestashop.blockcart || {};

  var showModal = prestashop.blockcart.showModal || function (modal) {
    var $body = $('body');
    $body.append(modal);
    $body.one('click', '#blockcart-modal', function (event) {
      if (event.target.id === 'blockcart-modal') {
        $(event.target).remove();
      }
    });
  };

  prestashop.on(
    'updateCart',
    function (event) {
      var refreshURL = $('.blockcart').data('refresh-url');
      var requestData = {};
      if (event && event.reason && typeof event.resp !== 'undefined' && !event.resp.hasError) {
        requestData = {
          id_customization: event.reason.idCustomization,
          id_product_attribute: event.reason.idProductAttribute,
          id_product: event.reason.idProduct,
          action: event.reason.linkAction
        };
      }
      if (event && event.resp && event.resp.hasError) {
        prestashop.emit('showErrorNextToAddtoCartButton', { errorMessage: event.resp.errors.join('<br/>')});
      }
      $.post(refreshURL, requestData).then(function (resp) {
        var html = $('<div />').append($.parseHTML(resp.preview));
        $('.blockcart').replaceWith($(resp.preview).find('.blockcart'));
        if (resp.modal) {
          showModal(resp.modal);
        }
      }).fail(function (resp) {
        prestashop.emit('handleError', { eventType: 'updateShoppingCart', resp: resp });
      });
    }
  );
});

 

×
×
  • Create New...