Compare commits

...
13 Commits
Author SHA1 Message Date
Joel Male 7427ce953a chore: bump version to 2.1.4 2026-06-13 14:19:39 +10:00
Joel Male 6ba50a1c48 fix: prevent save() on array after clear() with database driver 2026-06-13 14:18:55 +10:00
github-actions[bot] fce7125c5f Merge pull request #14 from wearepixel/dependabot/github_actions/actions-5dacb66663
chore(deps): bump shivammathur/setup-php from 2.37.1 to 2.37.2 in the actions group
2026-06-08 21:45:38 +00:00
dependabot[bot] 834e211443 chore(deps): bump shivammathur/setup-php in the actions group
Bumps the actions group with 1 update: [shivammathur/setup-php](https://github.com/shivammathur/setup-php).


Updates `shivammathur/setup-php` from 2.37.1 to 2.37.2
- [Release notes](https://github.com/shivammathur/setup-php/releases)
- [Commits](https://github.com/shivammathur/setup-php/compare/7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc...f3e473d116dcccaddc5834248c87452386958240)

---
updated-dependencies:
- dependency-name: shivammathur/setup-php
  dependency-version: 2.37.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-08 21:45:26 +00:00
github-actions[bot] 9b198edb7d Merge pull request #13 from wearepixel/dependabot/github_actions/actions-6a98abd9ac
chore(deps): bump actions/checkout from 6.0.2 to 6.0.3 in the actions group
2026-06-03 10:48:17 +00:00
dependabot[bot] 49959faace chore(deps): bump actions/checkout in the actions group
Bumps the actions group with 1 update: [actions/checkout](https://github.com/actions/checkout).


Updates `actions/checkout` from 6.0.2 to 6.0.3
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/de0fac2e4500dabe0009e67214ff5f5447ce83dd...df4cb1c069e1874edd31b4311f1884172cec0e10)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-03 10:48:04 +00:00
Joel Male e61ffae5fe chore: bump version to 2.1.3 2026-05-29 14:27:02 +10:00
Joel Male 10ab30f4e8 fix: correct add() @method signature to accept array input style 2026-05-29 14:14:34 +10:00
Joel Male 34626eef5e chore: bump version to 2.1.2 2026-05-29 14:12:49 +10:00
Joel Male 6020b655e2 Merge pull request #12 from wearepixel/fix/phpstan-facade-types
fix: add PHPStan/Larastan support to CartFacade
2026-05-29 14:11:47 +10:00
Joel Male 2c56062f97 fix: add @mixin and @method PHPDoc to CartFacade for PHPStan/Larastan support 2026-05-29 14:09:15 +10:00
Joel Male b2a4864675 chore: ignore docs/superpowers/ 2026-05-27 20:22:32 +10:00
Joel Male aaa3360d1f chore: add test bootstrap, update phpunit config, and add Laravel 13 support to README
- Add tests/bootstrap.php to suppress PHP 8.4 vendor deprecation notices (Mockery implicit-nullable)
- Update phpunit.xml.dist to reference bootstrap, use PHPUnit 11.5 schema, and ignore indirect deprecations
- Note Laravel 13 support in README
2026-05-27 19:50:09 +10:00
9 changed files with 82 additions and 23 deletions
+2 -2
View File
@@ -18,10 +18,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup PHP
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached
+2 -1
View File
@@ -3,4 +3,5 @@
.idea
.phpunit.result.cache
READMETODO.md
build
build
docs/superpowers/
+8 -7
View File
@@ -9,11 +9,12 @@
A Cart Implementation for Laravel.
Supported Laravel Versions: 10, 11, and 12.
Supported Laravel Versions: 10, 11, 12, and 13.
For Laravel 9.0 and below, please use version [1.0](https://github.com/wearepixel/laravel-cart/releases/tag/1.0.12)
## Table of Contents
- [Getting Started](#-getting-started)
- [Demo](#-deni)
- [Documentation](#-documentation)
@@ -27,6 +28,7 @@ ## Table of Contents
- [License](#-license)
## 🚀 Getting Started
### 🔥 Installing
Install the package through [Composer](http://getcomposer.org/).
@@ -107,7 +109,6 @@ #### Round Mode
'round_mode' => env('LARAVEL_CART_ROUND_MODE', 'down'),
```
### Basic Usage
The cart has a default sessionKey that holds the cart data and stores it in the session, so you can have multiple carts for multiple users.
@@ -168,8 +169,8 @@ #### Adding to the cart: **Cart::add()**
[], // attributes
[
[
'name' => '10% Off',
'type' => 'discount',
'name' => '10% Off',
'type' => 'discount',
'value' => '-10%'
]
] // conditions
@@ -199,7 +200,7 @@ #### Updating an item on a cart: **Cart::update()**
```php
Cart::update(
456, # product id
[
[
'name' => 'New Item Name', // new item name
'price' => 98.67, // new item price as a float or string
]
@@ -215,7 +216,7 @@ #### Updating an item on a cart: **Cart::update()**
// reducing it...
Cart::update(
456,
456,
[
'quantity' => -1, // so if from 4 to 3
]
@@ -841,4 +842,4 @@ ## 🫡 Credits
## 📓 License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "wearepixel/laravel-cart",
"version": "2.1.1",
"version": "2.1.4",
"description": "A cart implementation for Laravel",
"keywords": [
"laravel",
+3 -7
View File
@@ -1,15 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
>
<source>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd">
<source ignoreIndirectDeprecations="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
<testsuites>
<testsuites>
<testsuite name="Laravel Cart Test Suite">
<directory>tests</directory>
</testsuite>
+2 -4
View File
@@ -159,10 +159,8 @@ public function clear()
$deleted = $this->session->delete();
$this->session = [
$this->itemsKey => [],
$this->conditionsKey => [],
];
$this->session[$this->itemsKey] = [];
$this->session[$this->conditionsKey] = [];
return $deleted;
}
+31 -1
View File
@@ -3,10 +3,40 @@
namespace Wearepixel\Cart\Facades;
use Illuminate\Support\Facades\Facade;
use Wearepixel\Cart\Cart;
use Wearepixel\Cart\CartCollection;
use Wearepixel\Cart\CartCondition;
use Wearepixel\Cart\CartConditionCollection;
use Wearepixel\Cart\ItemCollection;
/**
* @mixin Cart
*
* @method static ItemCollection|null get(int|string $itemId)
* @method static bool has(int|string $itemId)
* @method static self add(string|int|array<string, mixed> $id, string|null $name = null, float|null $price = null, int|float|null $quantity = null, array<string, mixed> $attributes = [], CartCondition|array<mixed> $conditions = [], string|null $associatedModel = null)
* @method static bool update(int|string $id, array $data)
* @method static void remove(int|string $id)
* @method static void clear()
* @method static void clearItems()
* @method static Cart condition(array|CartCondition $condition)
* @method static CartConditionCollection|array getConditions(bool $array = false, bool $active = false)
* @method static CartCondition|null getCondition(string $conditionName)
* @method static CartConditionCollection getConditionsByType(string $type)
* @method static void removeConditionsByType(string $type)
* @method static void removeCartCondition(string $conditionName)
* @method static void clearItemConditions(int|string $itemId)
* @method static void clearAllConditions()
* @method static CartCollection getContent()
* @method static bool isEmpty()
* @method static int getTotalQuantity()
* @method static int|float|string getSubTotal(bool $formatted = true)
* @method static int|float|string getSubTotalWithoutConditions(bool $formatted = true)
* @method static int|float getTotal()
*/
class CartFacade extends Facade
{
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return 'cart';
}
+19
View File
@@ -123,4 +123,23 @@
expect($this->cart->getContent()->count())->toEqual(0, 'Cart content should be 0');
expect(MockCartModel::all()->count())->toEqual(0, 'The carts database table should have 0 rows');
});
test('can clear cart conditions after clearing the cart', function () {
$condition = new CartCondition([
'name' => '10% Off',
'type' => 'coupon',
'target' => 'subtotal',
'value' => '-10%',
]);
$this->cart->add(1, 'Sample Item', 100.99, 2, []);
$this->cart->condition($condition);
$this->cart->clear();
// This was throwing "Call to a member function save() on array"
// because clear() replaced $this->session with a plain array
expect(fn () => $this->cart->clearCartConditions())->not->toThrow(Error::class);
expect($this->cart->getConditions())->toBeEmpty();
});
});
+14
View File
@@ -0,0 +1,14 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
// Suppress PHP 8.4 deprecation notices that originate from vendor code.
// These are typically from third-party packages (e.g. Mockery) that have not
// yet updated implicit-nullable parameter signatures and are not actionable here.
set_error_handler(static function (int $errno, string $errstr, string $errfile): bool {
if ($errno === E_DEPRECATED && str_contains($errfile, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR)) {
return true;
}
return false;
}, E_DEPRECATED);