0

Enviroment: I am using isml for view (demandware templating), browser is chrome.

What I am trying is to store the shopping store ID:

function cacheStores(data) {
        cachedStores = {};
        for (var i = data.length - 1; i >= 0; i--) {
            var store = data[i];
            console.log(store);
            cachedStores[store.physicalId] = store;

        }

It works when I am on the page, but when I leave the page (to next page) and try to go back to it, the value is empty.

ISML:

<input type="hidden" name="dwfrm_billing_shippingAddress_addressFields_houseNumber" value=>

That is the function setting name and value

    function setShippingField(name, value) {
        jQuery('input[name=' + name + ']', addressContainer).val(value);
    }
    //only set if housenumber is a field
    if ($houseNumber.length) {
        var matches = shippingAddress1.match(/\d+/);
        if (matches) {
            shippingHouseNum = matches[0];
            shippingAddress1 = shippingAddress1.replace(shippingHouseNum, '');
            setShippingField(checkout.initFields.s_houseNumber, shippingHouseNum);
        }
    }
        // set hidden fields
        setShippingField(checkout.initFields.s_title,     billingTitle);
        setShippingField(checkout.initFields.s_lastName,  shippingLastName);
        setShippingField(checkout.initFields.s_firstName, shippingFirstName);
        setShippingField(checkout.initFields.s_address1,  shippingAddress1.substr(0, MAX_ADDRESS1_LEN));
        setShippingField(checkout.initFields.s_address2,  shippingAddress2);
        setShippingField(checkout.initFields.s_address3,  store.physicalId);
        setShippingField(checkout.initFields.s_zip,       store.address.postalCode);
        setShippingField(checkout.initFields.s_city,      shippingCity);
        setShippingField(checkout.initFields.s_country,   billingCountry);

        // set visible labels
        jQuery('#customer', addressContainer).text(billingTitle + " " + shippingAddress2);
        jQuery('#shopname', addressContainer).text(shippingLastName + ' ' + shippingFirstName);
        jQuery('#shopstreet', addressContainer).text(shippingAddress1 + ' ' + shippingHouseNum); // includes house number
        jQuery('#shopid', addressContainer).text(store.physicalId); // we're not using shop ids here
        jQuery('#shopzipcity', addressContainer).text(store.address.postalCode + ' ' + shippingCity);


        window.top.close();
    }
Haris Khan
  • 171
  • 1
  • 2
  • 10
  • 2
    The lifetime of any variable in JavaScript is only as long as the page. If you need longer, you'd need to use localStorage, sessionStorage, cookies or a server-side data store. – Rory McCrossan Sep 25 '15 at 12:06
  • store.physicalId is the only var that is missing the value, while rest of them still have it. – Haris Khan Sep 25 '15 at 12:17

1 Answers1

0

It looks like client-side issue, the one you are having. I do not think it relates to the server-side logic you are using.

setShippingField(checkout.initFields.s_address3,  store.physicalId);

Should not this be with something different than s_address3 field as key?

From your code snippet it is not clear what exactly you have in the checkout variable and in its initFields member. Also what exactly you pass to cacheStores function's data parameter.

On a side note, it is bad practice to use same identifier for different things in different scopes (cacheStores in one scope is function, and in another scope is object.)

Zlatin Zlatev
  • 3,034
  • 1
  • 24
  • 32