Skip to content

Commit

Permalink
Fixed #620
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Oct 18, 2019
1 parent 3177f9d commit e5861e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added `craft\commerce\test\fixtures\elements\ProductFixture`. ([#1009](https://github.com/craftcms/commerce/pull/1009))
- Added “Customer Info” tab to Edit User page, its appearance can be controlled with `showCustomerTabOnEditUser` Commerce setting.
- Added the `activeCartDuration` setting to determine if a cart should show as inactive on the Order index page. ([#959](https://github.com/craftcms/commerce/issues/959))
- Added the `allowEmptyCartOnCheckout` setting to determine if a customer can check out with an empty cart. ([#620](https://github.com/craftcms/commerce/issues/620))
- Added `getActiveCarts` and `getInactiveCarts` to the customer model.
- Added the ability to delete customer addresses from the customer info tab on the Edit User page. ([#171](https://github.com/craftcms/commerce/issues/171))

Expand Down
21 changes: 16 additions & 5 deletions src/controllers/PaymentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Craft;
use craft\commerce\base\Gateway;
use craft\commerce\elements\Order;
use craft\commerce\errors\CurrencyException;
use craft\commerce\errors\PaymentException;
use craft\commerce\errors\PaymentSourceException;
Expand Down Expand Up @@ -53,13 +54,13 @@ public function actionPay()
$this->requirePostRequest();

$customError = '';
$order = null;

$plugin = Plugin::getInstance();
$request = Craft::$app->getRequest();
$session = Craft::$app->getSession();

if (($number = $request->getBodyParam('orderNumber')) !== null) {
/** @var Order $order */
$order = $plugin->getOrders()->getOrderByNumber($number);

if (!$order) {
Expand All @@ -73,10 +74,8 @@ public function actionPay()

return null;
}
}

// Get the cart if no order number was passed.
if (!$order) {
} else {
/** @var Order $order */
$order = $plugin->getCarts()->getCart(true);
}

Expand Down Expand Up @@ -120,6 +119,18 @@ public function actionPay()
return null;
}

if (!$plugin->getSettings()->allowEmptyCartOnCheckout && $order->getIsEmpty()) {
$error = Craft::t('commerce', 'Order can not be empty.');

if ($request->getAcceptsJson()) {
return $this->asErrorJson($error);
}

$session->setError($error);

return null;
}

// Set if the customer should be registered on order completion
if ($request->getBodyParam('registerUserOnOrderComplete')) {
$order->registerUserOnOrderComplete = true;
Expand Down
6 changes: 6 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class Settings extends Model
*/
public $autoSetNewCartAddresses = true;

/**
* @var bool Allow the cart to be empty on checkout
* @todo Set this to false in 3.0
*/
public $allowEmptyCartOnCheckout = true;

/**
* @var bool
*/
Expand Down

0 comments on commit e5861e2

Please sign in to comment.