Skip to content

Commit 98bc98d

Browse files
committed
Potential fix for #4180
1 parent 3ca0c93 commit 98bc98d

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

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)