Compare commits

..
2 Commits
Author SHA1 Message Date
Joel Male 2ccba20119 1.0.8 2024-08-30 10:08:47 +10:00
Joel Male 313a4f7aa2 Revert "1.0.7"
This reverts commit 4a312a37e2.
2024-08-30 10:08:27 +10:00
25 changed files with 70 additions and 70 deletions
+8 -8
View File
@@ -33,14 +33,14 @@ ## Installing
Install the package through [Composer](http://getcomposer.org/). Install the package through [Composer](http://getcomposer.org/).
`composer require "pixeldigital/laravel-cart"` `composer require "wearepixel/laravel-cart"`
## Configuration ## 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="Pixeldigital\Cart\CartServiceProvider" --tag="config" php artisan vendor:publish --provider="Wearepixel\Cart\CartServiceProvider" --tag="config"
``` ```
### Formatting Numbers ### Formatting Numbers
@@ -302,7 +302,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 \Pixeldigital\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.
@@ -315,7 +315,7 @@ #### Adding a condition to the cart: **Cart::condition()**
Cart::condition($condition); Cart::condition($condition);
// Add multiple conditions // Add multiple conditions
$tax = new \Pixeldigital\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.
@@ -323,7 +323,7 @@ #### Adding a condition to the cart: **Cart::condition()**
'order' => 2 'order' => 2
]); ]);
$shipping = new \Pixeldigital\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.
@@ -338,7 +338,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 \Pixeldigital\Cart\CartCondition([ $shipping = new \Wearepixel\Cart\CartCondition([
'name' => 'Express Shipping $15', 'name' => 'Express Shipping $15',
'type' => 'shipping', 'type' => 'shipping',
'target' => 'total', 'target' => 'total',
@@ -429,7 +429,7 @@ ### Condition on items
```php ```php
// lets create first our condition instance // lets create first our condition instance
$saleCondition = new \Pixeldigital\Cart\CartCondition([ $saleCondition = new \Wearepixel\Cart\CartCondition([
'name' => '50% Off', 'name' => '50% Off',
'type' => 'tax', 'type' => 'tax',
'value' => '-50%', 'value' => '-50%',
@@ -449,7 +449,7 @@ ### Condition 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 \Pixeldigital\Cart\CartCondition([ $saleCondition = new \Wearepixel\Cart\CartCondition([
'name' => 'SALE 5%', 'name' => 'SALE 5%',
'type' => 'sale', 'type' => 'sale',
'value' => '-5%', 'value' => '-5%',
+5 -5
View File
@@ -1,6 +1,6 @@
{ {
"name": "pixeldigital/laravel-cart", "name": "wearepixel/laravel-cart",
"version": "1.0.7", "version": "1.0.8",
"description": "A cart implementation for Laravel", "description": "A cart implementation for Laravel",
"keywords": [ "keywords": [
"laravel", "laravel",
@@ -32,17 +32,17 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Pixeldigital\\Cart\\": "src/" "Wearepixel\\Cart\\": "src/"
} }
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"extra": { "extra": {
"laravel": { "laravel": {
"providers": [ "providers": [
"Pixeldigital\\Cart\\CartServiceProvider" "Wearepixel\\Cart\\CartServiceProvider"
], ],
"aliases": { "aliases": {
"Cart": "Pixeldigital\\Cart\\Facades\\CartFacade" "Cart": "Wearepixel\\Cart\\Facades\\CartFacade"
} }
} }
}, },
+11 -11
View File
@@ -1,12 +1,12 @@
<?php <?php
namespace Pixeldigital\Cart; namespace Wearepixel\Cart;
use Pixeldigital\Cart\Helpers\Helpers; use Wearepixel\Cart\Helpers\Helpers;
use Pixeldigital\Cart\Validators\CartItemValidator; use Wearepixel\Cart\Validators\CartItemValidator;
use Pixeldigital\Cart\Exceptions\InvalidItemException; use Wearepixel\Cart\Exceptions\InvalidItemException;
use Pixeldigital\Cart\Exceptions\UnknownModelException; use Wearepixel\Cart\Exceptions\UnknownModelException;
use Pixeldigital\Cart\Exceptions\InvalidConditionException; use Wearepixel\Cart\Exceptions\InvalidConditionException;
class Cart class Cart
{ {
@@ -270,11 +270,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 = '\\Pixeldigital\\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 Pixeldigital\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'];
@@ -353,7 +353,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 \'Pixeldigital\Cart\CartCondition\''); throw new InvalidConditionException('Argument 1 must be an instance of \'Wearepixel\Cart\CartCondition\'');
} }
$conditions = $this->getConditions(); $conditions = $this->getConditions();
@@ -479,7 +479,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 = 'Pixeldigital\\Cart\\CartCondition'; $conditionInstance = 'Wearepixel\\Cart\\CartCondition';
if ($item['conditions'] instanceof $conditionInstance) { if ($item['conditions'] instanceof $conditionInstance) {
if ($tempConditionsHolder->getName() == $conditionName) { if ($tempConditionsHolder->getName() == $conditionName) {
@@ -776,7 +776,7 @@ protected function itemHasConditions($item)
return count($item['conditions']) > 0; return count($item['conditions']) > 0;
} }
$conditionInstance = 'Pixeldigital\\Cart\\CartCondition'; $conditionInstance = 'Wearepixel\\Cart\\CartCondition';
if ($item['conditions'] instanceof $conditionInstance) { if ($item['conditions'] instanceof $conditionInstance) {
return true; return true;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart; namespace Wearepixel\Cart;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
+4 -4
View File
@@ -1,10 +1,10 @@
<?php <?php
namespace Pixeldigital\Cart; namespace Wearepixel\Cart;
use Pixeldigital\Cart\Helpers\Helpers; use Wearepixel\Cart\Helpers\Helpers;
use Pixeldigital\Cart\Validators\CartConditionValidator; use Wearepixel\Cart\Validators\CartConditionValidator;
use Pixeldigital\Cart\Exceptions\InvalidConditionException; use Wearepixel\Cart\Exceptions\InvalidConditionException;
class CartCondition class CartCondition
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart; namespace Wearepixel\Cart;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart; namespace Wearepixel\Cart;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Pixeldigital\Cart\Exceptions; namespace Wearepixel\Cart\Exceptions;
class InvalidConditionException extends \Exception {} class InvalidConditionException extends \Exception {}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Pixeldigital\Cart\Exceptions; namespace Wearepixel\Cart\Exceptions;
class InvalidItemException extends \Exception {} class InvalidItemException extends \Exception {}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Pixeldigital\Cart\Exceptions; namespace Wearepixel\Cart\Exceptions;
class UnknownModelException extends \Exception {} class UnknownModelException extends \Exception {}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart\Facades; namespace Wearepixel\Cart\Facades;
use Illuminate\Support\Facades\Facade; use Illuminate\Support\Facades\Facade;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart\Helpers; namespace Wearepixel\Cart\Helpers;
class Helpers class Helpers
{ {
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart; namespace Wearepixel\Cart;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
+3 -3
View File
@@ -1,9 +1,9 @@
<?php <?php
namespace Pixeldigital\Cart; namespace Wearepixel\Cart;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Pixeldigital\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 = 'Pixeldigital\\Cart\\CartCondition'; $conditionInstance = 'Wearepixel\\Cart\\CartCondition';
if ($this['conditions'] instanceof $conditionInstance) { if ($this['conditions'] instanceof $conditionInstance) {
return true; return true;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Pixeldigital\Cart\Validators; namespace Wearepixel\Cart\Validators;
class CartConditionValidator extends Validator {} class CartConditionValidator extends Validator {}
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace Pixeldigital\Cart\Validators; namespace Wearepixel\Cart\Validators;
class CartItemValidator extends Validator {} class CartItemValidator extends Validator {}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart\Validators; namespace Wearepixel\Cart\Validators;
use Illuminate\Validation\Factory; use Illuminate\Validation\Factory;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart\Tests\Helpers; namespace Wearepixel\Cart\Tests\Helpers;
use Illuminate\Contracts\Database\ModelIdentifier; use Illuminate\Contracts\Database\ModelIdentifier;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Pixeldigital\Cart\Tests\Helpers; namespace Wearepixel\Cart\Tests\Helpers;
class SessionMock class SessionMock
{ {
+3 -3
View File
@@ -1,8 +1,8 @@
<?php <?php
use Pixeldigital\Cart\Cart; use Wearepixel\Cart\Cart;
use Pixeldigital\Cart\CartCondition; use Wearepixel\Cart\CartCondition;
use Pixeldigital\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');
+10 -10
View File
@@ -1,8 +1,8 @@
<?php <?php
use Pixeldigital\Cart\Cart; use Wearepixel\Cart\Cart;
use Pixeldigital\Cart\Tests\Helpers\MockProduct; use Wearepixel\Cart\Tests\Helpers\MockProduct;
use Pixeldigital\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('Pixeldigital\\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('Pixeldigital\\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('Pixeldigital\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('Pixeldigital\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('Pixeldigital\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('Pixeldigital\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('Pixeldigital\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');
+2 -2
View File
@@ -1,7 +1,7 @@
<?php <?php
use Pixeldigital\Cart\Cart; use Wearepixel\Cart\Cart;
use Pixeldigital\Cart\Tests\Helpers\SessionMock; use Wearepixel\Cart\Tests\Helpers\SessionMock;
beforeEach(function () {}); beforeEach(function () {});
+2 -2
View File
@@ -1,7 +1,7 @@
<?php <?php
use Pixeldigital\Cart\Cart; use Wearepixel\Cart\Cart;
use Pixeldigital\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');
+6 -6
View File
@@ -1,9 +1,9 @@
<?php <?php
use Pixeldigital\Cart\Cart; use Wearepixel\Cart\Cart;
use Pixeldigital\Cart\CartCondition; use Wearepixel\Cart\CartCondition;
use Pixeldigital\Cart\Tests\Helpers\MockProduct; use Wearepixel\Cart\Tests\Helpers\MockProduct;
use Pixeldigital\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 \Pixeldigital\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(\Pixeldigital\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');
+2 -2
View File
@@ -1,7 +1,7 @@
<?php <?php
use Pixeldigital\Cart\Cart; use Wearepixel\Cart\Cart;
use Pixeldigital\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');