mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
fix tests & validation errors
This commit is contained in:
+11
-5
@@ -153,7 +153,7 @@ public function add(
|
||||
$this->add(
|
||||
$item['id'],
|
||||
$item['name'],
|
||||
$item['price'],
|
||||
isset($item['price']) ? $item['price'] : null,
|
||||
$item['quantity'],
|
||||
Helpers::issetAndHasValueOrAssignDefault($item['attributes'], []),
|
||||
Helpers::issetAndHasValueOrAssignDefault($item['conditions'], []),
|
||||
@@ -164,8 +164,7 @@ public function add(
|
||||
$this->add(
|
||||
$id['id'],
|
||||
$id['name'],
|
||||
// isset($id['price']) ? $id['price'] : null,
|
||||
$id['price'],
|
||||
isset($id['price']) ? $id['price'] : null,
|
||||
$id['quantity'],
|
||||
Helpers::issetAndHasValueOrAssignDefault($id['attributes'], []),
|
||||
Helpers::issetAndHasValueOrAssignDefault($id['conditions'], []),
|
||||
@@ -706,8 +705,15 @@ protected function validate($item)
|
||||
$validator = CartItemValidator::make($item, $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
// if the error is due to quantity
|
||||
if ($validator->errors()->first('quantity') === 'The quantity must be at least 0.1.') {
|
||||
if ($validator->errors()->first('id') === 'validation.required') {
|
||||
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.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user