Skip to content

Commit 772d889

Browse files
committed
Fix #4213
1 parent 95e5eed commit 772d889

File tree

14 files changed

+97
-29
lines changed

14 files changed

+97
-29
lines changed

src/controllers/OrdersController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
use craft\commerce\helpers\PaymentForm;
3636
use craft\commerce\helpers\Purchasable;
3737
use craft\commerce\models\inventory\InventoryFulfillMovement;
38+
use craft\commerce\models\LineItemStatus;
3839
use craft\commerce\models\OrderAdjustment;
3940
use craft\commerce\models\OrderNotice;
41+
use craft\commerce\models\OrderStatus;
4042
use craft\commerce\models\Pdf;
4143
use craft\commerce\models\Transaction;
4244
use craft\commerce\Plugin;
@@ -1456,13 +1458,18 @@ private function _registerJavascript(array $variables): void
14561458

14571459
Craft::$app->getView()->registerJs('window.orderEdit.orderId = ' . $order->id . ';', View::POS_BEGIN);
14581460

1459-
$orderStatuses = Plugin::getInstance()->getOrderStatuses()->getAllOrderStatuses($order->storeId)->all();
1461+
$orderStatuses = Plugin::getInstance()->getOrderStatuses()->getAllOrderStatuses($order->storeId)
1462+
->map(fn(OrderStatus $orderStatus) => $orderStatus->toArray(expand: ['uiLabel']))
1463+
->all();
14601464
Craft::$app->getView()->registerJs('window.orderEdit.orderStatuses = ' . Json::encode($orderStatuses) . ';', View::POS_BEGIN);
14611465

14621466
$orderSites = $order->getStore()->getSites()->all();
14631467
Craft::$app->getView()->registerJs('window.orderEdit.orderSites = ' . Json::encode(array_values($orderSites)) . ';', View::POS_BEGIN);
14641468

1465-
$lineItemStatuses = Plugin::getInstance()->getLineItemStatuses()->getAllLineItemStatuses($order->storeId)->all();
1469+
$lineItemStatuses = Plugin::getInstance()->getLineItemStatuses()->getAllLineItemStatuses($order->storeId)
1470+
->map(fn(LineItemStatus $lineItemStatus) => $lineItemStatus->toArray(expand: ['uiLabel']))
1471+
->all();
1472+
14661473
Craft::$app->getView()->registerJs('window.orderEdit.lineItemStatuses = ' . Json::encode($lineItemStatuses) . ';', View::POS_BEGIN);
14671474

14681475
$lineItemTypes = LineItemType::types();

src/models/LineItemStatus.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
namespace craft\commerce\models;
99

1010
use Craft;
11+
use craft\base\Chippable;
1112
use craft\commerce\base\HasStoreInterface;
1213
use craft\commerce\base\Model;
1314
use craft\commerce\base\StoreTrait;
15+
use craft\commerce\behaviors\StoreBehavior;
16+
use craft\commerce\Plugin;
1417
use craft\commerce\records\LineItemStatus as LineItemStatusRecord;
1518
use craft\helpers\Cp;
1619
use craft\helpers\Html;
1720
use craft\helpers\UrlHelper;
21+
use craft\models\Site;
1822
use craft\validators\HandleValidator;
1923
use craft\validators\UniqueValidator;
2024
use DateTime;
@@ -30,7 +34,7 @@
3034
* @author Pixel & Tonic, Inc. <[email protected]>
3135
* @since 2.0
3236
*/
33-
class LineItemStatus extends Model implements HasStoreInterface
37+
class LineItemStatus extends Model implements HasStoreInterface, Chippable
3438
{
3539
use StoreTrait;
3640

@@ -84,13 +88,10 @@ class LineItemStatus extends Model implements HasStoreInterface
8488
*/
8589
public function __toString()
8690
{
87-
return $this->getDisplayName();
91+
return $this->getUiLabel();
8892
}
8993

90-
/**
91-
* @since 5.5.3
92-
*/
93-
public function getDisplayName(): string
94+
public function getUiLabel(): string
9495
{
9596
return Craft::t('site', $this->name ?? '');
9697
}
@@ -136,6 +137,7 @@ public function extraFields(): array
136137
{
137138
$fields = parent::extraFields();
138139
$fields[] = 'labelHtml';
140+
$fields[] = 'uiLabel';
139141

140142
return $fields;
141143
}
@@ -151,7 +153,7 @@ public function getCpEditUrl(): string
151153
public function getLabelHtml(): string
152154
{
153155
return Cp::statusLabelHtml([
154-
'label' => Html::encode($this->getDisplayName()),
156+
'label' => Html::encode($this->getUiLabel()),
155157
'color' => Html::encode($this->color),
156158
]);
157159
}
@@ -172,4 +174,25 @@ public function getConfig(): array
172174
'default' => $this->default,
173175
];
174176
}
177+
178+
/**
179+
* @inheritdoc
180+
*/
181+
public static function get(int|string $id): ?static
182+
{
183+
/** @var Site|StoreBehavior|null $site */
184+
$site = Cp::requestedSite();
185+
$storeId = $site?->getStore()->id ?? null;
186+
187+
/** @phpstan-ignore-next-line */
188+
return Plugin::getInstance()->getLineItemStatuses()->getLineItemStatusById($id, $storeId);
189+
}
190+
191+
/**
192+
* @inheritdoc
193+
*/
194+
public function getId(): string|int|null
195+
{
196+
return $this->id;
197+
}
175198
}

src/models/OrderStatus.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
namespace craft\commerce\models;
99

