Skip to content

Commit

Permalink
Merge branch '5.x' into 5.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/base/Purchasable.php
  • Loading branch information
nfourtythree committed Aug 21, 2024
2 parents c28c295 + f6fdf0d commit 7d83ce8
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 20 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes for Craft Commerce

## Unreleased

- Fixed a bug where variant indexes weren’t displaying promotion prices as currency values.
- Fixed a PHP error that could occur when sending an order email. ([#3596](https://github.com/craftcms/commerce/issues/3596))
- Fixed a bug where dimension fields were not displaying values in the correct formatting locale. ([#3636](https://github.com/craftcms/commerce/issues/3636))
- Fixed a bug where users couldn’t access catalog pricing rules when the current user had permission. ([#3639](https://github.com/craftcms/commerce/issues/3639))
- Fixed a bug where available shipping methods were not returned in order of price. ([#3631](https://github.com/craftcms/commerce/issues/3631))

## 5.1.0-beta.2 - 2024-08-16

- Fixed a bug where it wasn’t possible to select shipping and tax categories for custom line items on the Edit Order page.
Expand Down Expand Up @@ -75,6 +83,10 @@
### System
- Craft Commerce now requires Craft CMS 5.2 or later.

## 5.0.16.2 - 2024-08-16

- Fixed a bug where variants’ `sku` values could be cleared out when saving a product revision.

## 5.0.16.1 - 2024-08-16

- Fixed a bug where variants’ `sku` values could be cleared out when saving a product.
Expand Down
39 changes: 34 additions & 5 deletions src/base/Purchasable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use craft\commerce\elements\Order;
use craft\commerce\errors\StoreNotFoundException;
use craft\commerce\helpers\Currency;
use craft\commerce\helpers\Localization;
use craft\commerce\helpers\Purchasable as PurchasableHelper;
use craft\commerce\models\InventoryItem;
use craft\commerce\models\InventoryLevel;
Expand Down Expand Up @@ -292,6 +293,34 @@ public function currencyAttributes(): array
];
}

/**
* @inheritdoc
*/
public function setAttributesFromRequest(array $values): void
{
$length = ArrayHelper::remove($values, 'length');
if ($length !== null) {
$this->length = $length ? (float)Localization::normalizeNumber($length) : null;
}

$width = ArrayHelper::remove($values, 'width');
if ($width !== null) {
$this->width = $width ? (float)Localization::normalizeNumber($width) : null;
}

$height = ArrayHelper::remove($values, 'height');
if ($height !== null) {
$this->height = $height ? (float)Localization::normalizeNumber($height) : null;
}

$weight = ArrayHelper::remove($values, 'weight');
if ($weight !== null) {
$this->weight = $weight ? (float)Localization::normalizeNumber($weight) : null;
}

$this->setAttributes($values);
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -927,7 +956,7 @@ public function afterSave(bool $isNew): void
$isOwnerDraftApplying = $owner && $owner->getIsCanonical() && $owner->duplicateOf !== null && $owner->duplicateOf->getIsDraft();
}

if ($this->duplicateOf !== null && !$isOwnerDraftApplying) {
if ($this->duplicateOf !== null && !$this->getIsRevision() && !$isOwnerDraftApplying) {
$this->sku = PurchasableHelper::tempSku() . '-' . $this->getSku();
// Nullify inventory item so a new one is created
$this->inventoryItemId = null;
Expand Down Expand Up @@ -1188,10 +1217,10 @@ protected function attributeHtml(string $attribute): string
'sku' => (string)Html::encode($this->getSkuAsText()),
'price' => $this->basePriceAsCurrency,
'promotionalPrice' => $this->basePromotionalPriceAsCurrency,
'weight' => $this->weight !== null ? Craft::$app->getLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->weightUnits : '',
'length' => $this->length !== null ? Craft::$app->getLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->dimensionUnits : '',
'width' => $this->width !== null ? Craft::$app->getLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->dimensionUnits : '',
'height' => $this->height !== null ? Craft::$app->getLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->dimensionUnits : '',
'weight' => $this->weight !== null ? Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->weightUnits : '',
'length' => $this->length !== null ? Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->dimensionUnits : '',
'width' => $this->width !== null ? Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->dimensionUnits : '',
'height' => $this->height !== null ? Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->dimensionUnits : '',
'minQty' => (string)$this->minQty,
'maxQty' => (string)$this->maxQty,
'stock' => $stock,
Expand Down
4 changes: 2 additions & 2 deletions src/elements/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ protected function attributeHtml(string $attribute): string
case 'defaultWeight':
{
if ($productType->hasDimensions) {
return Craft::$app->getLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->weightUnits;
return Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->weightUnits;
}

return '';
Expand All @@ -1586,7 +1586,7 @@ protected function attributeHtml(string $attribute): string
case 'defaultHeight':
{
if ($productType->hasDimensions) {
return Craft::$app->getLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->dimensionUnits;
return Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($this->$attribute) . ' ' . Plugin::getInstance()->getSettings()->dimensionUnits;
}

return '';
Expand Down
6 changes: 3 additions & 3 deletions src/fieldlayoutelements/PurchasableDimensionsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,23 @@ public function inputHtml(ElementInterface $element = null, bool $static = false
Cp::fieldHtml(Cp::textHtml([
'id' => 'length',
'name' => 'length',
'value' => $element->length !== null ? Craft::$app->getLocale()->getFormatter()->asDecimal($element->length) : '',
'value' => $element->length !== null ? Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($element->length) : '',
'class' => 'text',
'size' => 10,
'unit' => Plugin::getInstance()->getSettings()->dimensionUnits,
]), ['id' => 'length', 'label' => Craft::t('commerce', 'Length')]) .
Cp::fieldHtml(Cp::textHtml([
'id' => 'width',
'name' => 'width',
'value' => $element->width !== null ? Craft::$app->getLocale()->getFormatter()->asDecimal($element->width) : '',
'value' => $element->width !== null ? Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($element->width) : '',
'class' => 'text',
'size' => 10,
'unit' => Plugin::getInstance()->getSettings()->dimensionUnits,
]), ['id' => 'width', 'label' => Craft::t('commerce', 'Width')]) .
Cp::fieldHtml(Cp::textHtml([
'id' => 'height',
'name' => 'height',
'value' => $element->height !== null ? Craft::$app->getLocale()->getFormatter()->asDecimal($element->height) : '',
'value' => $element->height !== null ? Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($element->height) : '',
'class' => 'text',
'size' => 10,
'unit' => Plugin::getInstance()->getSettings()->dimensionUnits,
Expand Down
2 changes: 1 addition & 1 deletion src/fieldlayoutelements/PurchasableWeightField.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function inputHtml(ElementInterface $element = null, bool $static = false
return Cp::textHtml([
'id' => 'weight',
'name' => 'weight',
'value' => $element->weight !== null ? Craft::$app->getLocale()->getFormatter()->asDecimal($element->weight) : '',
'value' => $element->weight !== null ? Craft::$app->getFormattingLocale()->getFormatter()->asDecimal($element->weight) : '',
'class' => 'text',
'size' => 10,
'unit' => Plugin::getInstance()->getSettings()->weightUnits,
Expand Down
4 changes: 2 additions & 2 deletions src/models/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function getSenderAddress(bool $parse = true): ?string
}

if (!$senderAddress = App::parseEnv($this->_senderAddress)) {
$senderAddress = App::mailSettings()->fromEmail;
$senderAddress = App::parseEnv(App::mailSettings()->fromEmail);
}

return $senderAddress;
Expand Down Expand Up @@ -258,7 +258,7 @@ public function getSenderName(bool $parse = true): ?string
}

if (!$senderName = App::parseEnv($this->_senderName)) {
$senderName = App::mailSettings()->fromName;
$senderName = App::parseEnv(App::mailSettings()->fromName);
}

return $senderName;
Expand Down
4 changes: 2 additions & 2 deletions src/services/Pdfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Pdfs extends Component
public const EVENT_AFTER_SAVE_PDF = 'afterSavePdf';

/**
* @event PdfEvent The event that is triggered before an order’s PDF is rendered.
* @event PdfRenderEvent The event that is triggered before an order’s PDF is rendered.
*
* Event handlers can customize PDF rendering by modifying several properties on the event object:
*
Expand Down Expand Up @@ -136,7 +136,7 @@ class Pdfs extends Component
public const EVENT_BEFORE_RENDER_PDF = 'beforeRenderPdf';

/**
* @event PdfEvent The event that is triggered after an order’s PDF has been rendered.
* @event PdfRenderEvent The event that is triggered after an order’s PDF has been rendered.
*
* Event handlers can override Commerce’s PDF generation by setting the `pdf` property on the event to a custom-rendered PDF string. The event properties will be the same as those from `beforeRenderPdf`, but `pdf` will contain a rendered PDF string and is the only one for which setting a value will make any difference for the resulting PDF output.
*
Expand Down
2 changes: 1 addition & 1 deletion src/services/ShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getMatchingShippingMethods(Order $order): array

// Sort by price. Using the cached price and don't call `$method->getPriceForOrder($order);` again.
uasort($matchingMethods, static function($a, $b) {
return ($a['price'] < $b['price']) ? -1 : 1;
return $a['price'] <=> $b['price'];
});

$shippingMethods = [];
Expand Down
8 changes: 4 additions & 4 deletions src/templates/store-management/pricing-rules/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]) %}

{% block actionButton %}
{% if currentUser.can('commerce-createPricingCatalogRules') %}
{% if currentUser.can('commerce-createCatalogPricingRules') %}
<a href="{{ url("commerce/store-management/#{storeHandle}/pricing-rules/new") }}" class="btn submit add icon">{{ 'New catalog pricing rule'|t('commerce') }}</a>
{% endif %}
{% endblock %}
Expand Down Expand Up @@ -57,7 +57,7 @@

{% js %}
var actions = [
{% if currentUser.can('commerce-editPricingCatalogRules') %}
{% if currentUser.can('commerce-editCatalogPricingRules') %}
{
label: Craft.t('commerce', 'Set status'),
actions: [
Expand All @@ -78,7 +78,7 @@ var actions = [
]
},
{% endif %}
{% if currentUser.can('commerce-deletePricingCatalogRules') %}
{% if currentUser.can('commerce-deleteCatalogPricingRules') %}
{
label: Craft.t('commerce', 'Delete'),
action: 'commerce/catalog-pricing-rules/delete',
Expand Down Expand Up @@ -106,7 +106,7 @@ new Craft.VueAdminTable({
columns: columns,
fullPane: false,
container: '#pcr-vue-admin-table',
deleteAction: {{ currentUser.can('commerce-deletePricingCatalogRules')? '"commerce/catalog-pricing-rules/delete"' : 'null' }},
deleteAction: {{ currentUser.can('commerce-deleteCatalogPricingRules')? '"commerce/catalog-pricing-rules/delete"' : 'null' }},
emptyMessage: Craft.t('commerce', 'No catalog pricing rules exist yet.'),
padded: true,
tableData: {{ tableData|json_encode|raw }}
Expand Down

0 comments on commit 7d83ce8

Please sign in to comment.