- {% if not cart.shippingMethod %}
+ {% if not cart.shippingMethodName %}
{{ 'None selected.'|t }}
{{- 'Choose a shipping method.'|t -}}
diff --git a/example-templates/src/shop/checkout/_includes/order-summary.twig b/example-templates/src/shop/checkout/_includes/order-summary.twig
index 6d424923bc..6c1934f77e 100644
--- a/example-templates/src/shop/checkout/_includes/order-summary.twig
+++ b/example-templates/src/shop/checkout/_includes/order-summary.twig
@@ -71,7 +71,7 @@
{{- 'Shipping Method'|t -}}
- {% if not cart.shippingMethod %}
+ {% if not cart.shippingMethodName %}
{{ 'None selected.'|t }}
{{- 'Choose a shipping method.'|t -}}
diff --git a/src/elements/Order.php b/src/elements/Order.php
index 9355746282..6cebff8a53 100644
--- a/src/elements/Order.php
+++ b/src/elements/Order.php
@@ -1766,8 +1766,11 @@ public function recalculate()
if (!$this->shippingMethodHandle) {
$this->shippingMethodName = null;
- } elseif ($shippingMethod = $this->getShippingMethod()) {
- $this->shippingMethodName = $shippingMethod->getName();
+ } else {
+ $shippingMethod = ArrayHelper::firstWhere($this->getAvailableShippingMethodOptions(), 'handle', $this->shippingMethodHandle);
+ if ($shippingMethod) {
+ $this->shippingMethodName = $shippingMethod->getName();
+ }
}
$lineItemRemoved = false;
@@ -1878,10 +1881,23 @@ public function getAvailableShippingMethodOptions(): array
$attributes = (new ShippingMethod())->attributes();
foreach ($availableMethods as $method) {
- $option = new ShippingMethodOption($method->getAttributes($attributes));
+ $option = new ShippingMethodOption();
+
+ if ($method instanceof ShippingMethod) {
+ // TODO remove at a breaking change version
+ foreach (['dateCreated', 'dateUpdated'] as $attribute) {
+ $option->$attribute = $method->$attribute;
+ }
+ }
+
$option->setOrder($this);
- $option->matchesOrder = true;
+ $option->enabled = $method->getIsEnabled();
+ $option->id = $method->getId();
+ $option->name = $method->getName();
+ $option->handle = $method->getHandle();
+ $option->matchesOrder = ArrayHelper::isIn($method->handle, $availableMethods);
$option->price = $method->getPriceForOrder($this);
+
$options[$option->getHandle()] = $option;
}
@@ -3034,6 +3050,7 @@ public function getShippingMethodId()
/**
* @return ShippingMethod|null
+ * @deprected in 3.4.18. Use `$shippingMethodHandle` or `$shippingMethodName` instead.
*/
public function getShippingMethod()
{