4

Currently creating a product doesn't need any image. How do I make it required? Using javascript is ok. I know how to do it with input text field, but image is quite different.

1 Answer 1

3

You can try to add some class for the field media_gallery_content_save and then to validate it as you check it to be != []. For example in app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml replace this:

<input type="hidden" id="<?php echo $_block->getHtmlId() ?>_save" name="<?php echo $_block->getElement()->getName() ?>[images]" value="<?php echo $_block->htmlEscape($_block->getImagesJson()) ?>" />

with this:

<input type="hidden" id="<?php echo $_block->getHtmlId() ?>_save" name="<?php echo $_block->getElement()->getName() ?>[images]" value="<?php echo $_block->htmlEscape($_block->getImagesJson()) ?>" class="required-entry-image" />

and in app/design/adminhtml/default/default/template/catalog/product/edit.phtml replace this:

Validation.addAllThese([
    ['validate-super-product-attributes', '<?php echo Mage::helper('catalog')->__('Please select one or more attributes.') ?>', function(v) {
                return (v != "no-attributes");
            }]]);

with this:

Validation.addAllThese([
    ['validate-super-product-attributes', '<?php echo Mage::helper('catalog')->__('Please select one or more attributes.') ?>', function(v) {
                return (v != "no-attributes");
            }],
    ['required-entry-image', '<?php echo Mage::helper('catalog')->__('This is a required field.') ?>', function(v) {
                return (v != "[]");
            }]]);

Of course it's better not to change it in the core files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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