Operation if one value is potentially empty

I’m trying to add together two values which then save to a session storage variable. There is a potential that one of the values is empty. If both values are not null, this works fine with the expected outcome e.g. value1 (1) + value2 (1) saves to the variable as 2. If value1(1) + value2 (empty) the variable isn’t populated.

Is there a way to define ‘not empty’ in data formatting?

Thanks

Might it be possible just to set a default to an empty value, assuming a string ‘’ or a number 0 using the General -> Default option in the formatter

2 Likes

Thanks @Hyperbytes. How would I then go about binding that value to the session variable.

Thanks

Core Actions => Set Session and bind it to the variable(s), all can be done through the formatter BUT don’t forget to define the session in the Globals also.

image

Best is not to concatenate the values before entering their values to a Session Storage, use a Keyed Array instead (key=>value). If the value is empty, the value for that key will also be empty. For more detail, see wCart Tutorial part 5. Add Session and Arrays to the Template. To set the values for the Keyed Array, see wCart Tutorial part 7. Apply Add to Cart Functionality

Rather than starting on your own, why not work through the whole tutorial, that way you will get an understanding of how easy it is without overthinking.

2 Likes

Thanks @Hyperbytes and @ben for your help