mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0d566cebd | ||
|
|
6638f812c8 | ||
|
|
8f442f51e0 | ||
|
|
6dfd0ce761 | ||
|
|
a3161888aa | ||
|
|
4c02310bf7 |
@@ -13,7 +13,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Dependabot metadata
|
- name: Dependabot metadata
|
||||||
id: metadata
|
id: metadata
|
||||||
uses: dependabot/fetch-metadata@v2.2.0
|
uses: dependabot/fetch-metadata@dbb049abf0d677abbd7f7eee0375145b417fdd34 # v2.2.0
|
||||||
with:
|
with:
|
||||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
|
||||||
|
|||||||
@@ -13,15 +13,15 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
php: ['8.2', '8.3', '8.4']
|
php: ['8.3', '8.4', '8.5']
|
||||||
stability: [prefer-stable]
|
stability: [prefer-stable]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||||
|
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # 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
|
||||||
@@ -29,7 +29,7 @@ jobs:
|
|||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
uses: nick-fields/retry@v3
|
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3
|
||||||
with:
|
with:
|
||||||
timeout_minutes: 5
|
timeout_minutes: 5
|
||||||
max_attempts: 5
|
max_attempts: 5
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
<a name="top"></a>
|
<a name="top"></a>
|
||||||
[](https://joelmale.com)
|
[](https://joelmale.com)
|
||||||
[](https://packagist.org/packages/joelwmale/laravel-cart)
|
[](https://packagist.org/packages/wearepixel/laravel-cart)
|
||||||
[](https://github.com/joelwmale/laravel-cart/actions?query=workflow%3ATests+branch%3Amaster)
|
[](https://github.com/wearepixel/laravel-cart/actions?query=workflow%3ATests+branch%3Amaster)
|
||||||
[](https://packagist.org/packages/joelwmale/laravel-cart)
|
[](https://packagist.org/packages/wearepixel/laravel-cart)
|
||||||
[](#)
|
[](#)
|
||||||
[](https://packagist.org/packages/joelwmale/laravel-cart)
|
[](https://packagist.org/packages/wearepixel/laravel-cart)
|
||||||
[](#-license)
|
[](#-license)
|
||||||
|
|
||||||
A Cart Implementation for Laravel.
|
A Cart Implementation for Laravel.
|
||||||
|
|
||||||
Supported Laravel Versions: 10, 11, and 12.
|
Supported Laravel Versions: 10, 11, and 12.
|
||||||
|
|
||||||
For Laravel 9.0 and below, please use version [1.0](https://github.com/joelwmale/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)
|
||||||
@@ -31,7 +31,7 @@ ### 🔥 Installing
|
|||||||
|
|
||||||
Install the package through [Composer](http://getcomposer.org/).
|
Install the package through [Composer](http://getcomposer.org/).
|
||||||
|
|
||||||
`composer require joelwmale/laravel-cart`
|
`composer require wearepixel/laravel-cart`
|
||||||
|
|
||||||
## 🧑🍳 Demo
|
## 🧑🍳 Demo
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ ### ⚙️ Configuration
|
|||||||
You can publish the configuration file to customize various options.
|
You can publish the configuration file to customize various options.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
php artisan vendor:publish --provider="Joelwmale\Cart\CartServiceProvider" --tag="config"
|
php artisan vendor:publish --provider="Wearepixel\Cart\CartServiceProvider" --tag="config"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Formatting Numbers
|
#### Formatting Numbers
|
||||||
@@ -110,21 +110,17 @@ #### Round Mode
|
|||||||
|
|
||||||
### Basic Usage
|
### Basic Usage
|
||||||
|
|
||||||
The cart has a default sessionKey that holds the cart data and stores it in the session.
|
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.
|
||||||
|
|
||||||
This
|
This also serves as a cart unique identifier which you can use to bind a cart to a specific user if you want to.
|
||||||
also serves as a cart unique identifier which you can use to bind a cart to a specific user if you want to.
|
|
||||||
|
|
||||||
Make sure to call `\Cart::session($sessionKey)` before calling any other cart methods.
|
Make sure to call `\Cart::setSessionKey($sessionKey)` before calling any other cart methods.
|
||||||
|
|
||||||
Usually this is not required.
|
Usually this is not required.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
// Binds the cart to a unique id (user id, session id, etc.)
|
// Binds the cart to a unique id (user id, session id, etc.)
|
||||||
\Cart::session(User::first()->id);
|
\Cart::setSessionKey(User::first()->id);
|
||||||
|
|
||||||
// If you don't want to bind the cart on a project level, you can add it to each call
|
|
||||||
\Cart::session(User::first()->id)->add(1, 'Product 1', 19.99, 2, ['size' => 'large']);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Adding to the cart: **Cart::add()**
|
#### Adding to the cart: **Cart::add()**
|
||||||
@@ -332,7 +328,7 @@ ##### Adding a condition to the cart: **Cart::condition()**
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
// Add a single condition to the cart
|
// Add a single condition to the cart
|
||||||
$condition = new \Joelwmale\Cart\CartCondition([
|
$condition = new \Wearepixel\Cart\CartCondition([
|
||||||
'name' => 'Tax: 10%',
|
'name' => 'Tax: 10%',
|
||||||
'type' => 'tax',
|
'type' => 'tax',
|
||||||
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
||||||
@@ -345,7 +341,7 @@ ##### Adding a condition to the cart: **Cart::condition()**
|
|||||||
Cart::condition($condition);
|
Cart::condition($condition);
|
||||||
|
|
||||||
// Add multiple conditions
|
// Add multiple conditions
|
||||||
$tax = new \Joelwmale\Cart\CartCondition([
|
$tax = new \Wearepixel\Cart\CartCondition([
|
||||||
'name' => 'Tax: 10%',
|
'name' => 'Tax: 10%',
|
||||||
'type' => 'tax',
|
'type' => 'tax',
|
||||||
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
||||||
@@ -353,7 +349,7 @@ ##### Adding a condition to the cart: **Cart::condition()**
|
|||||||
'order' => 2
|
'order' => 2
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$shipping = new \Joelwmale\Cart\CartCondition([
|
$shipping = new \Wearepixel\Cart\CartCondition([
|
||||||
'name' => 'Shipping: $15',
|
'name' => 'Shipping: $15',
|
||||||
'type' => 'shipping',
|
'type' => 'shipping',
|
||||||
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
||||||
@@ -368,7 +364,7 @@ ##### Adding a condition to the cart: **Cart::condition()**
|
|||||||
Cart::condition([$tax, $shipping]);
|
Cart::condition([$tax, $shipping]);
|
||||||
|
|
||||||
// add condition to only apply on totals, not in subtotal
|
// add condition to only apply on totals, not in subtotal
|
||||||
$shipping = new \Joelwmale\Cart\CartCondition([
|
$shipping = new \Wearepixel\Cart\CartCondition([
|
||||||
'name' => 'Express Shipping $15',
|
'name' => 'Express Shipping $15',
|
||||||
'type' => 'shipping',
|
'type' => 'shipping',
|
||||||
'target' => 'total',
|
'target' => 'total',
|
||||||
@@ -560,7 +556,7 @@ #### Conditions on items
|
|||||||
```php
|
```php
|
||||||
|
|
||||||
// lets create first our condition instance
|
// lets create first our condition instance
|
||||||
$saleCondition = new \Joelwmale\Cart\CartCondition([
|
$saleCondition = new \Wearepixel\Cart\CartCondition([
|
||||||
'name' => '50% Off',
|
'name' => '50% Off',
|
||||||
'type' => 'tax',
|
'type' => 'tax',
|
||||||
'value' => '-50%',
|
'value' => '-50%',
|
||||||
@@ -580,7 +576,7 @@ #### Conditions on items
|
|||||||
Cart::add($product);
|
Cart::add($product);
|
||||||
|
|
||||||
// You can of course also do multiple conditions on an item
|
// You can of course also do multiple conditions on an item
|
||||||
$saleCondition = new \Joelwmale\Cart\CartCondition([
|
$saleCondition = new \Wearepixel\Cart\CartCondition([
|
||||||
'name' => 'SALE 5%',
|
'name' => 'SALE 5%',
|
||||||
'type' => 'sale',
|
'type' => 'sale',
|
||||||
'value' => '-5%',
|
'value' => '-5%',
|
||||||
|
|||||||
+16
-16
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "joelwmale/laravel-cart",
|
"name": "wearepixel/laravel-cart",
|
||||||
"version": "1.2.0",
|
"version": "2.1.0",
|
||||||
"description": "A cart implementation for Laravel",
|
"description": "A cart implementation for Laravel",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"laravel",
|
"laravel",
|
||||||
@@ -19,37 +19,37 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.2",
|
"php": ">=8.3",
|
||||||
"illuminate/support": "^10.0|^11.0|^12.0",
|
"illuminate/support": "^11.0|^12.0|^13.0",
|
||||||
"illuminate/auth": "^10.0|^11.0|^12.0",
|
"illuminate/auth": "^11.0|^12.0|^13.0",
|
||||||
"illuminate/container": "^10.0|^11.0|^12.0",
|
"illuminate/container": "^11.0|^12.0|^13.0",
|
||||||
"illuminate/database": "^10.0|^11.0|^12.0",
|
"illuminate/database": "^11.0|^12.0|^13.0",
|
||||||
"illuminate/validation": "^10.0|^11.0|^12.0"
|
"illuminate/validation": "^11.0|^12.0|^13.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"mockery/mockery": "^1.6",
|
"mockery/mockery": "^2.0",
|
||||||
"laravel/pint": "^1.21",
|
"laravel/pint": "^1.21",
|
||||||
"pestphp/pest": "^3.0",
|
"pestphp/pest": "^3.0",
|
||||||
"larapack/dd": "dev-master"
|
"larapack/dd": "dev-master"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Joelwmale\\Cart\\": "src/"
|
"Wearepixel\\Cart\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Tests\\": "tests/"
|
"Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"extra": {
|
"extra": {
|
||||||
"laravel": {
|
"laravel": {
|
||||||
"providers": [
|
"providers": [
|
||||||
"Joelwmale\\Cart\\CartServiceProvider"
|
"Wearepixel\\Cart\\CartServiceProvider"
|
||||||
],
|
],
|
||||||
"aliases": {
|
"aliases": {
|
||||||
"Cart": "Joelwmale\\Cart\\Facades\\CartFacade"
|
"Cart": "Wearepixel\\Cart\\Facades\\CartFacade"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Generated
+26
-81
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "f793be451d0e7ab030f23c46cb371171",
|
"content-hash": "ae136c12e9ee350b88f5c7ccae6c8525",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
@@ -5123,58 +5123,6 @@
|
|||||||
],
|
],
|
||||||
"time": "2025-01-25T12:00:00+00:00"
|
"time": "2025-01-25T12:00:00+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "hamcrest/hamcrest-php",
|
|
||||||
"version": "dev-master",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/hamcrest/hamcrest-php.git",
|
|
||||||
"reference": "ea3c21ca78e9696dbd7d8f16e1141ca7be241e6a"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/ea3c21ca78e9696dbd7d8f16e1141ca7be241e6a",
|
|
||||||
"reference": "ea3c21ca78e9696dbd7d8f16e1141ca7be241e6a",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": "^5.3|^7.0|^8.0"
|
|
||||||
},
|
|
||||||
"replace": {
|
|
||||||
"cordoval/hamcrest-php": "*",
|
|
||||||
"davedevelopment/hamcrest-php": "*",
|
|
||||||
"kodova/hamcrest-php": "*"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpunit/php-file-iterator": "^1.4 || ^2.0 || ^3.0",
|
|
||||||
"phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0"
|
|
||||||
},
|
|
||||||
"default-branch": true,
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-master": "2.1-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"classmap": [
|
|
||||||
"hamcrest"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"BSD-3-Clause"
|
|
||||||
],
|
|
||||||
"description": "This is the PHP port of Hamcrest Matchers",
|
|
||||||
"keywords": [
|
|
||||||
"test"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/hamcrest/hamcrest-php/issues",
|
|
||||||
"source": "https://github.com/hamcrest/hamcrest-php/tree/master"
|
|
||||||
},
|
|
||||||
"time": "2025-01-01T06:33:44+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "jean85/pretty-package-versions",
|
"name": "jean85/pretty-package-versions",
|
||||||
"version": "2.x-dev",
|
"version": "2.x-dev",
|
||||||
@@ -5344,37 +5292,45 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "mockery/mockery",
|
"name": "mockery/mockery",
|
||||||
"version": "1.7.x-dev",
|
"version": "2.0.x-dev",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/mockery/mockery.git",
|
"url": "https://github.com/mockery/mockery.git",
|
||||||
"reference": "3f8d3ff1ffe4c552d45c5690c6d825e9310769bf"
|
"reference": "bfdbf7326fb03fba8dd8c02acba7269e2f7b7abf"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/mockery/mockery/zipball/3f8d3ff1ffe4c552d45c5690c6d825e9310769bf",
|
"url": "https://api.github.com/repos/mockery/mockery/zipball/bfdbf7326fb03fba8dd8c02acba7269e2f7b7abf",
|
||||||
"reference": "3f8d3ff1ffe4c552d45c5690c6d825e9310769bf",
|
"reference": "bfdbf7326fb03fba8dd8c02acba7269e2f7b7abf",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"hamcrest/hamcrest-php": "^2.0.1",
|
"ext-json": "*",
|
||||||
"lib-pcre": ">=7.0",
|
"ext-mbstring": "*",
|
||||||
"php": ">=7.3"
|
"ext-pcre": "*",
|
||||||
|
"php": "^8.1 || ^8.2 || ^8.3"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"phpunit/phpunit": "<8.0"
|
"phpunit/phpunit": "<8.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": ">=9.6.11 <10.4"
|
"phpunit/phpunit": "^8.5 || ^9.6",
|
||||||
|
"psalm/plugin-phpunit": "^0.18",
|
||||||
|
"vimeo/psalm": "^5.12"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "1.6.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
"files": [
|
||||||
"library/helpers.php",
|
"src/helpers.php",
|
||||||
"library/Mockery.php"
|
"src/Mockery.php"
|
||||||
],
|
],
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Mockery\\": "library/Mockery"
|
"Mockery\\": "src/Mockery"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
@@ -5385,20 +5341,12 @@
|
|||||||
{
|
{
|
||||||
"name": "Pádraic Brady",
|
"name": "Pádraic Brady",
|
||||||
"email": "padraic.brady@gmail.com",
|
"email": "padraic.brady@gmail.com",
|
||||||
"homepage": "https://github.com/padraic",
|
"homepage": "https://blog.astrumfutura.com"
|
||||||
"role": "Author"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Dave Marshall",
|
"name": "Dave Marshall",
|
||||||
"email": "dave.marshall@atstsolutions.co.uk",
|
"email": "dave.marshall@atstsolutions.co.uk",
|
||||||
"homepage": "https://davedevelopment.co.uk",
|
"homepage": "https://davedevelopment.co.uk"
|
||||||
"role": "Developer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Nathanael Esayeas",
|
|
||||||
"email": "nathanael.esayeas@protonmail.com",
|
|
||||||
"homepage": "https://github.com/ghostwriter",
|
|
||||||
"role": "Lead Developer"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Mockery is a simple yet flexible PHP mock object framework",
|
"description": "Mockery is a simple yet flexible PHP mock object framework",
|
||||||
@@ -5416,13 +5364,10 @@
|
|||||||
"testing"
|
"testing"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"docs": "https://docs.mockery.io/",
|
|
||||||
"issues": "https://github.com/mockery/mockery/issues",
|
"issues": "https://github.com/mockery/mockery/issues",
|
||||||
"rss": "https://github.com/mockery/mockery/releases.atom",
|
"source": "https://github.com/mockery/mockery/tree/2.0.x"
|
||||||
"security": "https://github.com/mockery/mockery/security/advisories",
|
|
||||||
"source": "https://github.com/mockery/mockery"
|
|
||||||
},
|
},
|
||||||
"time": "2023-10-01T17:31:30+00:00"
|
"time": "2024-03-12T12:46:22+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "myclabs/deep-copy",
|
"name": "myclabs/deep-copy",
|
||||||
@@ -7894,8 +7839,8 @@
|
|||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": ">=8.2"
|
"php": ">=8.3"
|
||||||
},
|
},
|
||||||
"platform-dev": {},
|
"platform-dev": {},
|
||||||
"plugin-api-version": "2.6.0"
|
"plugin-api-version": "2.9.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 41 KiB |
+43
-11
@@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
use Joelwmale\Cart\Helpers\Helpers;
|
use Wearepixel\Cart\Helpers\Helpers;
|
||||||
use Joelwmale\Cart\Validators\CartItemValidator;
|
use Wearepixel\Cart\Validators\CartItemValidator;
|
||||||
use Joelwmale\Cart\Exceptions\InvalidItemException;
|
use Wearepixel\Cart\Exceptions\InvalidItemException;
|
||||||
use Joelwmale\Cart\Exceptions\UnknownModelException;
|
use Wearepixel\Cart\Exceptions\UnknownModelException;
|
||||||
use Joelwmale\Cart\Exceptions\InvalidConditionException;
|
use Wearepixel\Cart\Exceptions\InvalidConditionException;
|
||||||
|
|
||||||
class Cart
|
class Cart
|
||||||
{
|
{
|
||||||
@@ -56,6 +56,16 @@ private function validateConfig($config)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSessionKey(): string
|
||||||
|
{
|
||||||
|
return $this->session->getSessionKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSessionKey(string $sessionKey): void
|
||||||
|
{
|
||||||
|
$this->session->setSessionKey($sessionKey);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get instance name of the cart
|
* get instance name of the cart
|
||||||
*
|
*
|
||||||
@@ -155,9 +165,31 @@ public function add(
|
|||||||
|
|
||||||
$this->currentItemId = $id;
|
$this->currentItemId = $id;
|
||||||
|
|
||||||
|
// clean up any incomplete items
|
||||||
|
$this->removeInvalidItems();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove any incomplete items
|
||||||
|
*/
|
||||||
|
public function removeInvalidItems(): bool
|
||||||
|
{
|
||||||
|
$carts = $this->getContent();
|
||||||
|
|
||||||
|
foreach ($carts as $index => $cart) {
|
||||||
|
|
||||||
|
if (! (isset($cart['id'], $cart['name'], $cart['quantity']))) {
|
||||||
|
|
||||||
|
// remove item
|
||||||
|
$this->remove($index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a cart item with whatever data is passed in
|
* Update a cart item with whatever data is passed in
|
||||||
*/
|
*/
|
||||||
@@ -222,11 +254,11 @@ public function setConfig($config)
|
|||||||
public function addItemCondition($productId, $itemCondition)
|
public function addItemCondition($productId, $itemCondition)
|
||||||
{
|
{
|
||||||
if ($product = $this->get($productId)) {
|
if ($product = $this->get($productId)) {
|
||||||
$conditionInstance = '\\Joelwmale\\Cart\\CartCondition';
|
$conditionInstance = '\\Wearepixel\\Cart\\CartCondition';
|
||||||
|
|
||||||
if ($itemCondition instanceof $conditionInstance) {
|
if ($itemCondition instanceof $conditionInstance) {
|
||||||
// we need to copy first to a temporary variable to hold the conditions
|
// we need to copy first to a temporary variable to hold the conditions
|
||||||
// to avoid hitting this error "Indirect modification of overloaded element of Joelwmale\Cart\ItemCollection has no effect"
|
// to avoid hitting this error "Indirect modification of overloaded element of Wearepixel\Cart\ItemCollection has no effect"
|
||||||
// this is due to laravel Collection instance that implements Array Access
|
// this is due to laravel Collection instance that implements Array Access
|
||||||
// // see link for more info: http://stackoverflow.com/questions/20053269/indirect-modification-of-overloaded-element-of-splfixedarray-has-no-effect
|
// // see link for more info: http://stackoverflow.com/questions/20053269/indirect-modification-of-overloaded-element-of-splfixedarray-has-no-effect
|
||||||
$itemConditionTempHolder = $product['conditions'];
|
$itemConditionTempHolder = $product['conditions'];
|
||||||
@@ -313,7 +345,7 @@ public function condition(array|CartCondition $condition): self
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! $condition instanceof CartCondition) {
|
if (! $condition instanceof CartCondition) {
|
||||||
throw new InvalidConditionException('Argument 1 must be an instance of \'Joelwmale\Cart\CartCondition\'');
|
throw new InvalidConditionException('Argument 1 must be an instance of \'Wearepixel\Cart\CartCondition\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
$conditions = $this->getConditions();
|
$conditions = $this->getConditions();
|
||||||
@@ -455,7 +487,7 @@ public function removeItemCondition($itemId, $conditionName)
|
|||||||
// on the given condition name the user wants to remove, if so,
|
// on the given condition name the user wants to remove, if so,
|
||||||
// lets just make $item['conditions'] an empty array as there's just 1 condition on it anyway
|
// lets just make $item['conditions'] an empty array as there's just 1 condition on it anyway
|
||||||
else {
|
else {
|
||||||
$conditionInstance = 'Joelwmale\\Cart\\CartCondition';
|
$conditionInstance = 'Wearepixel\\Cart\\CartCondition';
|
||||||
|
|
||||||
if ($item['conditions'] instanceof $conditionInstance) {
|
if ($item['conditions'] instanceof $conditionInstance) {
|
||||||
if ($tempConditionsHolder->getName() == $conditionName) {
|
if ($tempConditionsHolder->getName() == $conditionName) {
|
||||||
@@ -756,7 +788,7 @@ protected function itemHasConditions($item)
|
|||||||
return count($item['conditions']) > 0;
|
return count($item['conditions']) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$conditionInstance = 'Joelwmale\\Cart\\CartCondition';
|
$conditionInstance = 'Wearepixel\\Cart\\CartCondition';
|
||||||
|
|
||||||
if ($item['conditions'] instanceof $conditionInstance) {
|
if ($item['conditions'] instanceof $conditionInstance) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
use Joelwmale\Cart\Helpers\Helpers;
|
use Wearepixel\Cart\Helpers\Helpers;
|
||||||
use Joelwmale\Cart\Validators\CartConditionValidator;
|
use Wearepixel\Cart\Validators\CartConditionValidator;
|
||||||
use Joelwmale\Cart\Exceptions\InvalidConditionException;
|
use Wearepixel\Cart\Exceptions\InvalidConditionException;
|
||||||
|
|
||||||
class CartCondition
|
class CartCondition
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
|||||||
+30
-2
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
class CartSession
|
class CartSession
|
||||||
{
|
{
|
||||||
@@ -43,10 +43,38 @@ public function isInternalSession($session)
|
|||||||
{
|
{
|
||||||
return in_array(is_object($session) ? get_class($session) : $session, [
|
return in_array(is_object($session) ? get_class($session) : $session, [
|
||||||
'Illuminate\Session\SessionManager',
|
'Illuminate\Session\SessionManager',
|
||||||
'Joelwmale\Cart\Tests\Helpers\SessionMock',
|
'Wearepixel\Cart\Tests\Helpers\SessionMock',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSessionKey()
|
||||||
|
{
|
||||||
|
return $this->sessionKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSessionKey(string $sessionKey)
|
||||||
|
{
|
||||||
|
// set the session key and then update the session
|
||||||
|
$this->sessionKey = $sessionKey;
|
||||||
|
|
||||||
|
if ($this->driver == 'session') {
|
||||||
|
$session = $this->session->get($this->itemsKey);
|
||||||
|
$sessionKey = $this->session->get($this->conditionsKey);
|
||||||
|
|
||||||
|
$this->session->forget($this->itemsKey);
|
||||||
|
$this->session->forget($this->conditionsKey);
|
||||||
|
|
||||||
|
$this->itemsKey = $this->sessionKey . '_cart_items';
|
||||||
|
$this->conditionsKey = $this->sessionKey . '_cart_conditions';
|
||||||
|
|
||||||
|
$this->session->put($this->itemsKey, $session);
|
||||||
|
$this->session->put($this->conditionsKey, $sessionKey);
|
||||||
|
} elseif ($this->driver == 'database') {
|
||||||
|
$this->session[$this->sessionId] = $sessionKey;
|
||||||
|
$this->session->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function has($key)
|
public function has($key)
|
||||||
{
|
{
|
||||||
return $this->session->has($key) ?? $this->session;
|
return $this->session->has($key) ?? $this->session;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Exceptions;
|
namespace Wearepixel\Cart\Exceptions;
|
||||||
|
|
||||||
class InvalidConditionException extends \Exception {}
|
class InvalidConditionException extends \Exception {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Exceptions;
|
namespace Wearepixel\Cart\Exceptions;
|
||||||
|
|
||||||
class InvalidItemException extends \Exception {}
|
class InvalidItemException extends \Exception {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Exceptions;
|
namespace Wearepixel\Cart\Exceptions;
|
||||||
|
|
||||||
class UnknownModelException extends \Exception {}
|
class UnknownModelException extends \Exception {}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Facades;
|
namespace Wearepixel\Cart\Facades;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Helpers;
|
namespace Wearepixel\Cart\Helpers;
|
||||||
|
|
||||||
class Helpers
|
class Helpers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Joelwmale\Cart\Helpers\Helpers;
|
use Wearepixel\Cart\Helpers\Helpers;
|
||||||
|
|
||||||
class ItemCollection extends Collection
|
class ItemCollection extends Collection
|
||||||
{
|
{
|
||||||
@@ -72,7 +72,7 @@ public function hasConditions()
|
|||||||
if (is_array($this['conditions'])) {
|
if (is_array($this['conditions'])) {
|
||||||
return count($this['conditions']) > 0;
|
return count($this['conditions']) > 0;
|
||||||
}
|
}
|
||||||
$conditionInstance = 'Joelwmale\\Cart\\CartCondition';
|
$conditionInstance = 'Wearepixel\\Cart\\CartCondition';
|
||||||
if ($this['conditions'] instanceof $conditionInstance) {
|
if ($this['conditions'] instanceof $conditionInstance) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Validators;
|
namespace Wearepixel\Cart\Validators;
|
||||||
|
|
||||||
class CartConditionValidator extends Validator {}
|
class CartConditionValidator extends Validator {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Validators;
|
namespace Wearepixel\Cart\Validators;
|
||||||
|
|
||||||
class CartItemValidator extends Validator {}
|
class CartItemValidator extends Validator {}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Validators;
|
namespace Wearepixel\Cart\Validators;
|
||||||
|
|
||||||
use Illuminate\Validation\Factory;
|
use Illuminate\Validation\Factory;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
'storage' => [
|
'storage' => [
|
||||||
'session',
|
'session',
|
||||||
'database' => [
|
'database' => [
|
||||||
'model' => \Joelwmale\Cart\Tests\Helpers\MockCartModel::class,
|
'model' => \Wearepixel\Cart\Tests\Helpers\MockCartModel::class,
|
||||||
'id' => 'session_id',
|
'id' => 'session_id',
|
||||||
'items' => 'items',
|
'items' => 'items',
|
||||||
'conditions' => 'conditions',
|
'conditions' => 'conditions',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Tests\Helpers;
|
namespace Wearepixel\Cart\Tests\Helpers;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Tests\Helpers;
|
namespace Wearepixel\Cart\Tests\Helpers;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\ModelIdentifier;
|
use Illuminate\Contracts\Database\ModelIdentifier;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joelwmale\Cart\Tests\Helpers;
|
namespace Wearepixel\Cart\Tests\Helpers;
|
||||||
|
|
||||||
class SessionMock
|
class SessionMock
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Joelwmale\Cart\Cart;
|
use Wearepixel\Cart\Cart;
|
||||||
use Joelwmale\Cart\CartCondition;
|
use Wearepixel\Cart\CartCondition;
|
||||||
use Joelwmale\Cart\CartConditionCollection;
|
use Wearepixel\Cart\CartConditionCollection;
|
||||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
|
|||||||
+22
-10
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Joelwmale\Cart\Cart;
|
use Wearepixel\Cart\Cart;
|
||||||
use Joelwmale\Cart\Tests\Helpers\MockProduct;
|
use Wearepixel\Cart\Tests\Helpers\MockProduct;
|
||||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
@@ -149,7 +149,7 @@
|
|||||||
|
|
||||||
$item = $this->cart->get(1);
|
$item = $this->cart->get(1);
|
||||||
|
|
||||||
expect($item->attributes)->toBeInstanceOf('Joelwmale\\Cart\\ItemAttributeCollection');
|
expect($item->attributes)->toBeInstanceOf('Wearepixel\\Cart\\ItemAttributeCollection');
|
||||||
|
|
||||||
// now lets update the item with its new attributes
|
// now lets update the item with its new attributes
|
||||||
// when we get that item from cart, it should still be an instance of ItemAttributeCollection
|
// when we get that item from cart, it should still be an instance of ItemAttributeCollection
|
||||||
@@ -162,7 +162,7 @@
|
|||||||
|
|
||||||
$this->cart->update(1, $updatedItem);
|
$this->cart->update(1, $updatedItem);
|
||||||
|
|
||||||
expect($item->attributes)->toBeInstanceOf('Joelwmale\\Cart\\ItemAttributeCollection');
|
expect($item->attributes)->toBeInstanceOf('Wearepixel\\Cart\\ItemAttributeCollection');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('item orders are preserved by the order they are added', function () {
|
test('item orders are preserved by the order they are added', function () {
|
||||||
@@ -298,19 +298,19 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should throw an exception when no quantity is provided', function () {
|
test('should throw an exception when no quantity is provided', function () {
|
||||||
$this->expectException('Joelwmale\Cart\Exceptions\InvalidItemException');
|
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
|
||||||
$this->expectExceptionMessage('The quantity must be at least 0.1.');
|
$this->expectExceptionMessage('The quantity must be at least 0.1.');
|
||||||
$this->cart->add(455, 'Sample Item', 100.99, 0, []);
|
$this->cart->add(455, 'Sample Item', 100.99, 0, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw an exception when no id is provided', function () {
|
test('should throw an exception when no id is provided', function () {
|
||||||
$this->expectException('Joelwmale\Cart\Exceptions\InvalidItemException');
|
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
|
||||||
$this->expectExceptionMessage('The id field is required.');
|
$this->expectExceptionMessage('The id field is required.');
|
||||||
$this->cart->add('', 'Sample Item', 100.99, 2, []);
|
$this->cart->add('', 'Sample Item', 100.99, 2, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw an exception when no name is provided', function () {
|
test('should throw an exception when no name is provided', function () {
|
||||||
$this->expectException('Joelwmale\Cart\Exceptions\InvalidItemException');
|
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
|
||||||
$this->expectExceptionMessage('The name field is required.');
|
$this->expectExceptionMessage('The name field is required.');
|
||||||
$this->cart->add(523, '', 100.99, 2, []);
|
$this->cart->add(523, '', 100.99, 2, []);
|
||||||
});
|
});
|
||||||
@@ -646,7 +646,7 @@
|
|||||||
expect($this->cart->getContent()->count())->toEqual(1, 'Cart should have 1 item on it');
|
expect($this->cart->getContent()->count())->toEqual(1, 'Cart should have 1 item on it');
|
||||||
expect($this->cart->getContent()->first()['id'])->toEqual(456, 'The first content must have ID of 456');
|
expect($this->cart->getContent()->first()['id'])->toEqual(456, 'The first content must have ID of 456');
|
||||||
expect($this->cart->getContent()->first()['name'])->toEqual('Sample Item', 'The first content must have name of "Sample Item"');
|
expect($this->cart->getContent()->first()['name'])->toEqual('Sample Item', 'The first content must have name of "Sample Item"');
|
||||||
expect($addedItem->model)->toBeInstanceOf('Joelwmale\Cart\Tests\Helpers\MockProduct');
|
expect($addedItem->model)->toBeInstanceOf('Wearepixel\Cart\Tests\Helpers\MockProduct');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cart can add items with multidimensional array with associated model', function () {
|
test('cart can add items with multidimensional array with associated model', function () {
|
||||||
@@ -681,7 +681,7 @@
|
|||||||
|
|
||||||
$content = $this->cart->getContent();
|
$content = $this->cart->getContent();
|
||||||
foreach ($content as $item) {
|
foreach ($content as $item) {
|
||||||
expect($item->model)->toBeInstanceOf('Joelwmale\Cart\Tests\Helpers\MockProduct');
|
expect($item->model)->toBeInstanceOf('Wearepixel\Cart\Tests\Helpers\MockProduct');
|
||||||
}
|
}
|
||||||
|
|
||||||
expect($this->cart->isEmpty())->toBeFalse('Cart should not be empty');
|
expect($this->cart->isEmpty())->toBeFalse('Cart should not be empty');
|
||||||
@@ -689,3 +689,15 @@
|
|||||||
expect($this->cart->getTotalQuantity())->toBeInt('Return type should be INT');
|
expect($this->cart->getTotalQuantity())->toBeInt('Return type should be INT');
|
||||||
expect($this->cart->getTotalQuantity())->toEqual(12, 'Cart\'s quantity should be 4.');
|
expect($this->cart->getTotalQuantity())->toEqual(12, 'Cart\'s quantity should be 4.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('can add to cart and then update the session key', function () {
|
||||||
|
$this->cart->add(1, 'Sample Item', 100.99, 2, []);
|
||||||
|
|
||||||
|
expect($this->cart->getContent()->count())->toEqual(1, 'Cart content should be 1');
|
||||||
|
expect($this->cart->getContent()->first()['id'])->toEqual(1, 'Item added has ID of 1 so first content ID should be 1');
|
||||||
|
|
||||||
|
$this->cart->setSessionKey('new_session_key');
|
||||||
|
|
||||||
|
expect($this->cart->getSessionKey())->toEqual('new_session_key', 'Session key should be updated to new_session_key');
|
||||||
|
expect($this->cart->getContent()->count())->toEqual(1, 'Cart content should still be 1');
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Joelwmale\Cart\Cart;
|
use Wearepixel\Cart\Cart;
|
||||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||||
|
|
||||||
beforeEach(function () {});
|
beforeEach(function () {});
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('event cart adding', function () {
|
test('event cart adding', function () {
|
||||||
$events = Mockery::mock('Illuminate\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Adding', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Adding', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Added', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Added', Mockery::type('array'), true);
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('event cart adding multiple times', function () {
|
test('event cart adding multiple times', function () {
|
||||||
$events = Mockery::mock('Illuminate\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->times(2)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->times(2)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->times(2)->with('LaravelCart.Added', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->times(2)->with('LaravelCart.Added', Mockery::type('array'), true);
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('event cart adding multiple times scenario two', function () {
|
test('event cart adding multiple times scenario two', function () {
|
||||||
$events = Mockery::mock('Illuminate\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Added', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Added', Mockery::type('array'), true);
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('event cart remove item', function () {
|
test('event cart remove item', function () {
|
||||||
$events = Mockery::mock('Illuminate\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Added', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Added', Mockery::type('array'), true);
|
||||||
@@ -154,7 +154,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('event cart clear', function () {
|
test('event cart clear', function () {
|
||||||
$events = Mockery::mock('Illuminate\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->once()->with('LaravelCart.Created', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
||||||
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Added', Mockery::type('array'), true);
|
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Added', Mockery::type('array'), true);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Joelwmale\Cart\Cart;
|
use Wearepixel\Cart\Cart;
|
||||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Joelwmale\Cart\Cart;
|
use Wearepixel\Cart\Cart;
|
||||||
use Joelwmale\Cart\CartCondition;
|
use Wearepixel\Cart\CartCondition;
|
||||||
use Joelwmale\Cart\Tests\Helpers\MockCartModel;
|
use Wearepixel\Cart\Tests\Helpers\MockCartModel;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Joelwmale\Cart\Cart;
|
use Wearepixel\Cart\Cart;
|
||||||
use Joelwmale\Cart\CartCondition;
|
use Wearepixel\Cart\CartCondition;
|
||||||
use Joelwmale\Cart\Tests\Helpers\MockProduct;
|
use Wearepixel\Cart\Tests\Helpers\MockProduct;
|
||||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('item get conditions with conditions', function () {
|
test('item get conditions with conditions', function () {
|
||||||
$itemCondition1 = new \Joelwmale\Cart\CartCondition([
|
$itemCondition1 = new \Wearepixel\Cart\CartCondition([
|
||||||
'name' => 'SALE 5%',
|
'name' => 'SALE 5%',
|
||||||
'type' => 'sale',
|
'type' => 'sale',
|
||||||
'target' => 'item',
|
'target' => 'item',
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('it will throw an exception when a non existing model is being associated', function () {
|
test('it will throw an exception when a non existing model is being associated', function () {
|
||||||
$this->expectException(\Joelwmale\Cart\Exceptions\UnknownModelException::class);
|
$this->expectException(\Wearepixel\Cart\Exceptions\UnknownModelException::class);
|
||||||
$this->expectExceptionMessage('The supplied model SomeModel does not exist.');
|
$this->expectExceptionMessage('The supplied model SomeModel does not exist.');
|
||||||
|
|
||||||
$this->cart->add(1, 'Test item', 1, 10.00)->associate('SomeModel');
|
$this->cart->add(1, 'Test item', 1, 10.00)->associate('SomeModel');
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Joelwmale\Cart\Cart;
|
use Wearepixel\Cart\Cart;
|
||||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||||
|
|||||||
Reference in New Issue
Block a user