4

I was just wondering if there is a way the image radio button auto select as base, small, thumb so I don't have to select manually every time when uploaded. Screenshot enter image description here

Thanks

  • 1
    Why close and downvote? This is an important question! – Fabian Blechschmidt Jul 31 '14 at 6:00
5

And to answer the question: No, magento can't do this out of the box. But you can "easily" change the JS code which adds the row to the table, so when you add the first one, the radio buttons are checked.

The creation of a row is made here: js/mage/adminhtml/product.js:140

  • Hi Fab, any idea where to look at the product.js – Dips Jul 31 '14 at 6:20
  • I think it is under js/mage/adminhtml/product.js without the lib. – David Manners Jul 31 '14 at 7:17
  • 1
    I don't understand the question. I posted the path and the line? Damn, thanks David. Obviously I took the only project I have where someone copied the whole JS directory into lib :( – Fabian Blechschmidt Jul 31 '14 at 7:17
  • when you upload product image then the until the radio button checked the images doesn't display to the front end. I want the radio button auto checked when upload complete – Dips Aug 1 '14 at 4:17
  • 1
    @Dips, you don't need to reword your question. Fabian clearly understands what you want, and has provided you with an answer. I've just got it working thanks to his advice. True, he doesn't tell you exactly what you need to add to product.js - if you're unable to figure that part out, just say so. I've added an answer that will tell you exactly what needs to be added. But don't get used to the idea of SO doing all the work for you! :) – Doug McLean May 1 '15 at 10:17
3

To follow on from Fabian's Answer, you need to add

radio.checked=true;

just after the line

radio.observe('change', this.onChangeRadio);

in the Product.Gallery.createImageRow function.

In Magento 1.9.0.1 this is on line 149.

1

Thanks to Fabian and Doug for the groundwork. I just published an extension, which does exactly what you are trying to achieve in a clean way: https://github.com/customgento/CustomGento_AutoSelectImages

It simply adds a JS file on the admin product edit page. In the JS file, the mentioned method Product.Gallery.createImageRow is wrapped, so that the radio buttons can be selected after the first image has been uploaded. Here is the JS "magic":

if (typeof Product.Gallery !== 'undefined') {
    Product.Gallery.prototype.createImageRow = Product.Gallery.prototype.createImageRow.wrap(function (parentMethod, image) {
        // first call the parent method
        parentMethod(image);

        // auto-select the radio buttons for the first uploaded image
        $H(this.imageTypes).each(function (pair) {
            if (this.images.length === 1) {
                this.getFileElement(image.file, 'cell-' + pair.key + ' input').checked = true;
            }
        }.bind(this));
        this.setProductImages(image.file);
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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