mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7427ce953a | ||
|
|
6ba50a1c48 | ||
|
|
fce7125c5f | ||
|
|
834e211443 | ||
|
|
9b198edb7d | ||
|
|
49959faace | ||
|
|
e61ffae5fe | ||
|
|
10ab30f4e8 | ||
|
|
34626eef5e | ||
|
|
6020b655e2 | ||
|
|
2c56062f97 | ||
|
|
b2a4864675 | ||
|
|
aaa3360d1f |
@@ -18,10 +18,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2
|
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
|
||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php }}
|
php-version: ${{ matrix.php }}
|
||||||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached
|
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached
|
||||||
|
|||||||
@@ -4,3 +4,4 @@
|
|||||||
.phpunit.result.cache
|
.phpunit.result.cache
|
||||||
READMETODO.md
|
READMETODO.md
|
||||||
build
|
build
|
||||||
|
docs/superpowers/
|
||||||
@@ -9,11 +9,12 @@
|
|||||||
|
|
||||||
A Cart Implementation for Laravel.
|
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)
|
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
|
## Table of Contents
|
||||||
|
|
||||||
- [Getting Started](#-getting-started)
|
- [Getting Started](#-getting-started)
|
||||||
- [Demo](#-deni)
|
- [Demo](#-deni)
|
||||||
- [Documentation](#-documentation)
|
- [Documentation](#-documentation)
|
||||||
@@ -27,6 +28,7 @@ ## Table of Contents
|
|||||||
- [License](#-license)
|
- [License](#-license)
|
||||||
|
|
||||||
## 🚀 Getting Started
|
## 🚀 Getting Started
|
||||||
|
|
||||||
### 🔥 Installing
|
### 🔥 Installing
|
||||||
|
|
||||||
Install the package through [Composer](http://getcomposer.org/).
|
Install the package through [Composer](http://getcomposer.org/).
|
||||||
@@ -107,7 +109,6 @@ #### Round Mode
|
|||||||
'round_mode' => env('LARAVEL_CART_ROUND_MODE', 'down'),
|
'round_mode' => env('LARAVEL_CART_ROUND_MODE', 'down'),
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Basic Usage
|
### 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.
|
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.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wearepixel/laravel-cart",
|
"name": "wearepixel/laravel-cart",
|
||||||
"version": "2.1.1",
|
"version": "2.1.4",
|
||||||
"description": "A cart implementation for Laravel",
|
"description": "A cart implementation for Laravel",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"laravel",
|
"laravel",
|
||||||
|
|||||||
+2
-6
@@ -1,10 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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">
|
||||||
bootstrap="vendor/autoload.php"
|
<source ignoreIndirectDeprecations="true">
|
||||||
colors="true"
|
|
||||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
|
|
||||||
>
|
|
||||||
<source>
|
|
||||||
<include>
|
<include>
|
||||||
<directory suffix=".php">./src</directory>
|
<directory suffix=".php">./src</directory>
|
||||||
</include>
|
</include>
|
||||||
|
|||||||
+2
-4
@@ -159,10 +159,8 @@ public function clear()
|
|||||||
|
|
||||||
$deleted = $this->session->delete();
|
$deleted = $this->session->delete();
|
||||||
|
|
||||||
$this->session = [
|
$this->session[$this->itemsKey] = [];
|
||||||
$this->itemsKey => [],
|
$this->session[$this->conditionsKey] = [];
|
||||||
$this->conditionsKey => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $deleted;
|
return $deleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,40 @@
|
|||||||
namespace Wearepixel\Cart\Facades;
|
namespace Wearepixel\Cart\Facades;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
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
|
class CartFacade extends Facade
|
||||||
{
|
{
|
||||||
protected static function getFacadeAccessor()
|
protected static function getFacadeAccessor(): string
|
||||||
{
|
{
|
||||||
return 'cart';
|
return 'cart';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,4 +123,23 @@
|
|||||||
expect($this->cart->getContent()->count())->toEqual(0, 'Cart content should be 0');
|
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');
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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);
|
||||||
Reference in New Issue
Block a user