From abb3ee46806dcf8e9611226060df8d3d477e56b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 20:33:15 +0000 Subject: [PATCH 1/9] Initial plan From be38022225e5d069bbf48d4c098e0a6fd692fafa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 20:38:55 +0000 Subject: [PATCH 2/9] Separate product detail and listing swatch configuration checks Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com> --- .../Block/Catalog/Media/Js/Abstract.php | 5 ++++- .../Product/View/Type/Configurable/Swatches.php | 2 +- .../Mage/ConfigurableSwatches/Helper/Data.php | 16 ++++++++++++++-- .../ConfigurableSwatches/Helper/Productimg.php | 5 ++++- .../Mage/ConfigurableSwatches/Model/Observer.php | 10 ++++++++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Media/Js/Abstract.php b/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Media/Js/Abstract.php index 99f4f6920bf..c6290366cac 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Media/Js/Abstract.php +++ b/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Media/Js/Abstract.php @@ -119,7 +119,10 @@ public function getImageType() */ protected function _toHtml() { - if (!Mage::helper('configurableswatches')->isEnabled()) { // functionality disabled + // Check if swatches are enabled for either listing or product detail + if (!Mage::helper('configurableswatches')->isEnabled() + && !Mage::helper('configurableswatches')->isEnabledForProductDetail() + ) { return ''; // do not render block } diff --git a/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php b/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php index 2eeaa8cc3f4..915909f92c0 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php +++ b/app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php @@ -31,7 +31,7 @@ class Mage_ConfigurableSwatches_Block_Catalog_Product_View_Type_Configurable_Swa */ public function shouldRender($attribute, $jsonConfig) { - if (Mage::helper('configurableswatches')->isEnabled()) { + if (Mage::helper('configurableswatches')->isEnabledForProductDetail()) { if (Mage::helper('configurableswatches')->attrIsSwatchType($attribute->getProductAttribute())) { $this->_init($jsonConfig); return true; diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php index 4c812e5a917..4a21f7baa4e 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php @@ -27,7 +27,8 @@ class Mage_ConfigurableSwatches_Helper_Data extends Mage_Core_Helper_Abstract protected $_configAttributeIds = null; /** - * Is the extension enabled? + * Is the extension enabled for product listing? + * Requires both general enabled flag and listing attribute to be set. * * @return bool */ @@ -43,6 +44,17 @@ public function isEnabled() return $this->_enabled; } + /** + * Is the extension enabled for product detail page? + * Only requires general enabled flag, independent of listing configuration. + * + * @return bool + */ + public function isEnabledForProductDetail() + { + return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED); + } + /** * Return the formatted hyphenated string * @@ -126,7 +138,7 @@ public function getSwatchesProductJs() { /** @var Mage_Catalog_Model_Product $product */ $product = Mage::registry('current_product'); - if ($this->isEnabled() && $product) { + if ($this->isEnabledForProductDetail() && $product) { $configAttrs = $this->getSwatchAttributeIds(); /** @var Mage_Catalog_Model_Product_Type_Configurable $productType */ $productType = $product->getTypeInstance(true); diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php index 0dac68479fc..55e64b2f8ca 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php @@ -377,7 +377,10 @@ public function clearSwatchesCache() */ public function filterImageInGallery($product, $image) { - if (!Mage::helper('configurableswatches')->isEnabled()) { + // Check if swatches are enabled for either listing or product detail + if (!Mage::helper('configurableswatches')->isEnabled() + && !Mage::helper('configurableswatches')->isEnabledForProductDetail() + ) { return true; } diff --git a/app/code/core/Mage/ConfigurableSwatches/Model/Observer.php b/app/code/core/Mage/ConfigurableSwatches/Model/Observer.php index 22de7d04409..569823e4b66 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Model/Observer.php +++ b/app/code/core/Mage/ConfigurableSwatches/Model/Observer.php @@ -65,7 +65,10 @@ public function productListCollectionLoadAfter(Varien_Event_Observer $observer) */ public function productLoadAfter(Varien_Event_Observer $observer) { - if (!Mage::helper('configurableswatches')->isEnabled()) { // functionality disabled + // Check if swatches are enabled for either listing or product detail + if (!Mage::helper('configurableswatches')->isEnabled() + && !Mage::helper('configurableswatches')->isEnabledForProductDetail() + ) { return; // exit without loading swatch functionality } @@ -91,7 +94,10 @@ public function productLoadAfter(Varien_Event_Observer $observer) */ public function loadChildProductImagesOnMediaLoad(Varien_Event_Observer $observer) { - if (!Mage::helper('configurableswatches')->isEnabled()) { // functionality disabled + // Check if swatches are enabled for either listing or product detail + if (!Mage::helper('configurableswatches')->isEnabled() + && !Mage::helper('configurableswatches')->isEnabledForProductDetail() + ) { return; // exit without loading swatch functionality } From 236f4b921fe49467367d27c1904731acea9d3083 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 16:21:11 +0000 Subject: [PATCH 3/9] Add caching to isEnabledForProductDetail() for performance improvement Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com> --- app/code/core/Mage/ConfigurableSwatches/Helper/Data.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php index 4a21f7baa4e..fd17cde59c3 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php @@ -24,6 +24,8 @@ class Mage_ConfigurableSwatches_Helper_Data extends Mage_Core_Helper_Abstract protected $_enabled = null; + protected $_enabledForProductDetail = null; + protected $_configAttributeIds = null; /** @@ -52,7 +54,11 @@ public function isEnabled() */ public function isEnabledForProductDetail() { - return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED); + if (is_null($this->_enabledForProductDetail)) { + $this->_enabledForProductDetail = Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED); + } + + return $this->_enabledForProductDetail; } /** From 81c6f57d5316d20fcc90fa6075dc98c99ecedc00 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 16:22:48 +0000 Subject: [PATCH 4/9] Add docblock comments to cached properties for clarity Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com> --- .../core/Mage/ConfigurableSwatches/Helper/Data.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php index fd17cde59c3..a86b7595d0b 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php @@ -22,8 +22,18 @@ class Mage_ConfigurableSwatches_Helper_Data extends Mage_Core_Helper_Abstract protected $_moduleName = 'Mage_ConfigurableSwatches'; + /** + * Cached result for isEnabled() check + * + * @var bool|null + */ protected $_enabled = null; + /** + * Cached result for isEnabledForProductDetail() check + * + * @var bool|null + */ protected $_enabledForProductDetail = null; protected $_configAttributeIds = null; From 73983098c0700d2496a5031f24248f73c6eac05c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 16:47:17 +0000 Subject: [PATCH 5/9] Fix PHPDoc type order to null|bool for PHP CS Fixer compliance Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com> --- app/code/core/Mage/ConfigurableSwatches/Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php index a86b7595d0b..36956c31db1 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php @@ -25,14 +25,14 @@ class Mage_ConfigurableSwatches_Helper_Data extends Mage_Core_Helper_Abstract /** * Cached result for isEnabled() check * - * @var bool|null + * @var null|bool */ protected $_enabled = null; /** * Cached result for isEnabledForProductDetail() check * - * @var bool|null + * @var null|bool */ protected $_enabledForProductDetail = null; From 8bd629c3fcd8c4f2891578717af5084292609c46 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 17:49:35 +0000 Subject: [PATCH 6/9] Improve property docblock descriptions to be more descriptive Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com> --- app/code/core/Mage/ConfigurableSwatches/Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php index 73ba286a385..d6efbdd03eb 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php @@ -23,14 +23,14 @@ class Mage_ConfigurableSwatches_Helper_Data extends Mage_Core_Helper_Abstract protected $_moduleName = 'Mage_ConfigurableSwatches'; /** - * Cached result for isEnabled() check + * Cached result for product listing swatches enabled check * * @var null|bool */ protected $_enabled = null; /** - * Cached result for isEnabledForProductDetail() check + * Cached result for product detail swatches enabled check * * @var null|bool */ From 29161cf11b0a301dfec58681a7198df1f3676280 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 21:32:57 +0000 Subject: [PATCH 7/9] Fix fatal error when listing attribute is not configured Add null checks before calling methods on $listSwatchAttr to prevent fatal errors when no product listing attribute is configured. This was a pre-existing bug that was exposed when product detail swatches were decoupled from listing requirements. Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com> --- .../core/Mage/ConfigurableSwatches/Helper/Mediafallback.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php index e7e7feb70f2..833076aafcc 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php @@ -54,7 +54,7 @@ public function attachProductChildrenAttributeMapping(array $parentProducts, $st $swatchAttributeIds = Mage::helper('configurableswatches')->getSwatchAttributeIds(); } - if ($listSwatchAttr->getId()) { + if ($listSwatchAttr && $listSwatchAttr->getId()) { $swatchAttributeIds[] = $listSwatchAttr->getId(); } @@ -127,7 +127,8 @@ public function attachProductChildrenAttributeMapping(array $parentProducts, $st $mapping[$optionLabel]['default_label'] = $optionLabels[$optionId][0]; $mapping[$optionLabel]['labels'] = $optionLabels[$optionId]; - if ($attribute->getAttributeId() == $listSwatchAttr->getAttributeId() + if ($listSwatchAttr + && $attribute->getAttributeId() == $listSwatchAttr->getAttributeId() && !in_array($mapping[$optionLabel]['label'], $listSwatchValues) ) { $listSwatchValues[$optionId] = $mapping[$optionLabel]['label']; From fd595b004955010248552206656ec939225d6b87 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 21:34:35 +0000 Subject: [PATCH 8/9] Fix formatting of multi-line condition Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com> --- .../core/Mage/ConfigurableSwatches/Helper/Mediafallback.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php index 833076aafcc..deadfdcf750 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php @@ -127,7 +127,7 @@ public function attachProductChildrenAttributeMapping(array $parentProducts, $st $mapping[$optionLabel]['default_label'] = $optionLabels[$optionId][0]; $mapping[$optionLabel]['labels'] = $optionLabels[$optionId]; - if ($listSwatchAttr + if ($listSwatchAttr && $attribute->getAttributeId() == $listSwatchAttr->getAttributeId() && !in_array($mapping[$optionLabel]['label'], $listSwatchValues) ) { From 0b9dc20c2b87f3eba0a5630a60de2bdfc393dac4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 21:36:03 +0000 Subject: [PATCH 9/9] Use instanceof for more robust type checking in null checks Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com> --- .../core/Mage/ConfigurableSwatches/Helper/Mediafallback.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php index deadfdcf750..eb8b856e1d0 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php @@ -54,7 +54,7 @@ public function attachProductChildrenAttributeMapping(array $parentProducts, $st $swatchAttributeIds = Mage::helper('configurableswatches')->getSwatchAttributeIds(); } - if ($listSwatchAttr && $listSwatchAttr->getId()) { + if ($listSwatchAttr instanceof Mage_Eav_Model_Entity_Attribute_Abstract && $listSwatchAttr->getId()) { $swatchAttributeIds[] = $listSwatchAttr->getId(); } @@ -127,7 +127,7 @@ public function attachProductChildrenAttributeMapping(array $parentProducts, $st $mapping[$optionLabel]['default_label'] = $optionLabels[$optionId][0]; $mapping[$optionLabel]['labels'] = $optionLabels[$optionId]; - if ($listSwatchAttr + if ($listSwatchAttr instanceof Mage_Eav_Model_Entity_Attribute_Abstract && $attribute->getAttributeId() == $listSwatchAttr->getAttributeId() && !in_array($mapping[$optionLabel]['label'], $listSwatchValues) ) {