Muy Buenas I have an inconvenience when trying to go through the local storage to assign classes and styles to elements in the DOM. The case is that an ajax request is sent that returns a load to the local storage I used setTimeout to wait for the localstorage to load, but in local it works without problems but already the thing is a little more delayed in test server, I want to know if it exists a js method that is activated or something similar to know if I can already consult the localstorage. this is what I do to consult it.
function addToCartProductInd(sku) {
if (JSON.parse(localStorage.getItem('mage-cache-storage')) != null) {
var Lstorage = JSON.parse(localStorage.getItem('mage-cache-storage'));
if (Lstorage.cart && Lstorage.cart.items != null) {
var Prod_Larecetta = Lstorage.cart.items;
$.each( Prod_Larecetta, function( key, value ) {
if(value.product_sku == sku){
$("#remove-itm-in-cart-"+sku).attr('data-item-to-remove',value.item_id);
$("#input-number-"+sku).val(value.qty).attr('data-item_id',value.item_id);
}
});
}
}
}