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 d093742f8e9..e98b0537afb 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 @@ -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 } 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 1ed54a7cbec..b154abfcf6c 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 @@ -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; diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php index 50a657c11ca..d6efbdd03eb 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Data.php @@ -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 product listing swatches enabled check * * @var null|bool */ protected $_enabled = null; /** - * Swatch attribute IDs from config + * Cached result for product detail swatches enabled 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 */ @@ -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 * @@ -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); diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php index e7e7feb70f2..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->getId()) { + if ($listSwatchAttr instanceof Mage_Eav_Model_Entity_Attribute_Abstract && $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 instanceof Mage_Eav_Model_Entity_Attribute_Abstract + && $attribute->getAttributeId() == $listSwatchAttr->getAttributeId() && !in_array($mapping[$optionLabel]['label'], $listSwatchValues) ) { $listSwatchValues[$optionId] = $mapping[$optionLabel]['label']; diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php index 37ab28fd05d..92a95fbb3e9 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php @@ -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; } diff --git a/app/code/core/Mage/ConfigurableSwatches/Model/Observer.php b/app/code/core/Mage/ConfigurableSwatches/Model/Observer.php index b765ab00f43..691e575c387 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Model/Observer.php +++ b/app/code/core/Mage/ConfigurableSwatches/Model/Observer.php @@ -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 } @@ -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 }