I have created a button in product admin image popup by overriding the gallery.phtml.

Created the custom js mixin to the product-gallery.js

requirejs-config.js (path - Ayakil/ProcessImage/view/adminhtml/requirejs-config.js) file contains like below.

var config = {
config: {
    mixins: {
        'Magento_Catalog/js/product-gallery': {
            'Ayakil_ProcessImage/js/product-gallery-mixin': true

product-gallery-mixin.js (path - Ayakil/ProcessImage/view/adminhtml/web/js/product-gallery-mixin.js) file contains like below.

], function ($, _, mageTemplate, registry, urlBuilder) {
'use strict';

var galleryWidgetMixin = {
  $dialog.on('click', '[data-role=background-remover]', $.proxy(function (e) {
            let imageUrl = $("#current-image-url").val();
            let apiUrl = urlBuilder.build('imgprocess/process/processimage');
                showLoader: true, 
                url: apiUrl,
                data: {img:imageUrl},
                type: "POST", 
                dataType: 'json'
            }).done(function (data) { 
                alert(data); console.log(data); 
        }, this));

return function (targetWidget) {
    $.widget('mage.productGallery', targetWidget, galleryWidgetMixin);

    return $.mage.productGallery;

When i am clicking on the button i am getting a 404 error like below. Admin controller url is generating with the current edit url.

jquery.js:10109 POST https://magento245p1new.local/index.php/admin/catalog/product/edit/id/1414/key/226536366459bcf89b14af76496ced792f7b28d59dc365c3bc8dcbf528e64895/imgprocess/process/processimage/?isAjax=true 404 (Not Found)

How to give a proper controller url on this AJAX call? Kindly note this click event is triggering on the image click popup in product edit form area.

  • Is it the way you're building the URL in product-gallery-mixin.js? Shouldn't it be like this?: let apiUrl = urlBuilder.build('ayakil_processimage/process/processimage');
    – eleventy
    Apr 17 at 12:23
  • @eleventy here in the url builder imgprocess is my admin route name
    – Mujahidh
    Apr 18 at 5:26


Your Answer

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

Browse other questions tagged or ask your own question.