Skip to content

Commit be38022

Browse files
Copilotaddison74
andcommitted
Separate product detail and listing swatch configuration checks
Co-authored-by: addison74 <[email protected]>
1 parent abb3ee4 commit be38022

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Media/Js/Abstract.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ public function getImageType()
119119
*/
120120
protected function _toHtml()
121121
{
122-
if (!Mage::helper('configurableswatches')->isEnabled()) { // functionality disabled
122+
// Check if swatches are enabled for either listing or product detail
123+
if (!Mage::helper('configurableswatches')->isEnabled()
124+
&& !Mage::helper('configurableswatches')->isEnabledForProductDetail()
125+
) {
123126
return ''; // do not render block
124127
}
125128

app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Mage_ConfigurableSwatches_Block_Catalog_Product_View_Type_Configurable_Swa
3131
*/
3232
public function shouldRender($attribute, $jsonConfig)
3333
{
34-
if (Mage::helper('configurableswatches')->isEnabled()) {
34+
if (Mage::helper('configurableswatches')->isEnabledForProductDetail()) {
3535
if (Mage::helper('configurableswatches')->attrIsSwatchType($attribute->getProductAttribute())) {
3636
$this->_init($jsonConfig);
3737
return true;

app/code/core/Mage/ConfigurableSwatches/Helper/Data.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class Mage_ConfigurableSwatches_Helper_Data extends Mage_Core_Helper_Abstract
2727
protected $_configAttributeIds = null;
2828

2929
/**
30-
* Is the extension enabled?
30+
* Is the extension enabled for product listing?
31+
* Requires both general enabled flag and listing attribute to be set.
3132
*
3233
* @return bool
3334
*/
@@ -43,6 +44,17 @@ public function isEnabled()
4344
return $this->_enabled;
4445
}
4546

47+
/**
48+
* Is the extension enabled for product detail page?
49+
* Only requires general enabled flag, independent of listing configuration.
50+
*
51+
* @return bool
52+
*/
53+
public function isEnabledForProductDetail()
54+
{
55+
return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED);
56+
}
57+
4658
/**
4759
* Return the formatted hyphenated string
4860
*
@@ -126,7 +138,7 @@ public function getSwatchesProductJs()
126138
{
127139
/** @var Mage_Catalog_Model_Product $product */
128140
$product = Mage::registry('current_product');
129-
if ($this->isEnabled() && $product) {
141+
if ($this->isEnabledForProductDetail() && $product) {
130142
$configAttrs = $this->getSwatchAttributeIds();
131143
/** @var Mage_Catalog_Model_Product_Type_Configurable $productType */
132144
$productType = $product->getTypeInstance(true);

app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ public function clearSwatchesCache()
377377
*/
378378
public function filterImageInGallery($product, $image)
379379
{
380-
if (!Mage::helper('configurableswatches')->isEnabled()) {
380+
// Check if swatches are enabled for either listing or product detail
381+
if (!Mage::helper('configurableswatches')->isEnabled()
382+
&& !Mage::helper('configurableswatches')->isEnabledForProductDetail()
383+
) {
381384
return true;
382385
}
383386

app/code/core/Mage/ConfigurableSwatches/Model/Observer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ public function productListCollectionLoadAfter(Varien_Event_Observer $observer)
6565
*/
6666
public function productLoadAfter(Varien_Event_Observer $observer)
6767
{
68-
if (!Mage::helper('configurableswatches')->isEnabled()) { // functionality disabled
68+
// Check if swatches are enabled for either listing or product detail
69+
if (!Mage::helper('configurableswatches')->isEnabled()
70+
&& !Mage::helper('configurableswatches')->isEnabledForProductDetail()
71+
) {
6972
return; // exit without loading swatch functionality
7073
}
7174

@@ -91,7 +94,10 @@ public function productLoadAfter(Varien_Event_Observer $observer)
9194
*/
9295
public function loadChildProductImagesOnMediaLoad(Varien_Event_Observer $observer)
9396
{
94-
if (!Mage::helper('configurableswatches')->isEnabled()) { // functionality disabled
97+
// Check if swatches are enabled for either listing or product detail
98+
if (!Mage::helper('configurableswatches')->isEnabled()
99+
&& !Mage::helper('configurableswatches')->isEnabledForProductDetail()
100+
) {
95101
return; // exit without loading swatch functionality
96102
}
97103

0 commit comments

Comments
 (0)