Published: March 10, 2017
Last updated:

Magento :: SyntaxError: expected expression, got ‘,’

Problem description

Image upload is broken in Magento after upgrade to 1.9.3 or SUPEE-8788 patch. The following error is logged in browser console:
SyntaxError: expected expression, got ','
In HTML source code you can see that one element is missing in media_gallery_contentJsObject variable:
var media_gallery_contentJsObject = new Product.Gallery('media_gallery_content', , {"thumbnail":{"label":"Thumbnail ","field":"product[thumbnail]"},"small_image":{"label":"Small Image ","field":"product[small_image]"},"image":{"label":"Base Image ","field":"product[image]"}});

Cause

The problem is caused by Creare/CreareSEO or CJM/ColorSelectorPlus extensions that override image uploader code.

Solution

Creare/CreareSEO
Update app/design/adminhtml/default/default/template/creareseo/catalog/product/helper/gallery.phtml file with the following change:
--- app/design/adminhtml/default/default/template/creareseo/catalog/product/helper/gallery.phtml
+++ app/design/adminhtml/default/default/template/creareseo/catalog/product/helper/gallery.phtml
@@ -96,3 +96,3 @@
 //<![CDATA[
-var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php if ($_block->getElement()->getReadonly()):?>null<?php else:?><?php echo $_block->getUploader()->getJsObjectName() ?><?php endif;?>, <?php echo $_block->getImageTypesJson() ?>);
+var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
 //]]>
or re-upload it from https://raw.githubusercontent.com/unxsist/CreareSEO/d5e0f35d21d290e61745d9c16a085b0b945f7fc0/app/design/adminhtml/default/default/template/creareseo/catalog/product/helper/gallery.phtml.


CJM/ColorSelectorPlus
diff app/code/local/CJM/ColorSelectorPlus/blocks/Adminhtml/catalog/product/helper/gallery.phtml
--- app/code/local/CJM/ColorSelectorPlus/blocks/Adminhtml/catalog/product/helper/gallery.phtml
+++ app/code/local/CJM/ColorSelectorPlus/blocks/Adminhtml/catalog/product/helper/gallery.phtml
@@ -160,7 +160,7 @@
 <input type="hidden" id="<?php echo $_block->getHtmlId() ?>_save_image" name="<?php echo $_block->getElement()->getName() ?>[values]" value="<?php echo $_block->htmlEscape($_block->getImagesValuesJson()) ?>" />
 <script type="text/javascript">
 //<![CDATA[
-var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php if ($_block->getElement()->getReadonly()):?>null<?php else:?><?php echo $_block->getUploader()->getJsObjectName() ?><?php endif;?>, <?php echo $_block->getImageTypesJson() ?>);
+var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
 //]]>
 </script>
diff js/cjm/colorselectorplus/product-update.js js/cjm/colorselectorplus/product-update.js
--- js/cjm/colorselectorplus/product-update.js
+++ js/cjm/colorselectorplus/product-update.js
@@ -21,7 +21,6 @@
             newImage.defaultimg = 0;
             newImage.removed = 0;
             this.images.push(newImage);
-            this.uploader.removeFile(item.id);
         }.bind(this));
         this.container.setHasChanges();
         this.updateImages();

Posted in: Extensions, Troubleshooting

41 votes, 4.80 avg. rating (95% score)