Warning: array_merge_recursive() expects at least 1 parameter, 0 given  in /home/WEBSERVER/public_html/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php on line 336

#0 [internal function]: mageCoreErrorHandler(2, 'array_merge_rec...', '/home/WEBSERVER/...', 336, Array)
#1 [internal function]: array_merge_recursive()
#2 /home/WEBSERVER/public_html/app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php(336): call_user_func_array('array_merge_rec...', Array)
#3 /home/WEBSERVER/public_html/app/design/frontend/neighborhood/default/template/catalog/product/view/media.phtml(128): Mage_ConfigurableSwatches_Helper_Productimg->filterImageInGallery(Object(Amasty_Setimg_Model_Catalog_Product), Object(Varien_Object))
#4 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(241): include('/home/WEBSERVER/...')
#5 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/neighb...')
#6 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#7 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Abstract.php(923): Mage_Core_Block_Template->_toHtml()
#8 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Abstract.php(641): Mage_Core_Block_Abstract->toHtml()
#9 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Abstract.php(585): Mage_Core_Block_Abstract->_getChildHtml('media', true)
#10 /home/WEBSERVER/public_html/app/design/frontend/neighborhood/default/template/catalog/product/view.phtml(80): Mage_Core_Block_Abstract->getChildHtml('media')
#11 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(241): include('/home/WEBSERVER/...')
#12 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/neighb...')
#13 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#14 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Abstract.php(923): Mage_Core_Block_Template->_toHtml()
#15 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#16 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Abstract.php(923): Mage_Core_Block_Text_List->_toHtml()
#17 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Abstract.php(641): Mage_Core_Block_Abstract->toHtml()
#18 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Abstract.php(585): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#19 /home/WEBSERVER/public_html/app/design/frontend/neighborhood/default/template/page/2columns-right.phtml(62): Mage_Core_Block_Abstract->getChildHtml('content')
#20 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(241): include('/home/WEBSERVER/...')
#21 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/neighb...')
#22 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#23 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Block/Abstract.php(923): Mage_Core_Block_Template->_toHtml()
#24 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#25 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#26 /home/WEBSERVER/public_html/app/code/core/Mage/Cms/Helper/Page.php(137): Mage_Core_Controller_Varien_Action->renderLayout()
#27 /home/WEBSERVER/public_html/app/code/core/Mage/Cms/Helper/Page.php(52): Mage_Cms_Helper_Page->_renderPage(Object(SkyMagento_Redirect_IndexController), 'no-route')
#28 /home/WEBSERVER/public_html/app/code/core/Mage/Cms/controllers/IndexController.php(75): Mage_Cms_Helper_Page->renderPage(Object(SkyMagento_Redirect_IndexController), 'no-route')
#29 /home/WEBSERVER/public_html/app/code/local/SkyMagento/Redirect/controllers/IndexController.php(15): Mage_Cms_IndexController->noRouteAction(NULL)
#30 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): SkyMagento_Redirect_IndexController->noRouteAction()
#31 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('noRoute')
#32 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#33 /home/WEBSERVER/public_html/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#34 /home/WEBSERVER/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#35 /home/WEBSERVER/public_html/index.php(120): Mage::run(‘STORE_NAME’, 'store')
#36 {main}

I have a product with 5 images, one of which has a label that says "alt" - this works with our theme to enable this as the "hover" image for that product.

There are no images being used as configurable swatches. No other images have labels saved in them.

I have made sure there are no store specific settings saved.

I have reindexed and cleared my cache.

I have seen that other product updates are being made and not affected by this issue.

The section of code being referenced by this error is:

/**
 * Determine whether to show an image in the product media gallery
 *
 * @param Mage_Catalog_Model_Product $product
 * @param Varien_Object $image
 * @return bool
 */
public function filterImageInGallery($product, $image)
    {
        if (!Mage::helper('configurableswatches')->isEnabled()) {
            return true;
        }

        if (!isset($this->_productImageFilters[$product->getId()])) {
            **LINE 336** $mapping = call_user_func_array("array_merge_recursive", $product->getChildAttributeLabelMapping()); ** END LINE **
            $filters = array_unique($mapping['labels']);
            $filters = array_merge($filters, array_map(function ($label) {
                return $label . Mage_ConfigurableSwatches_Helper_Productimg::SWATCH_LABEL_SUFFIX;
            }, $filters));
            $this->_productImageFilters[$product->getId()] = $filters;
        }

        return !in_array(Mage_ConfigurableSwatches_Helper_Data::normalizeKey($image->getLabel()),
            $this->_productImageFilters[$product->getId()]);
    }

