Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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 @@ -44,7 +44,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
28 changes: 23 additions & 5 deletions app/code/core/Mage/ConfigurableSwatches/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ class Mage_ConfigurableSwatches_Helper_Data extends Mage_Core_Helper_Abstract
protected $_moduleName = 'Mage_ConfigurableSwatches';

/**
* Is the extension enabled
* Cached result for isEnabled() check
*
* @var null|bool
*/
protected $_enabled = null;

/**
* Swatch attribute IDs from config
* Cached result for isEnabledForProductDetail() check
*
* @var null|string[]
* @var null|bool
*/
protected $_enabledForProductDetail = null;

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 @@ -53,6 +56,21 @@ 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()
{
if (is_null($this->_enabledForProductDetail)) {
$this->_enabledForProductDetail = Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED);
}

return $this->_enabledForProductDetail;
}

/**
* Return the formatted hyphenated string
*
Expand Down Expand Up @@ -145,7 +163,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 @@ -389,7 +389,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 @@ -71,7 +71,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 Down Expand Up @@ -100,7 +103,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