1010
use Craft;
11+
use craft\base\Chippable;
1112
use craft\commerce\base\HasStoreInterface;
1213
use craft\commerce\base\Model;
1314
use craft\commerce\base\StoreTrait;
15+
use craft\commerce\behaviors\StoreBehavior;
1416
use craft\commerce\db\Table;
1517
use craft\commerce\elements\db\OrderQuery;
1618
use craft\commerce\elements\Order;
@@ -21,6 +23,7 @@
2123
use craft\helpers\Db;
2224
use craft\helpers\Html;
2325
use craft\helpers\UrlHelper;
26+
use craft\models\Site;
2427
use craft\validators\HandleValidator;
2528
use craft\validators\UniqueValidator;
2629
use DateTime;
@@ -37,7 +40,7 @@
3740
* @author Pixel & Tonic, Inc. <[email protected]>
3841
* @since 2.0
3942
*/
40-
class OrderStatus extends Model implements HasStoreInterface
43+
class OrderStatus extends Model implements HasStoreInterface, Chippable
4144
{
4245
use SoftDeleteTrait {
4346
SoftDeleteTrait::behaviors as softDeleteBehaviors;
@@ -99,13 +102,22 @@ public function behaviors(): array
99102
*/
100103
public function __toString()
101104
{
102-
return $this->getDisplayName();
105+
return $this->getUiLabel();
103106
}
104107

105108
/**
106109
* @since 2.2
110+
* @deprecated in 5.6. Use [[getUiLabel()]] instead.
107111
*/
108112
public function getDisplayName(): string
113+
{
114+
return $this->getUiLabel();
115+
}
116+
117+
/**
118+
* @inheritdoc
119+
*/
120+
public function getUiLabel(): string
109121
{
110122
if ($this->dateDeleted !== null) {
111123
return Craft::t('commerce', '{name} (Trashed)', ['name' => Craft::t('site', $this->name)]);
@@ -114,6 +126,7 @@ public function getDisplayName(): string
114126
return Craft::t('site', $this->name ?? '');
115127
}
116128

129+
117130
protected function defineRules(): array
118131
{
119132
return [
@@ -142,6 +155,7 @@ public function extraFields(): array
142155
$fields[] = 'emails';
143156
$fields[] = 'emailIds';
144157
$fields[] = 'labelHtml';
158+
$fields[] = 'uiLabel';
145159

146160
return $fields;
147161
}
@@ -172,7 +186,7 @@ public function getLabelHtml(): string
172186
{
173187
return Cp::statusLabelHtml([
174188
'color' => Html::encode($this->color),
175-
'label' => Html::encode($this->getDisplayName()),
189+
'label' => Html::encode($this->getUiLabel()),
176190
]);
177191
}
178192

@@ -209,4 +223,25 @@ public function getConfig(?array $emailIds = null): array
209223
'store' => $this->getStore()->uid,
210224
];
211225
}
226+
227+
/**
228+
* @inheritdoc
229+
*/
230+
public static function get(int|string $id): ?static
231+
{
232+
/** @var Site|StoreBehavior|null $site */
233+
$site = Cp::requestedSite();
234+
$storeId = $site?->getStore()->id ?? null;
235+
236+
/** @phpstan-ignore-next-line */
237+
return Plugin::getInstance()->getOrderStatuses()->getOrderStatusById($id, $storeId);
238+
}
239+
240+
/**
241+
* @inheritdoc
242+
*/
243+
public function getId(): string|int|null
244+
{
245+
return $this->id;
246+
}
212247
}

src/models/ShippingCategory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public function extraFields(): array
224224
$fields = parent::extraFields();
225225
$fields[] = 'productTypes';
226226
$fields[] = 'productTypeIds';
227+
$fields[] = 'uiLabel';
227228

228229
return $fields;
229230
}

src/services/ShippingCategories.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function getAllShippingCategoriesAsList(?int $storeId = null): array
9494
{
9595
$categories = $this->getAllShippingCategories($storeId);
9696

97-
return $categories->mapWithKeys(fn(ShippingCategory $category) => [$category->id => $category->name])->all();
97+
return $categories->mapWithKeys(fn(ShippingCategory $category) => [$category->id => $category->getUiLabel()])->all();
9898
}
9999

100100
/**
@@ -205,11 +205,11 @@ public function saveShippingCategory(ShippingCategory $shippingCategory, bool $r
205205

206206
// Find product types that are being removed from this shipping category
207207
$removedProductTypeIds = array_diff($currentProductTypeIds, $newProductTypeIds);
208-
208+
209209
// Update purchasables to default shipping category when product types are removed
210210
if (!empty($removedProductTypeIds)) {
211211
$defaultShippingCategory = $this->getDefaultShippingCategory($shippingCategory->storeId);
212-
212+
213213
// Get all variant purchasables that currently have this shipping category but whose product type is being removed
214214
$purchasableIds = (new Query())
215215
->select(['ps.purchasableId'])
@@ -222,7 +222,7 @@ public function saveShippingCategory(ShippingCategory $shippingCategory, bool $r
222222
'p.typeId' => $removedProductTypeIds,
223223
])
224224
->column();
225-
225+
226226
if (!empty($purchasableIds)) {
227227
// Update these purchasables to use the default shipping category
228228
Craft::$app->getDb()->createCommand()

src/services/TaxCategories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getAllTaxCategoriesAsList(): array
9595
{
9696
$categories = $this->getAllTaxCategories();
9797

98-
return ArrayHelper::map($categories, 'id', 'name');
98+
return ArrayHelper::map($categories, 'id', 'uiLabel');
9999
}
100100

101101
/**

src/web/assets/commerceui/dist/css/order.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/dist/css/order.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/dist/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/dist/js/app.js.LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
/**!
26-
* Sortable 1.15.0
26+
* Sortable 1.15.6
2727
* @author RubaXa <[email protected]>
2828
* @author owenm <[email protected]>
2929
* @license MIT

0 commit comments

Comments
 (0)