{"id":21901193,"url":"https://github.com/moltin/cart","last_synced_at":"2025-04-06T07:15:37.138Z","repository":{"id":8017605,"uuid":"9426403","full_name":"moltin/cart","owner":"moltin","description":"Shopping cart composer package","archived":false,"fork":false,"pushed_at":"2017-06-11T22:01:13.000Z","size":138,"stargazers_count":109,"open_issues_count":12,"forks_count":62,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-03-30T06:09:38.899Z","etag":null,"topics":["api","cart","moltin","shopping-cart"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moltin.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":"2013-04-14T08:24:52.000Z","updated_at":"2025-01-29T19:31:44.000Z","dependencies_parsed_at":"2022-09-11T03:40:18.499Z","dependency_job_id":null,"html_url":"https://github.com/moltin/cart","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moltin%2Fcart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moltin%2Fcart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moltin%2Fcart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moltin%2Fcart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moltin","download_url":"https://codeload.github.com/moltin/cart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445682,"owners_count":20939961,"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":["api","cart","moltin","shopping-cart"],"created_at":"2024-11-28T15:12:40.961Z","updated_at":"2025-04-06T07:15:37.120Z","avatar_url":"https://github.com/moltin.png","language":"PHP","readme":"# Shopping Cart Package\n\n[![Build Status](https://secure.travis-ci.org/moltin/cart.png)](http://travis-ci.org/moltin/cart)\n\n* [Website](http://molt.in)\n* [License](https://github.com/moltin/cart/master/LICENSE)\n* Version: dev\n\nThe Moltin shopping cart composer package makes it easy to implement a shopping basket into your application and\nstore the cart data using one of the numerous data stores provided. You can also inject your own data store if you\nwould like your cart data to be stored elsewhere.\n\n## Installation\nDownload and install composer from `http://www.getcomposer.org/download`\n\nAdd the following to your project `composer.json` file\n```\n{\n    \"require\": {\n        \"moltin/cart\": \"dev-master\"\n    }\n}\n```\nWhen you're done just run `php composer.phar install` and the package is ready to be used.\n\n## Usage\nBelow is a basic usage guide for this package.\n\n### Instantiating the cart\nBefore you begin, you will need to know which storage and identifier method you are going to use. The identifier is\nhow you store which cart is for that user. So if you store your cart in the database, then you need a cookie (or some\nother way of storing an identifier) so we can link the user to a stored cart.\n\nIn this example we're going to use the cookie identifier and session for storage.\n\n```php\nuse Moltin\\Cart\\Cart;\nuse Moltin\\Cart\\Storage\\Session;\nuse Moltin\\Cart\\Identifier\\Cookie;\n\n$cart = new Cart(new Session, new Cookie);\n```\n\n### Inserting items into the cart\nInserting an item into the cart is easy. The required keys are id, name, price and quantity, although you can pass\nover any custom data that you like.\n```php\n$cart-\u003einsert(array(\n    'id'       =\u003e 'foo',\n    'name'     =\u003e 'bar',\n    'price'    =\u003e 100,\n    'quantity' =\u003e 1\n));\n```\n\n### Setting the tax rate for an item\nAnother key you can pass to your insert method is 'tax'. This is a percentage which you would like to be added onto\nthe price of the item.\n\nIn the below example we will use 20% for the tax rate.\n\n```php\n$cart-\u003einsert(array(\n    'id'       =\u003e 'foo',\n    'name'     =\u003e 'bar',\n    'price'    =\u003e 100,\n    'quantity' =\u003e 1,\n    'tax'      =\u003e 20\n));\n```\n\n### Updating items in the cart\nYou can update items in your cart by updating any property on a cart item. For example, if you were within a\ncart loop then you can update a specific item using the below example.\n```php\nforeach ($cart-\u003econtents() as $item) {\n    $item-\u003ename = 'Foo';\n    $item-\u003equantity = 1;\n}\n```\n\n### Removing cart items\nYou can remove any items in your cart by using the ```remove()``` method on any cart item.\n```php\nforeach ($cart-\u003econtents() as $item) {\n    $item-\u003eremove();\n}\n```\n\n### Destroying/emptying the cart\nYou can completely empty/destroy the cart by using the ```destroy()``` method.\n```php\n$cart-\u003edestroy()\n```\n\n### Retrieve the cart contents\nYou can loop the cart contents by using the following method\n```php\n$cart-\u003econtents();\n```\n\nYou can also return the cart items as an array by passing true as the first argument\n```php\n$cart-\u003econtents(true);\n```\n\n### Retrieving the total items in the cart\n```php\n$cart-\u003etotalItems();\n```\n\nBy default this method will return all items in the cart as well as their quantities. You can pass ```true```\nas the first argument to get all unique items.\n```php\n$cart-\u003etotalItems(true);\n```\n\n### Retrieving the cart total\n```php\n$cart-\u003etotal();\n```\n\nBy default the ```total()``` method will return the total value of the cart as a ```float```, this will include\nany item taxes. If you want to retrieve the cart total without tax then you can do so by passing false to the\n```total()``` method\n```php\n$cart-\u003etotal(false);\n```\n\n### Check if the cart has an item\n```php\n$cart-\u003ehas($itemIdentifier);\n```\n\n### Retreive an item object by identifier\n```php\n$cart-\u003eitem($itemIdentifier);\n```\n\n## Cart items\nThere are several features of the cart items that may also help when integrating your cart.\n\n### Retrieving the total value of an item\nYou can retrieve the total value of a specific cart item (including quantities) using the following method.\n```php\n$item-\u003etotal();\n```\n\nBy default, this method will return the total value of the item plus tax. So if you had a product which costs 100,\nwith a quantity of 2 and a tax rate of 20% then the total returned by this method would be 240.\n\nYou can also get the total minus tax by passing false to the ```total()``` method.\n```php\n$item-\u003etotal(false);\n```\n\nThis would return 200.\n\n### Check if an item has options\nYou can check if a cart item has options by using the ```hasOptions()``` method.\n\n```php\nif ($item-\u003ehasOptions()) {\n    // We have options\n}\n```\n\n### Remove an item from the cart\n```php\n$item-\u003eremove();\n```\n\n### Output the item data as an array\n```php\n$item-\u003etoArray();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoltin%2Fcart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoltin%2Fcart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoltin%2Fcart/lists"}