Skip to content

Commit

Permalink
Merge branch '5.0' of https://github.com/craftcms/commerce into 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Feb 29, 2024
2 parents 51273c0 + 7495b53 commit e5019d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/controllers/StoresController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Craft;
use craft\commerce\db\Table;
use craft\commerce\elements\Order;
use craft\commerce\models\Store;
use craft\commerce\Plugin;
use craft\db\Query;
Expand Down Expand Up @@ -44,6 +45,7 @@ public function actionEditStore(?int $storeId = null, ?Store $storeModel = null)
$storesService = Plugin::getInstance()->getStores();

$brandNewStore = false;
$allowCurrencyChange = false;

if ($storeId !== null) {
if ($storeModel === null) {
Expand All @@ -59,6 +61,7 @@ public function actionEditStore(?int $storeId = null, ?Store $storeModel = null)
if ($storeModel === null) {
$storeModel = new Store();
$brandNewStore = true;
$allowCurrencyChange = true;
}

$title = Craft::t('app', 'Create a new Store');
Expand All @@ -76,6 +79,11 @@ public function actionEditStore(?int $storeId = null, ?Store $storeModel = null)
],
];

$storeHasOrders = $storeModel->id && (new Query())->from(Table::ORDERS)->where(['storeId' => $storeModel->id])->exists();
if (!$storeHasOrders) {
$allowCurrencyChange = true;
}

// map sites into select box options array
$availableSiteOptions = collect(Craft::$app->getSites()->getAllSites())->map(function($site) {
$availableForAssignmentToNewStores = Plugin::getInstance()->getStores()->getSiteIdsAvailableForAssignmentToNewStores();
Expand All @@ -90,6 +98,7 @@ public function actionEditStore(?int $storeId = null, ?Store $storeModel = null)

return $this->renderTemplate('commerce/settings/stores/_edit', [
'brandNewStore' => $brandNewStore,
'allowCurrencyChange' => $allowCurrencyChange,
'title' => $title,
'crumbs' => $crumbs,
'store' => $storeModel,
Expand Down
2 changes: 2 additions & 0 deletions src/templates/settings/stores/_edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
value: null,
options: availableSiteOptions,
}) }}
{% endif %}

{% if allowCurrencyChange %}
{{ forms.selectField({
label: "Currency"|t('commerce'),
id: 'currency',
Expand Down

0 comments on commit e5019d7

Please sign in to comment.