← All changes
|
includes/Admin/Product/Data/Services/AttributeService.php
+17
-5
1.10.4
→
1.10.27
View file →
| @@ -24,19 +24,31 @@ | ||
| 24 | 24 | $isEnabled = syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_ENABLED); |
| 25 | 25 | |
| 26 | 26 | if ($isEnabled !== 'yes') return null; |
| 27 | 27 | |
| 28 | - $attributeName = trim(syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_PRIORITY)); | |
| 28 | + $configuredNames = (string) syncBasalamSettings()->getSettings(SettingsConfig::PRODUCT_ATTRIBUTE_SUFFIX_PRIORITY); | |
| 29 | + $attributeNames = array_unique(array_filter( | |
| 30 | + array_map('trim', preg_split('/[,،]/u', $configuredNames)), | |
| 31 | + static function ($name) { return $name !== ''; } | |
| 32 | + )); | |
| 29 | 33 | |
| 30 | - if (empty($attributeName)) return null; | |
| 34 | + if (empty($attributeNames)) return null; | |
| 31 | 35 | |
| 32 | 36 | $wooAttributes = $this->getWooCommerceAttributes($product); |
| 37 | + $suffixValues = []; | |
| 33 | 38 | |
| 34 | - foreach ($wooAttributes as $attribute) { | |
| 35 | - if (trim($attribute['title']) === $attributeName && !empty($attribute['value'])) return $attribute['value']; | |
| 39 | + // Follow the configured order, regardless of the product's attribute order. | |
| 40 | + foreach ($attributeNames as $attributeName) { | |
| 41 | + foreach ($wooAttributes as $attribute) { | |
| 42 | + $value = trim($attribute['value']); | |
| 43 | + if (trim($attribute['title']) === $attributeName && $value !== '') { | |
| 44 | + $suffixValues[] = $value; | |
| 45 | + break; | |
| 46 | + } | |
| 47 | + } | |
| 36 | 48 | } |
| 37 | 49 | |
| 38 | - return null; | |
| 50 | + return empty($suffixValues) ? null : implode(', ', $suffixValues); | |
| 39 | 51 | } |
| 40 | 52 | |
| 41 | 53 | public function generateDescription($product): string |
| 42 | 54 | { |