Skip to content

Commit

Permalink
Handle submission of all 0 quantities gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
bossanova808 committed Apr 20, 2016
1 parent 7227ca0 commit a1665ab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ This plugin has been tested with Craft 2.5 and Craft Commerce 1.0.1187.

## Changelog

0.0.8
* [Fixed] Handle submissions with all zero quantities more gracefully

0.0.7
* [Added] Add custom events similar to the standard Commerce add to cart events.
* [Fixed] Improved the documentation a bit based on recent Slack chats
Expand Down
2 changes: 1 addition & 1 deletion multiadd/MultiAddPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getName()

public function getVersion()
{
return '0.0.7';
return '0.0.8';
}

public function getDeveloper()
Expand Down
17 changes: 17 additions & 0 deletions multiadd/controllers/MultiAddController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,24 @@ public function actionMultiAdd()
$errors[] = "No items?";
craft()->urlManager->setRouteVariables(['error' => 'No items?']);
}

//prevent submission of all 0 qtys
$itemsToProcess = false;
foreach ($items as $key => $item) {
$qty = isset($item['qty']) ? (int)$item['qty'] : 0;
if ($qty >0){
$itemsToProcess = true;
break;
}
}

if(!$itemsToProcess){
$errors[] = "All items have 0 quantity?";
craft()->urlManager->setRouteVariables(['error' => 'No items?']);
}
else {


// Do some cart-adding using our new, faster, rollback-able service
if (!$errors) {
$error = "";
Expand Down
2 changes: 1 addition & 1 deletion multiadd/services/MultiAdd_CartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function multiAddToCart($order, $items, &$error = '')
//Be bold, be brave, assume success...!
$success = true;

//raising event - passes in only the first line item which isn't ideal...
//raising event
$event = new Event($this, [
'lineItems' => $lineItems,
'order' => $order,
Expand Down

0 comments on commit a1665ab

Please sign in to comment.