Skip to content

Commit eca2ee3

Browse files
committed
Merge branch '5.x' of github.com:craftcms/commerce into 5.x
2 parents 35575a5 + 06c37ff commit eca2ee3

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Fixed a bug where tax and shipping categories weren’t getting saved on the Edit variant screen. ([#4180](https://github.com/craftcms/commerce/issues/4180))
56
- Fixed a bug where newly created variants weren’t visible on Edit product screens.
67
- Fixed a SQL error that could occur when viewing product indexes.
78
- Fixed a PHP error that occurred when applying project config changes after updating. ([#4185](https://github.com/craftcms/commerce/issues/4185))

src/base/Purchasable.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,22 @@ function($attribute, $params, Validator $validator) use ($lineItem, $lineItemQua
902902
*/
903903
public function setAttributes($values, $safeOnly = true): void
904904
{
905-
// Normalize empty strings to null for category IDs before setting
906-
if (isset($values['taxCategoryId']) && $values['taxCategoryId'] === '') {
907-
$values['taxCategoryId'] = null;
905+
// Normalize category IDs - handle arrays from componentSelect and empty strings
906+
if (isset($values['taxCategoryId'])) {
907+
if (is_array($values['taxCategoryId'])) {
908+
$values['taxCategoryId'] = reset($values['taxCategoryId']) ?: null;
909+
}
910+
if ($values['taxCategoryId'] === '') {
911+
$values['taxCategoryId'] = null;
912+
}
908913
}
909-
if (isset($values['shippingCategoryId']) && $values['shippingCategoryId'] === '') {
910-
$values['shippingCategoryId'] = null;
914+
if (isset($values['shippingCategoryId'])) {
915+
if (is_array($values['shippingCategoryId'])) {
916+
$values['shippingCategoryId'] = reset($values['shippingCategoryId']) ?: null;
917+
}
918+
if ($values['shippingCategoryId'] === '') {
919+
$values['shippingCategoryId'] = null;
920+
}
911921
}
912922

913923
parent::setAttributes($values, $safeOnly);

0 commit comments

Comments
 (0)