Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 14 additions & 2 deletions app/code/core/Mage/ConfigurableSwatches/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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);
}
Comment on lines +53 to +56
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new isEnabledForProductDetail() method lacks caching, unlike isEnabled() which caches its result in $this->_enabled. Since this method will be called multiple times during request processing (in observers, blocks, and helpers), consider adding caching to avoid repeated getStoreConfigFlag() calls.

Suggested implementation:

protected $_enabledForProductDetail = null;

public function isEnabledForProductDetail()
{
    if (is_null($this->_enabledForProductDetail)) {
        $this->_enabledForProductDetail = Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED);
    }
    return $this->_enabledForProductDetail;
}

Copilot uses AI. Check for mistakes.

/**
* Return the formatted hyphenated string
*
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 8 additions & 2 deletions app/code/core/Mage/ConfigurableSwatches/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
Loading