{"id":19241083,"url":"https://github.com/binocarlos/cornershop","last_synced_at":"2025-09-08T05:33:18.920Z","repository":{"id":13745763,"uuid":"16440180","full_name":"binocarlos/cornershop","owner":"binocarlos","description":"Shopping cart that saves to LocalStorage.","archived":false,"fork":false,"pushed_at":"2016-02-06T19:16:12.000Z","size":13,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-30T02:01:52.046Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binocarlos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-01T18:53:21.000Z","updated_at":"2021-10-25T01:33:52.000Z","dependencies_parsed_at":"2022-09-26T19:42:52.068Z","dependency_job_id":null,"html_url":"https://github.com/binocarlos/cornershop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fcornershop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fcornershop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fcornershop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binocarlos%2Fcornershop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binocarlos","download_url":"https://codeload.github.com/binocarlos/cornershop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232282891,"owners_count":18499330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T17:10:11.446Z","updated_at":"2025-01-03T03:06:03.347Z","avatar_url":"https://github.com/binocarlos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"cornershop\n==========\n\nShopping cart that saves to LocalStorage.\n\n## installation\n\nnpm/browserify:\n\n```bash\n$ npm install cornershop\n```\n\ncomponent:\n\n```bash\n$ component install binocarlos/cornershop\n```\n\n## usage\n\n\n### cart access\n\nEach cart has a name - this is used for the localstorage variable name and so you can have as many carts as you want.\n\n```js\nvar shop = require('cornershop');\nvar cart = shop('mystoreid');\n```\n\n### load()\n\nTo load the cart from localstorage either pass true as the second argument:\n\n```js\nvar shop = require('cornershop');\nvar cart = shop('mystoreid', true);\n```\n\nor call the .load method manually:\n\n```js\nvar shop = require('cornershop');\nvar cart = shop('mystoreid');\ncart.load();\n```\n\n### save()\n\nTo save the cart to localstorage call the .save() method:\n\n```js\nvar shop = require('cornershop');\nvar cart = shop('mystoreid');\ncart.load();\n\n// do stuff\n\ncart.save();\n```\n\n### items\n\nThe cart works on a list of items.  An item is a plain JavaScript object with these properties:\n\n * id \t\t(10)\n * name \t(Superman Poster)\n * price\t(12.5)\n * qty\t\t(2)\n\nYou can add any meta-data to an item that you want, for example a description and image:\n\n * desc\t\t(10x5 - superman logo bottom-right) \n * image\t(/img/shop/superman.png)\n\nAccess the items in the cart:\n\n```js\n// an array of items\nvar items = cart.items;\n\nvar item = items[0];\nconsole.log(item);\n\n/*\n{\n\tid:10,\n\tname:'Superman Poster',\n\tdesc:'10x5 - superman logo bottom-right',\n\tprice:12.5,\n\tqty:2,\n\timage:'/img/shop/superman.png'\n}\n*/\n```\n\n### addItem({...})\n\nTo add a new item to the cart:\n\n```js\ncart.addItem({\n\tid:10,\n\tname:'Superman Poster',\n\tdesc:'10x5 - superman logo bottom-right',\n\tprice:12.5,\n\tqty:2,\n\timage:'/img/shop/superman.png'\n})\n```\n\n### getItem(id)\n\nTo edit an item you fetch it by id and change properties of the item object and then save the cart.\n\n```js\nvar item = cart.getItem(10);\nitem.qty++;\ncart.save();\n```\n\n### removeItem(id)\n\nRemove an item with an id - this auto-saves:\n\n```js\ncart.removeItem(10);\n```\n\n### getTotal(withExtras)\n\nThe cart will return the current total - this is based on item.price * item.qty:\n\n```js\nvar total = cart.getTotal();\n```\n\n```js\nvar totalwithshipping = cart.getTotal(true);\n```\n\n## extras\n\nThis accounts for extra things like shipping and any other things that are not products but have a charge associated.\n\n### setExtra(field, {...})\n\nAdd an extra item to the cart - like shipping.\n\nEach extra item should have a 'name', 'price' and 'qty' field like the products.\n\n```js\ncart.setExtra('shipping', {\n\tname:'Shipping UK - 5 day',\n\tprice:12\n})\n```\n\n### removeExtra(field)\n\nRemove an extra field\n\n```js\ncart.removeExtra('shipping');\n```\n\n### getExtras()\n\nReturn an array of the extra settings in the cart:\n\n```js\nvar extra_array = cart.getExtras();\n```\n\n### getExtraTotal()\n\nReturn the sub-total just for the extra items\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinocarlos%2Fcornershop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinocarlos%2Fcornershop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinocarlos%2Fcornershop/lists"}