Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Tests

on:
push:
branches: [main, master, Dev]
pull_request:
branches: [main, master, Dev]

jobs:
phpunit:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.3', '8.4', '8.5']

name: PHP ${{ matrix.php }}

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, xml, curl
coverage: none

- name: Validate composer.json
run: composer validate --strict

- name: Install dependencies
run: composer update --prefer-dist --no-interaction --no-progress

- name: Run PHPUnit
run: composer test

lowest:
runs-on: ubuntu-latest
name: Lowest dependencies (PHP 8.3)

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, xml, curl
coverage: none

- name: Install lowest dependencies
run: composer update --prefer-dist --no-interaction --no-progress --prefer-lowest

- name: Run PHPUnit
run: composer test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ composer.phar
composer.lock
.DS_Store
.idea
.phpunit.result.cache
.phpunit.result.cache
.phpunit.cache
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) dev-ibizinfo and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
125 changes: 84 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,103 @@
# Laravel 5 & 6 , 7 & 9 Shopping Cart
[![Build Status](https://travis-ci.org/darryldecode/laravelshoppingcart.svg?branch=master)](https://travis-ci.org/darryldecode/laravelshoppingcart)
[![Total Downloads](https://poser.pugx.org/darryldecode/cart/d/total.svg)](https://packagist.org/packages/darryldecode/cart)
[![License](https://poser.pugx.org/darryldecode/cart/license.svg)](https://packagist.org/packages/darryldecode/cart)
# Laravel Shopping Cart (Laravel 13)

A Shopping Cart Implementation for Laravel Framework
[![Tests](https://github.com/dev-ibizinfo/laravelshoppingcart/actions/workflows/tests.yml/badge.svg)](https://github.com/dev-ibizinfo/laravelshoppingcart/actions/workflows/tests.yml)
[![PHP](https://img.shields.io/badge/PHP-8.3%2B-777BB4?logo=php&logoColor=white)](https://www.php.net/releases/)
[![Laravel](https://img.shields.io/badge/Laravel-13.x-FF2D20?logo=laravel&logoColor=white)](https://laravel.com/docs/13.x)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Packagist Version](https://poser.pugx.org/dev-ibizinfo/laravelshoppingcart/v)](https://packagist.org/packages/dev-ibizinfo/laravelshoppingcart)
[![Packagist Downloads](https://poser.pugx.org/dev-ibizinfo/laravelshoppingcart/d/total)](https://packagist.org/packages/dev-ibizinfo/laravelshoppingcart)

## QUICK PARTIAL DEMO
Session-based shopping cart for **Laravel 13** on **PHP 8.3+** (8.3–8.5 supported). The package targets **`illuminate/*` ^13.0** only (no Laravel 12 or older frameworks in the same release line).

Demo: https://shoppingcart-demo.darrylfernandez.com/cart
> **Lineage:** API and behavior follow the original [darryldecode/laravelshoppingcart](https://github.com/darryldecode/laravelshoppingcart) / Packagist `darryldecode/cart`. For **Laravel 5–12**, use that package at the version constraint that matches your app. This fork is for **Laravel 13** and modern PHP only.

Git repo of the demo: https://github.com/darryldecode/laravelshoppingcart-demo
## Requirements

## INSTALLATION
| Requirement | Notes |
|-------------|--------|
| **PHP** | `^8.3` (tested on 8.3, 8.4, 8.5) |
| **Laravel** | 13.x — `illuminate/support`, `illuminate/validation`, `illuminate/translation`, `illuminate/filesystem` at **^13.0** |

Install the package through [Composer](http://getcomposer.org/).
## Features

For Laravel 5.1~:
`composer require "darryldecode/cart:~2.0"`
- Session-backed cart with **session keys** and **multiple named instances**
- **Conditions** (fees, discounts, tax) at cart or line level
- **Eloquent / model** association on line items
- **Events** fired on cart lifecycle
- Optional **custom storage** (session, database, etc.)
- **Number formatting** via `config/shopping_cart.php`

For Laravel 5.5, 5.6, or 5.7~, 9:
## Quick demo (upstream project)

```composer require "darryldecode/cart:~4.0"``` or
```composer require "darryldecode/cart"```
Live demo: https://shoppingcart-demo.darrylfernandez.com/cart

## CONFIGURATION
Demo source: https://github.com/darryldecode/laravelshoppingcart-demo

1. Open config/app.php and add this line to your Service Providers Array.
(The demo may target an older Laravel version; use this package’s install steps below for Laravel 13 apps.)

```php
Darryldecode\Cart\CartServiceProvider::class
## Installation

Install with [Composer](https://getcomposer.org/):

```bash
composer require dev-ibizinfo/laravelshoppingcart
```

Laravel will **auto-discover** the service provider and the `Cart` facade alias from `composer.json` → `extra.laravel`. You normally do **not** need to register anything by hand.

## Configuration

### 1. Publish config (optional)

Use this when you want to change formatting, storage, or event classes:

```bash
php artisan vendor:publish --provider="Darryldecode\Cart\CartServiceProvider" --tag="config"
```

2. Open config/app.php and add this line to your Aliases
This publishes `config/shopping_cart.php`.

### 2. Manual registration (only if package discovery is disabled)

**Service provider**

```php
'Cart' => Darryldecode\Cart\Facades\CartFacade::class
Darryldecode\Cart\CartServiceProvider::class,
```

3. Optional configuration file (useful if you plan to have full control)
Register it in the place your Laravel 13 app lists providers (for example `bootstrap/providers.php`, or inside `AppServiceProvider`, depending on your skeleton).

**Facade alias**

```php
php artisan vendor:publish --provider="Darryldecode\Cart\CartServiceProvider" --tag="config"
'Cart' => Darryldecode\Cart\Facades\CartFacade::class,
```

## HOW TO USE

- [Quick Usage](#usage-usage-example)
- [Usage](#usage)
- [Conditions](#conditions)
- [Items](#items)
- [Associating Models](#associating-models)
- [Instances](#instances)
- [Exceptions](#exceptions)
- [Events](#events)
- [Format Response](#format)
- [Examples](#examples)
- [Using Different Storage](#storage)
- [License](#license)
Add to your aliases map if your app still uses a central aliases array; otherwise reference `Darryldecode\Cart\Facades\CartFacade` or the configured alias `Cart` as usual.

## Development

| Task | Command |
|------|---------|
| Run tests | `composer test` |
| Validate `composer.json` | `composer validate --strict` |

**CI:** [GitHub Actions](.github/workflows/tests.yml) runs PHPUnit on PHP **8.3**, **8.4**, and **8.5**, runs `composer validate --strict`, and includes a **lowest dependency** install on PHP 8.3.

## Table of contents

- [Quick usage example](#quick-usage-example)
- [Usage](#usage)
- [Conditions](#conditions)
- [Items](#items)
- [Associating models](#associating-models)
- [Instances](#instances)
- [Exceptions](#exceptions)
- [Events](#events)
- [Format response](#format-response)
- [Examples](#examples)
- [Using different storage](#storage)
- [License](#license)

## Quick Usage Example

Expand Down Expand Up @@ -95,9 +136,9 @@ foreach($items as $row) {
echo $row->qty;
echo $row->price;

echo $item->associatedModel->id; // whatever properties your model have
echo $item->associatedModel->name; // whatever properties your model have
echo $item->associatedModel->description; // whatever properties your model have
echo $row->associatedModel->id; // whatever properties your model have
echo $row->associatedModel->name; // whatever properties your model have
echo $row->associatedModel->description; // whatever properties your model have
}

// FOR FULL USAGE, SEE BELOW..
Expand Down Expand Up @@ -1250,7 +1291,9 @@ OR

## License

The Laravel Shopping Cart is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

It builds on the ideas and API of the community **Laravel Shopping Cart** projects above; this **Laravel 13** line is maintained separately with updated `composer.json`, tests, and CI.

### Disclaimer

Expand Down
85 changes: 49 additions & 36 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
{
"name": "saleem189/cart",
"description": "Laravel 5 Shopping cart",
"keywords": ["laravel", "shopping cart", "cart"],
"license": "MIT",
"authors": [
{
"name": "Darryl Fernandez",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.3",
"illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/validation": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/translation": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0"
},
"require-dev": {
"mockery/mockery": "^1.4.2",
"phpunit/phpunit": "^9.0",
"symfony/var-dumper": "5.1.5.*@dev"
},
"autoload": {
"psr-4": {
"Darryldecode\\": "src/Darryldecode"
}
},
"minimum-stability": "dev",
"extra": {
"laravel": {
"providers": [
"Darryldecode\\Cart\\CartServiceProvider"
],
"aliases": {
"Cart": "Darryldecode\\Cart\\Facades\\CartFacade"
}
}
"name": "dev-ibizinfo/laravelshoppingcart",
"description": "Laravel 13 Shopping cart",
"keywords": [
"laravel",
"shopping cart",
"cart"
],
"license": "MIT",
"authors": [
{
"name": "dev-ibizinfo",
"email": "[email protected]"
}
],
"require": {
"php": "^8.3",
"illuminate/support": "^13.0",
"illuminate/validation": "^13.0",
"illuminate/translation": "^13.0",
"illuminate/filesystem": "^13.0"
},
"require-dev": {
"mockery/mockery": "^1.6",
"phpunit/phpunit": "^12.0"
},
"autoload": {
"psr-4": {
"Darryldecode\\": "src/Darryldecode"
}
},
"autoload-dev": {
"psr-4": {
"Darryldecode\\Tests\\": "tests/"
}
},
"minimum-stability": "stable",
"prefer-stable": true,
"scripts": {
"test": "phpunit"
},
"extra": {
"laravel": {
"providers": [
"Darryldecode\\Cart\\CartServiceProvider"
],
"aliases": {
"Cart": "Darryldecode\\Cart\\Facades\\CartFacade"
}
}
}
}
15 changes: 6 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<exclude>./tests/helpers</exclude>
</testsuite>
</testsuites>
</phpunit>
Loading