diff --git a/README.md b/README.md index b155ac1..6d8867f 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ [![Laravel Cart](./docs/laravel-cart.png)](https://joelmale.com) -[![Latest Version on Packagist](https://img.shields.io/packagist/v/joelwmale/laravel-cart.svg?style=flat-square)](https://packagist.org/packages/joelwmale/laravel-cart) -[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/joelwmale/laravel-cart/tests.yml?branch=master&label=Tests)](https://github.com/joelwmale/laravel-cart/actions?query=workflow%3ATests+branch%3Amaster) -[![Total Downloads](https://img.shields.io/packagist/dt/joelwmale/laravel-cart.svg?style=flat-square)](https://packagist.org/packages/joelwmale/laravel-cart) -[![GitHub last commit](https://img.shields.io/github/last-commit/joelwmale/laravel-cart)](#) -[![License](https://poser.pugx.org/joelwmale/laravel-cart/license.svg)](https://packagist.org/packages/joelwmale/laravel-cart) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/wearepixel/laravel-cart.svg?style=flat-square)](https://packagist.org/packages/wearepixel/laravel-cart) +[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/wearepixel/laravel-cart/tests.yml?branch=master&label=Tests)](https://github.com/wearepixel/laravel-cart/actions?query=workflow%3ATests+branch%3Amaster) +[![Total Downloads](https://img.shields.io/packagist/dt/wearepixel/laravel-cart.svg?style=flat-square)](https://packagist.org/packages/wearepixel/laravel-cart) +[![GitHub last commit](https://img.shields.io/github/last-commit/wearepixel/laravel-cart)](#) +[![License](https://poser.pugx.org/wearepixel/laravel-cart/license.svg)](https://packagist.org/packages/wearepixel/laravel-cart) [![Free](https://img.shields.io/badge/free_for_non_commercial_use-brightgreen)](#-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%', diff --git a/composer.json b/composer.json index 360fe10..86ada9e 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "joelwmale/laravel-cart", + "name": "wearepixel/laravel-cart", "version": "2.0.0", "description": "A cart implementation for Laravel", "keywords": [ @@ -27,14 +27,14 @@ "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", "larapack/dd": "dev-master" }, "autoload": { "psr-4": { - "Joelwmale\\Cart\\": "src/" + "Wearepixel\\Cart\\": "src/" } }, "autoload-dev": { @@ -46,10 +46,10 @@ "extra": { "laravel": { "providers": [ - "Joelwmale\\Cart\\CartServiceProvider" + "Wearepixel\\Cart\\CartServiceProvider" ], "aliases": { - "Cart": "Joelwmale\\Cart\\Facades\\CartFacade" + "Cart": "Wearepixel\\Cart\\Facades\\CartFacade" } } }, diff --git a/composer.lock b/composer.lock index b5d4e06..53484f9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f793be451d0e7ab030f23c46cb371171", + "content-hash": "ae136c12e9ee350b88f5c7ccae6c8525", "packages": [ { "name": "brick/math", @@ -5123,58 +5123,6 @@ ], "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", "version": "2.x-dev", @@ -5344,37 +5292,45 @@ }, { "name": "mockery/mockery", - "version": "1.7.x-dev", + "version": "2.0.x-dev", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "3f8d3ff1ffe4c552d45c5690c6d825e9310769bf" + "reference": "bfdbf7326fb03fba8dd8c02acba7269e2f7b7abf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/3f8d3ff1ffe4c552d45c5690c6d825e9310769bf", - "reference": "3f8d3ff1ffe4c552d45c5690c6d825e9310769bf", + "url": "https://api.github.com/repos/mockery/mockery/zipball/bfdbf7326fb03fba8dd8c02acba7269e2f7b7abf", + "reference": "bfdbf7326fb03fba8dd8c02acba7269e2f7b7abf", "shasum": "" }, "require": { - "hamcrest/hamcrest-php": "^2.0.1", - "lib-pcre": ">=7.0", - "php": ">=7.3" + "ext-json": "*", + "ext-mbstring": "*", + "ext-pcre": "*", + "php": "^8.1 || ^8.2 || ^8.3" }, "conflict": { "phpunit/phpunit": "<8.0" }, "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", + "extra": { + "branch-alias": { + "dev-main": "1.6.x-dev" + } + }, "autoload": { "files": [ - "library/helpers.php", - "library/Mockery.php" + "src/helpers.php", + "src/Mockery.php" ], "psr-4": { - "Mockery\\": "library/Mockery" + "Mockery\\": "src/Mockery" } }, "notification-url": "https://packagist.org/downloads/", @@ -5385,20 +5341,12 @@ { "name": "Pádraic Brady", "email": "padraic.brady@gmail.com", - "homepage": "https://github.com/padraic", - "role": "Author" + "homepage": "https://blog.astrumfutura.com" }, { "name": "Dave Marshall", "email": "dave.marshall@atstsolutions.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" + "homepage": "https://davedevelopment.co.uk" } ], "description": "Mockery is a simple yet flexible PHP mock object framework", @@ -5416,13 +5364,10 @@ "testing" ], "support": { - "docs": "https://docs.mockery.io/", "issues": "https://github.com/mockery/mockery/issues", - "rss": "https://github.com/mockery/mockery/releases.atom", - "security": "https://github.com/mockery/mockery/security/advisories", - "source": "https://github.com/mockery/mockery" + "source": "https://github.com/mockery/mockery/tree/2.0.x" }, - "time": "2023-10-01T17:31:30+00:00" + "time": "2024-03-12T12:46:22+00:00" }, { "name": "myclabs/deep-copy", @@ -7894,8 +7839,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=8.2" + "php": ">=8.3" }, "platform-dev": {}, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/docs/laravel-cart.png b/docs/laravel-cart.png index f8cac1f..53c41f9 100644 Binary files a/docs/laravel-cart.png and b/docs/laravel-cart.png differ diff --git a/src/Cart.php b/src/Cart.php index b1949cd..4a2b3b7 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -1,12 +1,12 @@ 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']; @@ -345,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(); @@ -487,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) { @@ -788,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; diff --git a/src/CartCollection.php b/src/CartCollection.php index b08a088..18ee559 100644 --- a/src/CartCollection.php +++ b/src/CartCollection.php @@ -1,6 +1,6 @@ 0; } - $conditionInstance = 'Joelwmale\\Cart\\CartCondition'; + $conditionInstance = 'Wearepixel\\Cart\\CartCondition'; if ($this['conditions'] instanceof $conditionInstance) { return true; } diff --git a/src/Validators/CartConditionValidator.php b/src/Validators/CartConditionValidator.php index d0182fc..8cb4b8d 100644 --- a/src/Validators/CartConditionValidator.php +++ b/src/Validators/CartConditionValidator.php @@ -1,5 +1,5 @@ [ 'session', 'database' => [ - 'model' => \Joelwmale\Cart\Tests\Helpers\MockCartModel::class, + 'model' => \Wearepixel\Cart\Tests\Helpers\MockCartModel::class, 'id' => 'session_id', 'items' => 'items', 'conditions' => 'conditions', diff --git a/tests/Helpers/MockCartModel.php b/tests/Helpers/MockCartModel.php index 6093e61..890fefa 100644 --- a/tests/Helpers/MockCartModel.php +++ b/tests/Helpers/MockCartModel.php @@ -1,6 +1,6 @@ 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'); diff --git a/tests/Unit/CartTestEventsTest.php b/tests/Unit/CartTestEventsTest.php index 80c0ef1..6bc0ead 100644 --- a/tests/Unit/CartTestEventsTest.php +++ b/tests/Unit/CartTestEventsTest.php @@ -1,7 +1,7 @@ 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); diff --git a/tests/Unit/CartTestMultipleInstancesTest.php b/tests/Unit/CartTestMultipleInstancesTest.php index a09b413..eb1017c 100644 --- a/tests/Unit/CartTestMultipleInstancesTest.php +++ b/tests/Unit/CartTestMultipleInstancesTest.php @@ -1,7 +1,7 @@ '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'); diff --git a/tests/Unit/ItemTestOtherFormatTest.php b/tests/Unit/ItemTestOtherFormatTest.php index 025d72c..928e8af 100644 --- a/tests/Unit/ItemTestOtherFormatTest.php +++ b/tests/Unit/ItemTestOtherFormatTest.php @@ -1,7 +1,7 @@