mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05729b7865 | ||
|
|
7e6ee749bf | ||
|
|
17532f1b05 | ||
|
|
d058ad5521 | ||
|
|
3f5e9374c3 | ||
|
|
fcdd356718 | ||
|
|
3500fa43a9 | ||
|
|
28a72581fc | ||
|
|
ddcf38dab0 | ||
|
|
e7bf1ba3a3 | ||
|
|
ebf5a41e01 | ||
|
|
e0d566cebd | ||
|
|
863ef52e8d | ||
|
|
6638f812c8 | ||
|
|
8f442f51e0 | ||
|
|
6dfd0ce761 | ||
|
|
a3161888aa |
+21
-5
@@ -1,17 +1,33 @@
|
||||
version: 2
|
||||
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
target-branch: "master"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "monday"
|
||||
open-pull-requests-limit: 10
|
||||
groups:
|
||||
actions:
|
||||
patterns: ["*"]
|
||||
commit-message:
|
||||
prefix: "chore"
|
||||
include: "scope"
|
||||
labels:
|
||||
- "deps"
|
||||
- "dependencies"
|
||||
|
||||
- package-ecosystem: "composer"
|
||||
directory: "/"
|
||||
target-branch: "master"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "tuesday"
|
||||
open-pull-requests-limit: 10
|
||||
groups:
|
||||
php-minor-patch:
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
||||
commit-message:
|
||||
prefix: "chore"
|
||||
include: "scope"
|
||||
labels:
|
||||
- "deps"
|
||||
- "dependencies"
|
||||
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
|
||||
- name: Dependabot metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v2.2.0
|
||||
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
|
||||
|
||||
@@ -9,19 +9,19 @@ on:
|
||||
jobs:
|
||||
tests:
|
||||
name: Tests
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
php: ['8.2', '8.3', '8.4']
|
||||
php: ["8.3", "8.4", "8.5"]
|
||||
stability: [prefer-stable]
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached
|
||||
@@ -29,12 +29,11 @@ jobs:
|
||||
coverage: none
|
||||
|
||||
- name: Install dependencies
|
||||
uses: nick-fields/retry@v3
|
||||
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
|
||||
with:
|
||||
timeout_minutes: 5
|
||||
max_attempts: 5
|
||||
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress ${{ matrix.flags }}
|
||||
|
||||
|
||||
- name: Execute tests
|
||||
run: vendor/bin/pest
|
||||
run: vendor/bin/pest
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<a name="top"></a>
|
||||
[](https://joelmale.com)
|
||||
[](https://packagist.org/packages/joelwmale/laravel-cart)
|
||||
[](https://github.com/joelwmale/laravel-cart/actions?query=workflow%3ATests+branch%3Amaster)
|
||||
[](https://packagist.org/packages/joelwmale/laravel-cart)
|
||||
[](#)
|
||||
[](https://packagist.org/packages/joelwmale/laravel-cart)
|
||||
[](https://packagist.org/packages/wearepixel/laravel-cart)
|
||||
[](https://github.com/wearepixel/laravel-cart/actions?query=workflow%3ATests+branch%3Amaster)
|
||||
[](https://packagist.org/packages/wearepixel/laravel-cart)
|
||||
[](#)
|
||||
[](https://packagist.org/packages/wearepixel/laravel-cart)
|
||||
[](#-license)
|
||||
|
||||
A Cart Implementation for Laravel.
|
||||
|
||||
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
|
||||
- [Getting Started](#-getting-started)
|
||||
@@ -31,7 +31,7 @@ ### 🔥 Installing
|
||||
|
||||
Install the package through [Composer](http://getcomposer.org/).
|
||||
|
||||
`composer require joelwmale/laravel-cart`
|
||||
`composer require wearepixel/laravel-cart`
|
||||
|
||||
## 🧑🍳 Demo
|
||||
|
||||
@@ -71,7 +71,7 @@ ### ⚙️ Configuration
|
||||
You can publish the configuration file to customize various options.
|
||||
|
||||
```php
|
||||
php artisan vendor:publish --provider="Joelwmale\Cart\CartServiceProvider" --tag="config"
|
||||
php artisan vendor:publish --provider="Wearepixel\Cart\CartServiceProvider" --tag="config"
|
||||
```
|
||||
|
||||
#### Formatting Numbers
|
||||
@@ -328,7 +328,7 @@ ##### Adding a condition to the cart: **Cart::condition()**
|
||||
|
||||
```php
|
||||
// Add a single condition to the cart
|
||||
$condition = new \Joelwmale\Cart\CartCondition([
|
||||
$condition = new \Wearepixel\Cart\CartCondition([
|
||||
'name' => 'Tax: 10%',
|
||||
'type' => 'tax',
|
||||
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
||||
@@ -341,7 +341,7 @@ ##### Adding a condition to the cart: **Cart::condition()**
|
||||
Cart::condition($condition);
|
||||
|
||||
// Add multiple conditions
|
||||
$tax = new \Joelwmale\Cart\CartCondition([
|
||||
$tax = new \Wearepixel\Cart\CartCondition([
|
||||
'name' => 'Tax: 10%',
|
||||
'type' => 'tax',
|
||||
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
||||
@@ -349,7 +349,7 @@ ##### Adding a condition to the cart: **Cart::condition()**
|
||||
'order' => 2
|
||||
]);
|
||||
|
||||
$shipping = new \Joelwmale\Cart\CartCondition([
|
||||
$shipping = new \Wearepixel\Cart\CartCondition([
|
||||
'name' => 'Shipping: $15',
|
||||
'type' => 'shipping',
|
||||
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
|
||||
@@ -364,7 +364,7 @@ ##### Adding a condition to the cart: **Cart::condition()**
|
||||
Cart::condition([$tax, $shipping]);
|
||||
|
||||
// add condition to only apply on totals, not in subtotal
|
||||
$shipping = new \Joelwmale\Cart\CartCondition([
|
||||
$shipping = new \Wearepixel\Cart\CartCondition([
|
||||
'name' => 'Express Shipping $15',
|
||||
'type' => 'shipping',
|
||||
'target' => 'total',
|
||||
@@ -556,7 +556,7 @@ #### Conditions on items
|
||||
```php
|
||||
|
||||
// lets create first our condition instance
|
||||
$saleCondition = new \Joelwmale\Cart\CartCondition([
|
||||
$saleCondition = new \Wearepixel\Cart\CartCondition([
|
||||
'name' => '50% Off',
|
||||
'type' => 'tax',
|
||||
'value' => '-50%',
|
||||
@@ -576,7 +576,7 @@ #### Conditions on items
|
||||
Cart::add($product);
|
||||
|
||||
// You can of course also do multiple conditions on an item
|
||||
$saleCondition = new \Joelwmale\Cart\CartCondition([
|
||||
$saleCondition = new \Wearepixel\Cart\CartCondition([
|
||||
'name' => 'SALE 5%',
|
||||
'type' => 'sale',
|
||||
'value' => '-5%',
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
# Security Policy
|
||||
|
||||
**PLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY, [SEE BELOW](#reporting-a-vulnerability).**
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you discover a security vulnerability, please report it privately using the below channel:
|
||||
|
||||
**GitHub Private Vulnerability Reporting** — go to the repository's **Security** tab and click **"Report a vulnerability"**. This creates a private advisory visible only to maintainers and provides a structured workflow for triage, fix coordination, and CVE assignment.
|
||||
|
||||
All security vulnerabilities will be promptly addressed.
|
||||
+17
-17
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "joelwmale/laravel-cart",
|
||||
"version": "1.2.1",
|
||||
"name": "wearepixel/laravel-cart",
|
||||
"version": "2.1.1",
|
||||
"description": "A cart implementation for Laravel",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
@@ -19,37 +19,37 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.2",
|
||||
"illuminate/support": "^10.0|^11.0|^12.0",
|
||||
"illuminate/auth": "^10.0|^11.0|^12.0",
|
||||
"illuminate/container": "^10.0|^11.0|^12.0",
|
||||
"illuminate/database": "^10.0|^11.0|^12.0",
|
||||
"illuminate/validation": "^10.0|^11.0|^12.0"
|
||||
"php": ">=8.3",
|
||||
"illuminate/support": "^11.0|^12.0|^13.0",
|
||||
"illuminate/auth": "^11.0|^12.0|^13.0",
|
||||
"illuminate/container": "^11.0|^12.0|^13.0",
|
||||
"illuminate/database": "^11.0|^12.0|^13.0",
|
||||
"illuminate/validation": "^11.0|^12.0|^13.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.6",
|
||||
"mockery/mockery": "^2.0",
|
||||
"laravel/pint": "^1.21",
|
||||
"pestphp/pest": "^3.0",
|
||||
"pestphp/pest": "^4.7",
|
||||
"larapack/dd": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Joelwmale\\Cart\\": "src/"
|
||||
"Wearepixel\\Cart\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Joelwmale\\Cart\\CartServiceProvider"
|
||||
"Wearepixel\\Cart\\CartServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Cart": "Joelwmale\\Cart\\Facades\\CartFacade"
|
||||
"Cart": "Wearepixel\\Cart\\Facades\\CartFacade"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Generated
+1020
-720
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 41 KiB |
+33
-11
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart;
|
||||
namespace Wearepixel\Cart;
|
||||
|
||||
use Joelwmale\Cart\Helpers\Helpers;
|
||||
use Joelwmale\Cart\Validators\CartItemValidator;
|
||||
use Joelwmale\Cart\Exceptions\InvalidItemException;
|
||||
use Joelwmale\Cart\Exceptions\UnknownModelException;
|
||||
use Joelwmale\Cart\Exceptions\InvalidConditionException;
|
||||
use Wearepixel\Cart\Helpers\Helpers;
|
||||
use Wearepixel\Cart\Validators\CartItemValidator;
|
||||
use Wearepixel\Cart\Exceptions\InvalidItemException;
|
||||
use Wearepixel\Cart\Exceptions\UnknownModelException;
|
||||
use Wearepixel\Cart\Exceptions\InvalidConditionException;
|
||||
|
||||
class Cart
|
||||
{
|
||||
@@ -165,9 +165,31 @@ public function add(
|
||||
|
||||
$this->currentItemId = $id;
|
||||
|
||||
// clean up any incomplete items
|
||||
$this->removeInvalidItems();
|
||||
|
||||
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
|
||||
*/
|
||||
@@ -232,11 +254,11 @@ public function setConfig($config)
|
||||
public function addItemCondition($productId, $itemCondition)
|
||||
{
|
||||
if ($product = $this->get($productId)) {
|
||||
$conditionInstance = '\\Joelwmale\\Cart\\CartCondition';
|
||||
$conditionInstance = '\\Wearepixel\\Cart\\CartCondition';
|
||||
|
||||
if ($itemCondition instanceof $conditionInstance) {
|
||||
// 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
|
||||
// // see link for more info: http://stackoverflow.com/questions/20053269/indirect-modification-of-overloaded-element-of-splfixedarray-has-no-effect
|
||||
$itemConditionTempHolder = $product['conditions'];
|
||||
@@ -323,7 +345,7 @@ public function condition(array|CartCondition $condition): self
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -465,7 +487,7 @@ public function removeItemCondition($itemId, $conditionName)
|
||||
// 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
|
||||
else {
|
||||
$conditionInstance = 'Joelwmale\\Cart\\CartCondition';
|
||||
$conditionInstance = 'Wearepixel\\Cart\\CartCondition';
|
||||
|
||||
if ($item['conditions'] instanceof $conditionInstance) {
|
||||
if ($tempConditionsHolder->getName() == $conditionName) {
|
||||
@@ -766,7 +788,7 @@ protected function itemHasConditions($item)
|
||||
return count($item['conditions']) > 0;
|
||||
}
|
||||
|
||||
$conditionInstance = 'Joelwmale\\Cart\\CartCondition';
|
||||
$conditionInstance = 'Wearepixel\\Cart\\CartCondition';
|
||||
|
||||
if ($item['conditions'] instanceof $conditionInstance) {
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart;
|
||||
namespace Wearepixel\Cart;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart;
|
||||
namespace Wearepixel\Cart;
|
||||
|
||||
use Joelwmale\Cart\Helpers\Helpers;
|
||||
use Joelwmale\Cart\Validators\CartConditionValidator;
|
||||
use Joelwmale\Cart\Exceptions\InvalidConditionException;
|
||||
use Wearepixel\Cart\Helpers\Helpers;
|
||||
use Wearepixel\Cart\Validators\CartConditionValidator;
|
||||
use Wearepixel\Cart\Exceptions\InvalidConditionException;
|
||||
|
||||
class CartCondition
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart;
|
||||
namespace Wearepixel\Cart;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart;
|
||||
namespace Wearepixel\Cart;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart;
|
||||
namespace Wearepixel\Cart;
|
||||
|
||||
class CartSession
|
||||
{
|
||||
@@ -43,7 +43,7 @@ public function isInternalSession($session)
|
||||
{
|
||||
return in_array(is_object($session) ? get_class($session) : $session, [
|
||||
'Illuminate\Session\SessionManager',
|
||||
'Joelwmale\Cart\Tests\Helpers\SessionMock',
|
||||
'Wearepixel\Cart\Tests\Helpers\SessionMock',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Exceptions;
|
||||
namespace Wearepixel\Cart\Exceptions;
|
||||
|
||||
class InvalidConditionException extends \Exception {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Exceptions;
|
||||
namespace Wearepixel\Cart\Exceptions;
|
||||
|
||||
class InvalidItemException extends \Exception {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Exceptions;
|
||||
namespace Wearepixel\Cart\Exceptions;
|
||||
|
||||
class UnknownModelException extends \Exception {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Facades;
|
||||
namespace Wearepixel\Cart\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Helpers;
|
||||
namespace Wearepixel\Cart\Helpers;
|
||||
|
||||
class Helpers
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart;
|
||||
namespace Wearepixel\Cart;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart;
|
||||
namespace Wearepixel\Cart;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Joelwmale\Cart\Helpers\Helpers;
|
||||
use Wearepixel\Cart\Helpers\Helpers;
|
||||
|
||||
class ItemCollection extends Collection
|
||||
{
|
||||
@@ -72,7 +72,7 @@ public function hasConditions()
|
||||
if (is_array($this['conditions'])) {
|
||||
return count($this['conditions']) > 0;
|
||||
}
|
||||
$conditionInstance = 'Joelwmale\\Cart\\CartCondition';
|
||||
$conditionInstance = 'Wearepixel\\Cart\\CartCondition';
|
||||
if ($this['conditions'] instanceof $conditionInstance) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Validators;
|
||||
namespace Wearepixel\Cart\Validators;
|
||||
|
||||
class CartConditionValidator extends Validator {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Validators;
|
||||
namespace Wearepixel\Cart\Validators;
|
||||
|
||||
class CartItemValidator extends Validator {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Validators;
|
||||
namespace Wearepixel\Cart\Validators;
|
||||
|
||||
use Illuminate\Validation\Factory;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
'storage' => [
|
||||
'session',
|
||||
'database' => [
|
||||
'model' => \Joelwmale\Cart\Tests\Helpers\MockCartModel::class,
|
||||
'model' => \Wearepixel\Cart\Tests\Helpers\MockCartModel::class,
|
||||
'id' => 'session_id',
|
||||
'items' => 'items',
|
||||
'conditions' => 'conditions',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Tests\Helpers;
|
||||
namespace Wearepixel\Cart\Tests\Helpers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Tests\Helpers;
|
||||
namespace Wearepixel\Cart\Tests\Helpers;
|
||||
|
||||
use Illuminate\Contracts\Database\ModelIdentifier;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Joelwmale\Cart\Tests\Helpers;
|
||||
namespace Wearepixel\Cart\Tests\Helpers;
|
||||
|
||||
class SessionMock
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Joelwmale\Cart\Cart;
|
||||
use Joelwmale\Cart\CartCondition;
|
||||
use Joelwmale\Cart\CartConditionCollection;
|
||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
||||
use Wearepixel\Cart\Cart;
|
||||
use Wearepixel\Cart\CartCondition;
|
||||
use Wearepixel\Cart\CartConditionCollection;
|
||||
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||
|
||||
beforeEach(function () {
|
||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||
|
||||
+10
-10
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Joelwmale\Cart\Cart;
|
||||
use Joelwmale\Cart\Tests\Helpers\MockProduct;
|
||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
||||
use Wearepixel\Cart\Cart;
|
||||
use Wearepixel\Cart\Tests\Helpers\MockProduct;
|
||||
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||
|
||||
beforeEach(function () {
|
||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||
@@ -149,7 +149,7 @@
|
||||
|
||||
$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
|
||||
// when we get that item from cart, it should still be an instance of ItemAttributeCollection
|
||||
@@ -162,7 +162,7 @@
|
||||
|
||||
$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 () {
|
||||
@@ -298,19 +298,19 @@
|
||||
});
|
||||
|
||||
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->cart->add(455, 'Sample Item', 100.99, 0, []);
|
||||
});
|
||||
|
||||
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->cart->add('', 'Sample Item', 100.99, 2, []);
|
||||
});
|
||||
|
||||
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->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()->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($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 () {
|
||||
@@ -681,7 +681,7 @@
|
||||
|
||||
$content = $this->cart->getContent();
|
||||
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');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Joelwmale\Cart\Cart;
|
||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
||||
use Wearepixel\Cart\Cart;
|
||||
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||
|
||||
beforeEach(function () {});
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
});
|
||||
|
||||
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.Adding', 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 () {
|
||||
$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')->times(2)->with('LaravelCart.Adding', 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 () {
|
||||
$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')->times(3)->with('LaravelCart.Adding', 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 () {
|
||||
$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')->times(3)->with('LaravelCart.Adding', 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 () {
|
||||
$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')->times(3)->with('LaravelCart.Adding', Mockery::type('array'), true);
|
||||
$events->shouldReceive('dispatch')->times(3)->with('LaravelCart.Added', Mockery::type('array'), true);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Joelwmale\Cart\Cart;
|
||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
||||
use Wearepixel\Cart\Cart;
|
||||
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||
|
||||
beforeEach(function () {
|
||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Joelwmale\Cart\Cart;
|
||||
use Joelwmale\Cart\CartCondition;
|
||||
use Joelwmale\Cart\Tests\Helpers\MockCartModel;
|
||||
use Wearepixel\Cart\Cart;
|
||||
use Wearepixel\Cart\CartCondition;
|
||||
use Wearepixel\Cart\Tests\Helpers\MockCartModel;
|
||||
|
||||
beforeEach(function () {
|
||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Joelwmale\Cart\Cart;
|
||||
use Joelwmale\Cart\CartCondition;
|
||||
use Joelwmale\Cart\Tests\Helpers\MockProduct;
|
||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
||||
use Wearepixel\Cart\Cart;
|
||||
use Wearepixel\Cart\CartCondition;
|
||||
use Wearepixel\Cart\Tests\Helpers\MockProduct;
|
||||
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||
|
||||
beforeEach(function () {
|
||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||
@@ -47,7 +47,7 @@
|
||||
});
|
||||
|
||||
test('item get conditions with conditions', function () {
|
||||
$itemCondition1 = new \Joelwmale\Cart\CartCondition([
|
||||
$itemCondition1 = new \Wearepixel\Cart\CartCondition([
|
||||
'name' => 'SALE 5%',
|
||||
'type' => 'sale',
|
||||
'target' => 'item',
|
||||
@@ -77,7 +77,7 @@
|
||||
});
|
||||
|
||||
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->cart->add(1, 'Test item', 1, 10.00)->associate('SomeModel');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Joelwmale\Cart\Cart;
|
||||
use Joelwmale\Cart\Tests\Helpers\SessionMock;
|
||||
use Wearepixel\Cart\Cart;
|
||||
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
||||
|
||||
beforeEach(function () {
|
||||
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
||||
|
||||
Reference in New Issue
Block a user