Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:35:42+00:00 2026-06-11T07:35:42+00:00

I’m using simplecartjs to power an online store. It stores it’s data in local

  • 0

I’m using simplecartjs to power an online store. It stores it’s data in local storage, which looks like this:

{"SCI-1":{"quantity":1,"id":"SCI-1","price":20,"name":"Mattamusta -teippi","size":"Tyhjä"},"SCI-3":{"quantity":1,"id":"SCI-3","price":19,"name":"Mohawk .vaimennusmatto 48 x 39cm"},"SCI-5":{"quantity":2,"id":"SCI-5","price":8,"name":"Car Speaker -hajuste","color":"Green Tea"},"SCI-7":{"quantity":1,"id":"SCI-7","price":50,"name":"Asennuspaketti"},"SCI-9":{"quantity":1,"id":"SCI-9","price":30,"name":"Quartz-kalvot","color":"Yellow","size":"50cm x 30cm"},"SCI-11":{"quantity":1,"id":"SCI-11","price":30,"name":"Quartz-kalvot","color":"True Blue","size":"50cm x 30cm"}}

And I want to add this line before it’s closed.

"SCI-12":{"quantity":1,"id":"SCI-12","price":5,"name":"Toimituskulut"}

However, the amount of products will depend on user, and so on SCI-12 must grow with the number of items.

EDIT Actually, it doens’t have to use SCI-1, it can be anything, as long as it’s after the items.

EDIT2
Here’s what I’m trying… But without luck.

$("#matkahuolto").click(function(){
    var value_object = '"Toimituskulut":{"quantity":1,"id":"Toimituskulut","price":5,"name":"Toimituskulut"}';
    var json_object = JSON.parse(localStorage.your_json); // convert string to object

    json_object["simpleCart_items"] = value_object; // add value

    localStorage.your_json = JSON.stringify(json_object);  // store it again.

    });

    $("#posti").click(function(){
    var json_object = JSON.parse(localStorage.your_json); // convert string to object

    json_object["simpleCart_items"] = value_object; // add value

    localStorage.your_json = JSON.stringify(json_object);  // store it again.

    });

EDIT3 A screenshot of localstorage.
LocalStorage

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:35:43+00:00Added an answer on June 11, 2026 at 7:35 am

    The first thing you need to understand is how items are stored in localStorage, which is basically like a hashmap/dictionary in that the items are stored in key value pairs.

    For example to store a string localStorage you would do something like

    localStorage["myKey"] = "some value";
    

    To retrieve the value you would just to the reverse

    var myValue = localStorage["myKey"];
    

    The next thing to realize is that you can in fact only store strings in localStorage, so if you want to store a object you need to first convert it to a string representation. This is usually done by converting the object to JSON which is a compact notation used to represent an object as a string. To convert an object to JSON you just use the JSON.stringify method, and to parse an item you use the JSON.parse method

    For example to convert an object to JSON

    var someObject = {id: 1, name: 'Test'};
    
    var jsonSomeObject = JSON.stringify(someObject); 
    // jsonSomeObject looks like "{"id":1,"name":"test"}"
    

    And to read an object from JSON

    someObject = JSON.parse(jsonSomeObject);
    

    So now in your case assuming that your object contains the appropriate data all you need to do is stringify your object and add it to localStorage using some key,

    var jsonData = JSON.stringify({"SCI-12":{"quantity":1,"id":"SCI-12","price":5,"name":"Toimituskulut"}});
    
    localStorage["aKey"] = jsonData;
    

    and when you want to access this data later (presumably after coming back to the page)

    var mySCI = JSON.parse(localStorage["aKey"])
    

    If you are trying to update a specific entry in localStorage then you would just read it in and then overwrite it, for example

    var mySCI = JSON.parse(localStorage["aKey"]);
    mySCI.SCI-12.quantity = 2;
    localStorage["aKey"] = JSON.stringify(mySCI);
    

    Keep in mind that while most browsers have built in support for JSON some older ones don’t, if this is an issue you can include Douglass Crockfords JSON-js script to provide support.

    Edit:

    Based on the screenshot you just posted, you can see that the key under which the values are stored in localStorage is in fact simpleCart_items (and not your_json which are using in your code), and that the object that is being stored has a object stored under the key “SCI-1) (and probably others under “SCI’s”). So what you would need to do is something like the following

     $("#matkahuolto").click(function(){
        var value_object = {quantity: 1, id: 1, name: "someName"} ; 
        var jsonObject = JSON.parse(localStorage["simpleCart_items"]);
        json_object["SCI_1"] = value_object; // add value
    
     localStorage["simpleCart_items"] = JSON.stringify(json_object);  // store it again.
    
    });
    
    $("#posti").click(function(){
     // convert string to object
     var json_object = JSON.parse(localStorage["simpleCart_items"]); 
    
    json_object["SCI-1"] = value_object; // add value
    
     localStorage["simpleCart_items"] = JSON.stringify(json_object);  // store it again.
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.