{"id":29906063,"url":"https://github.com/mazesec/cart","last_synced_at":"2025-08-01T20:09:28.447Z","repository":{"id":57064727,"uuid":"426621800","full_name":"mazesec/Cart","owner":"mazesec","description":"A simple PHP shopping cart library to use in ecommerce web applications","archived":false,"fork":false,"pushed_at":"2021-11-20T23:45:18.000Z","size":29,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-01T05:20:36.150Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","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/mazesec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-10T12:54:52.000Z","updated_at":"2025-04-14T18:40:57.000Z","dependencies_parsed_at":"2022-08-24T04:40:06.983Z","dependency_job_id":null,"html_url":"https://github.com/mazesec/Cart","commit_stats":null,"previous_names":["0xm4ze/cart","mazesec/cart"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mazesec/Cart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazesec%2FCart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazesec%2FCart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazesec%2FCart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazesec%2FCart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mazesec","download_url":"https://codeload.github.com/mazesec/Cart/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazesec%2FCart/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268290738,"owners_count":24226646,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-08-01T20:09:25.474Z","updated_at":"2025-08-01T20:09:28.434Z","avatar_url":"https://github.com/mazesec.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cart library\nA simple PHP shopping cart library to use in ecommerce web applications\n\n## Usage\n### Installation\n```sh \n  composer require tal7aouy/cart\n  ```\n### Configuration\n\n##### Options\n\n| Parameter       | Type     | Description                                                            |\n| --------------- | -------- | ---------------------------------------------------------------------- |\n| maxItem         | **int**  | The maximum item can be added to cart. 0 = Unlimited                   |\n| itemMaxQte      | **int**  | The maximum quantity per item can be added to cart. 0 = Unlimited      |\n| cookieState     | **bool** |  cookie that helps you to keep data in browser when it closed.         |\n\n```php\n//Instantiate cart \n$cart= new Cart(**array** $options);\n```\n\n\n```php\n  require_once __DIR__.\"/vendor/autoload.php\";\n  use Tal7aouy\\Cart;\n// Initialize Cart object\n$cart = new Cart([\n  // Can add unlimited number of item to cart\n  'maxItem'      =\u003e 0,\n  \n  // Set maximum quantity allowed per item to 20\n  'itemMaxQte'  =\u003e 20,\n  \n  // do not use cookie ,cart data will lost when browser is closed\n  'cookieState'        =\u003e false,\n]);\n```\n\n\n\n### Add Item\n\nAdds an item to cart.\n\n\u003e $cart-\u003eadd(**string** $id, **int** $quantity = 1, **array** $attributes = []): **bool**;\n\n```php\n// Add item with ID #10\n$cart-\u003eadd('10');\n\n// Add 5 item with ID #12\n$cart-\u003eadd('12', 5);\n\n// Add item with ID #14 with price, color, and size\n$cart-\u003eadd('14', 1, [\n  'price'  =\u003e '5.99',\n  'color'  =\u003e 'yellow',\n  'size'   =\u003e 'SM',\n]);\n\n// Item with same ID but different attributes will added as separate item in cart\n$cart-\u003eadd('14', 1, [\n  'price'  =\u003e '5.99',\n  'color'  =\u003e 'Brown',\n  'size'   =\u003e 'M',\n]);\n```\n### has Item\n\n```php\n// has item with ID #10\n$isExist = $cart-\u003ehas('10');\n\n\n// has item exist with attributes\n$isExist = $cart-\u003ehas('10',[\n  'price'  =\u003e '5.99',\n  'color'  =\u003e 'yellow',\n  'size'   =\u003e 'SM',\n]);\n\n```\n\n\n### Update Item\n\nUpdates quantity of an item. Attributes **must be** provides if item with same ID exists with different attributes.\n\n\u003e $cart-\u003eupdate(**string** $id, **int** $quantity = 1, **array** $attributes = []): **bool**;\n\n```php\n// Set quantity for item #10 to 5\n$cart-\u003eupdate('10', 5);\n\n// Set quantity for item #14 to 2\n$cart-\u003eupdate('14' [\n  'price'  =\u003e '5.99',\n  'color'  =\u003e 'Red',\n  'size'   =\u003e 'M',\n]);\n```\n\n\n\n### Remove Item\n\nRemoves an item. Attributes **must be** provided to remove specified item, or all items with same ID will be removed from cart.\n\n\u003e $cart-\u003eremove(**string** $id, **array** $attributes = []): **bool**;\n\n```php\n// Remove item #10\n$cart-\u003eremove('10');\n\n// Remove item #14 with color white and size XS\n$cart-\u003eremove('1003', [\n  'price'  =\u003e '5.99',\n  'color'  =\u003e 'White',\n  'size'   =\u003e 'XS',\n]);\n```\n\n\n\n### Get Items\n\nGets a multi-dimensional array of items stored in cart.\n\n\u003e $cart-\u003egetItems( ): **array**;\n\n```php\n// Get all items in the cart\n$allItems = $cart-\u003egetItems();\n\nforeach ($allItems as $items) {\n  foreach ($items as $item) {\n    echo 'ID: '.$item['id'].'\u003cbr /\u003e';\n    echo 'Qty: '.$item['quantity'].'\u003cbr /\u003e';\n    echo 'Price: '.$item['attributes']['price'].'\u003cbr /\u003e';\n    echo 'Size: '.$item['attributes']['size'].'\u003cbr /\u003e';\n    echo 'Color: '.$item['attributes']['color'].'\u003cbr /\u003e';\n  }\n}\n```\n\n\n### Get Item\n\nGets a multi-dimensional array of one item stored in cart.\n\n\u003e $cart-\u003egetItem(**string** $id, **string** $hash): **array**;\n\n```php\n// Get first one item from the cart with id 10\n$theItem = $cart-\u003egetItem('10');\n\n// Get one item from the cart with any id and hash\n$theItem = $cart-\u003egetItem($item['id'], $item['hash']);\n```\n\n\n\n### Check Cart Empty\n\nChecks if the cart is empty.\n\n\u003e $cart-\u003eisEmpty( ):**bool**;\n\n```php\nif ($cart-\u003eisEmpty()) {\n  echo 'There is nothing in the basket.';\n}\n```\n\n\n\n### Get Total Item\n\nGets the total of items in the cart.\n\n\u003e $cart-\u003egetTotalItems( ): **int**;\n\n```php\necho 'There are '.$cart-\u003egetTotalItems().' items in the cart.';\n```\n\n\n\n### Get Total Quantity\n\nGets the total of quantity in the cart.\n\n\u003e $cart-\u003egetTotalQuantity( ): **int**;\n\n```php\necho $cart-\u003egetTotalQuantity();\n```\n\n\n\n### Get Attribute Total\n\nGets the sum of a specific attribute.\n\n\u003e $cart-\u003egetTotalAttribute( **string** $attribute ): **float**;\n\n```php\necho '\u003ch3\u003eTotal Price: $'.number_format($cart-\u003egetTotalAttribute('price'), 2, '.', ',').'\u003c/h3\u003e';\n```\n\n\n\n### Clear Cart\n\nClears all items in the cart.\n\n\u003e $cart-\u003eclear( ):void;\n\n```php\n$cart-\u003eclear();\n```\n\n\n\n### Destroy Cart\n\nDestroys the entire cart session.\n\n\u003e \\$cart-\u003edestroy( );\n\n```php\n$cart-\u003edestroy();\n```\n\n\n\n### Item Exists\n\nChecks if an item exists in cart.\n\n\u003e **bool** \\$cart-\u003eisItemExists( **string** \\$id\\[, **array** \\$attributes\\] );\n\n```php\nif ($cart-\u003eisItemExists('1001')) {\n  echo 'This item already added to cart.';\n}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazesec%2Fcart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazesec%2Fcart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazesec%2Fcart/lists"}