--- EDIT ---

@Sukumar - My PHP Info page says that GD library is enabled. Here is the breakdown:

GD Support  enabled
GD Version  bundled (2.1.0 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.2.1
T1Lib Support   enabled
GIF Read Support    enabled
GIF Create Support  enabled
JPEG Support    enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version  1.2.10
WBMP Support    enabled
XPM Support enabled
libXpm Version  30411
XBM Support enabled

@Preston - I updated the file you mentioned in my /local folder. Cache was flushed, CDN disabled, Reindexed All. No change unfortunately.

I was getting the same error when accessing the product page directly when 'Display Out of Stock Products' is set to No in the admin and the product is out of stock. The attachProductChildrenAttributeMapping function in Mage_ConfigurableSwatches_Helper_Mediafallback continues without setting $mapping attributes in this case. The empty $mapping array causes array_merge_recursive to throw the error.

I changed

if (!$childProduct->hasData($attribute->getAttributeCode())
    || (!$isInStock && !Mage::helper('cataloginventory')->isShowOutOfStock())) {
    continue;
}

to

if (!$childProduct->hasData($attribute->getAttributeCode())) {
    continue;
}

----- UPDATE -----

I realized there are a few other places in the attachProductChildrenAttributeMapping() that could cause the $mapping to be empty. It might be better to update filterImageInGallery in Mage_ConfigurableSwatches_Helper_Productimg to add an empty array check.

public function filterImageInGallery($product, $image) { if (!Mage::helper('configurableswatches')->isEnabled()) { return true; }

if (!isset($this->_productImageFilters[$product->getId()])) {
    $filters = array();
    if(!empty($childAttr = $product->getChildAttributeLabelMapping())) {
        $mapping = call_user_func_array("array_merge_recursive", $childAttr);
        $filters = array_unique($mapping['labels']);
        $filters = array_merge($filters, array_map(function ($label) {
            return $label . Mage_ConfigurableSwatches_Helper_Productimg::SWATCH_LABEL_SUFFIX;
        }, $filters));
    }
    $this->_productImageFilters[$product->getId()] = $filters;
}

return !in_array(Mage_ConfigurableSwatches_Helper_Data::normalizeKey($image->getLabel()),
    $this->_productImageFilters[$product->getId()]);
}
  • Your update has fixed the page loading issue and I can now see my products. During this change I also realized that the attribute I was using for these products is "new" and had not been added to the list "Product Attributes to Show as Swatches in Product Detail" - Your fix corrected my issue, but the issue is also fixed by making sure your product's attribute(s) is selected in this list. – Steven J Jul 8 at 16:38

You should pass your arguments as an array. The method returns an array but you need to pass your arguments in an array and pass an array to the array_merge_recursive method. So an array in an array.

$mapping = call_user_func_array("array_merge_recursive", [$product->getChildAttributeLabelMapping()]);
$filters = array_unique($mapping['labels']);

call_user_func_array (PHP 4 >= 4.0.4, PHP 5, PHP 7)

call_user_func_array — Call a callback with an array of parameters

Description

mixed call_user_func_array ( callable $callback , array $param_arr ) Calls the callback given by the first parameter with the parameters in param_arr.

http://php.net/manual/en/function.call-user-func-array.php

  • Changing this only gave me an error on the following line - $filters – Steven J Jul 6 at 2:57
  • Can you please be more specific about what error? – Quisse Jul 6 at 7:18
  • Warning: array_unique() expects parameter 1 to be array, null given – Steven J Jul 8 at 16:15
up vote 0 down vote accepted

TLDR: Make sure the attribute you're using to allow selection of a simple product is included in the Product Attributes to Show as Swatches in Product Detail list in System > Configuration > Configurable Swatch

~~ Other Credit ~~

@Preston made an update to that block of code that allowed me to see the product page and notice that the attributes were not showing as swatches and instead as a drop down. This clued me into the solution mentioned above.

This issue is due to php gd library. Please check the GD library you are using is compatible with the php version you are using or not.

You can install it by following command if its not installed:

sudo apt-get install php5-gd (you need to mention the php version. e.g. php5)

Then restart the server by following command:

sudo service apache2 restart

You can verify it by following command:

php -i | grep -i --color gd

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.