Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevented Configurable Swatches assets from loading while unneeded #2999

Merged
merged 16 commits into from
Mar 30, 2023
Merged
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 @@ -64,4 +64,18 @@ protected function _getImageSizes()
{
return ['small_image'];
}

/**
* Prevent actual block render if we are disabled, and i.e. via the module
* config as opposed to the advanced module settings page
*
* @return string
*/
protected function _toHtml()
{
if (!Mage::getStoreConfigFlag(Mage_ConfigurableSwatches_Helper_Data::CONFIG_PATH_LIST_SWATCH_ATTRIBUTE)) {
return '';
}
return parent::_toHtml();
}
}
62 changes: 31 additions & 31 deletions app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,8 @@ public function getConfigurableImagesFallbackArray(
$keepFrame = false
) {
if (!$product->hasConfigurableImagesFallbackArray()) {
$mapping = $product->getChildAttributeLabelMapping();

$mapping = $product->getChildAttributeLabelMapping() ?? [];
$mediaGallery = $product->getMediaGallery();

if (!isset($mediaGallery['images'])) {
return []; //nothing to do here
}
Expand All @@ -194,36 +192,38 @@ public function getConfigurableImagesFallbackArray(
}, $mediaGallery['images']);

// load images from the configurable product for swapping
foreach ($mapping as $map) {
$imagePath = null;

//search by store-specific label and then default label if nothing is found
$imageKey = array_search($map['label'], $imageHaystack);
if ($imageKey === false) {
$imageKey = array_search($map['default_label'], $imageHaystack);
}

//assign proper image file if found
if ($imageKey !== false) {
$imagePath = $mediaGallery['images'][$imageKey]['file'];
}

$imagesByLabel[$map['label']] = [
'configurable_product' => [
Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_SMALL => null,
Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_BASE => null,
],
'products' => $map['product_ids'],
];
if (is_array($mapping)) {
foreach ($mapping as $map) {
$imagePath = null;

//search by store-specific label and then default label if nothing is found
$imageKey = array_search($map['label'], $imageHaystack);
if ($imageKey === false) {
$imageKey = array_search($map['default_label'], $imageHaystack);
}

if ($imagePath) {
$imagesByLabel[$map['label']]['configurable_product']
[Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_SMALL] =
$this->_resizeProductImage($product, 'small_image', $keepFrame, $imagePath);
//assign proper image file if found
if ($imageKey !== false) {
$imagePath = $mediaGallery['images'][$imageKey]['file'];
}

$imagesByLabel[$map['label']]['configurable_product']
[Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_BASE] =
$this->_resizeProductImage($product, 'image', $keepFrame, $imagePath);
$imagesByLabel[$map['label']] = [
'configurable_product' => [
Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_SMALL => null,
Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_BASE => null,
],
'products' => $map['product_ids'],
];

if ($imagePath) {
$imagesByLabel[$map['label']]['configurable_product']
[Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_SMALL] =
$this->_resizeProductImage($product, 'small_image', $keepFrame, $imagePath);

$imagesByLabel[$map['label']]['configurable_product']
[Mage_ConfigurableSwatches_Helper_Productimg::MEDIA_IMAGE_TYPE_BASE] =
$this->_resizeProductImage($product, 'image', $keepFrame, $imagePath);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
<action method="addItem" ifconfig="configswatches/general/product_list_price_change">
<type>skin_js</type><name>js/configurableswatches/configurable-swatch-prices.js</name>
</action>
<action method="addItem"><type>skin_js</type><name>js/configurableswatches/product-media.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/configurableswatches/swatches-list.js</name></action>
<action method="addItem" ifconfig="configswatches/general/product_list_attribute">
<type>skin_js</type><name>js/configurableswatches/product-media.js</name>
</action>
<action method="addItem" ifconfig="configswatches/general/product_list_attribute">
<type>skin_js</type><name>js/configurableswatches/swatches-list.js</name>
</action>
</reference>
<reference name="product_list.name.after">
<block type="core/template" name="product_list.swatches" template="configurableswatches/catalog/product/list/swatches.phtml" />
Expand Down