mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61475a7060 | ||
|
|
6604cf984d |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wearepixel/laravel-cart",
|
"name": "wearepixel/laravel-cart",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"description": "A cart implementation for Laravel",
|
"description": "A cart implementation for Laravel",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"laravel",
|
"laravel",
|
||||||
|
|||||||
+11
-5
@@ -153,7 +153,7 @@ public function add(
|
|||||||
$this->add(
|
$this->add(
|
||||||
$item['id'],
|
$item['id'],
|
||||||
$item['name'],
|
$item['name'],
|
||||||
$item['price'],
|
isset($item['price']) ? $item['price'] : null,
|
||||||
$item['quantity'],
|
$item['quantity'],
|
||||||
Helpers::issetAndHasValueOrAssignDefault($item['attributes'], []),
|
Helpers::issetAndHasValueOrAssignDefault($item['attributes'], []),
|
||||||
Helpers::issetAndHasValueOrAssignDefault($item['conditions'], []),
|
Helpers::issetAndHasValueOrAssignDefault($item['conditions'], []),
|
||||||
@@ -164,8 +164,7 @@ public function add(
|
|||||||
$this->add(
|
$this->add(
|
||||||
$id['id'],
|
$id['id'],
|
||||||
$id['name'],
|
$id['name'],
|
||||||
// isset($id['price']) ? $id['price'] : null,
|
isset($id['price']) ? $id['price'] : null,
|
||||||
$id['price'],
|
|
||||||
$id['quantity'],
|
$id['quantity'],
|
||||||
Helpers::issetAndHasValueOrAssignDefault($id['attributes'], []),
|
Helpers::issetAndHasValueOrAssignDefault($id['attributes'], []),
|
||||||
Helpers::issetAndHasValueOrAssignDefault($id['conditions'], []),
|
Helpers::issetAndHasValueOrAssignDefault($id['conditions'], []),
|
||||||
@@ -706,8 +705,15 @@ protected function validate($item)
|
|||||||
$validator = CartItemValidator::make($item, $rules);
|
$validator = CartItemValidator::make($item, $rules);
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
// if the error is due to quantity
|
if ($validator->errors()->first('id') === 'validation.required') {
|
||||||
if ($validator->errors()->first('quantity') === 'The quantity must be at least 0.1.') {
|
throw new InvalidItemException('The id field is required.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($validator->errors()->first('name') === 'validation.required') {
|
||||||
|
throw new InvalidItemException('The name field is required.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($validator->errors()->first('quantity') === 'validation.min.numeric') {
|
||||||
throw new InvalidItemException('The quantity must be at least 0.1.');
|
throw new InvalidItemException('The quantity must be at least 0.1.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-16
@@ -60,7 +60,7 @@
|
|||||||
expect($this->cart->getContent()->count())->toEqual(1, 'Cart content should be 1');
|
expect($this->cart->getContent()->count())->toEqual(1, 'Cart content should be 1');
|
||||||
expect($this->cart->getContent()->first()['id'])->toEqual(455, 'Item added has ID of 455 so first content ID should be 455');
|
expect($this->cart->getContent()->first()['id'])->toEqual(455, 'Item added has ID of 455 so first content ID should be 455');
|
||||||
expect($this->cart->getTotal())->toEqual(0, 'Total should be 0');
|
expect($this->cart->getTotal())->toEqual(0, 'Total should be 0');
|
||||||
})->only();
|
});
|
||||||
|
|
||||||
test('can add an item without attributes', function () {
|
test('can add an item without attributes', function () {
|
||||||
$item = [
|
$item = [
|
||||||
@@ -296,6 +296,24 @@
|
|||||||
|
|
||||||
expect($item['quantity'])->toEqual(9.9, 'Item quantity should be 9.9');
|
expect($item['quantity'])->toEqual(9.9, 'Item quantity should be 9.9');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should throw an exception when no quantity is provided', function () {
|
||||||
|
$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('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('Wearepixel\Cart\Exceptions\InvalidItemException');
|
||||||
|
$this->expectExceptionMessage('The name field is required.');
|
||||||
|
$this->cart->add(523, '', 100.99, 2, []);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cart items attributes', function () {
|
test('cart items attributes', function () {
|
||||||
@@ -555,21 +573,6 @@
|
|||||||
expect($item['quantity'])->toEqual(3, 'Item quantity of with item ID of 456 should now be reduced to 2');
|
expect($item['quantity'])->toEqual(3, 'Item quantity of with item ID of 456 should now be reduced to 2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw exception when provided invalid values scenario one', function () {
|
|
||||||
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
|
|
||||||
$this->cart->add(455, 'Sample Item', 100.99, 0, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw exception when provided invalid values scenario two', function () {
|
|
||||||
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
|
|
||||||
$this->cart->add('', 'Sample Item', 100.99, 2, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw exception when provided invalid values scenario three', function () {
|
|
||||||
$this->expectException('Wearepixel\Cart\Exceptions\InvalidItemException');
|
|
||||||
$this->cart->add(523, '', 100.99, 2, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('clearing cart', function () {
|
test('clearing cart', function () {
|
||||||
$items = [
|
$items = [
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user