Jump to content

Duplicate product WITHOUT copying image ?


dtwfung

Recommended Posts

Hi there,

I am new to PS 1.7. I have been using PS 1.6 for few years. Recently, upgrade production system to 1.7.

In 1.6, making new product (duplicate from old product ) can have option in copying images or not.  In PS 1.7 5.x, no such option anymore.

Please advise if the option has dropped or I just don't know how ?

 

Cheers

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

Hello everyone.

I have good news for you. I've done it. See below how to duplicate product without images:

1. Modification of file /html/src/Adapter/Product/AdminProductDataUpdater.php

look for 

use Validate;

and add after it

use Tools;

look for

if (!Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {

and change to

if (!Tools::getValue('noimage') && !Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {

2. Modification of file html/src/PrestaShopBundle/Resources/views/Admin/Product/CatalogPage/Lists/list.html.twig

look for this block

                {% set buttons_action = buttons_action|merge([
                    {
                        "onclick": "unitProductAction(this, 'duplicate');",
                        "icon": "content_copy",
                        "label": "Duplicate"|trans({}, 'Admin.Actions')
                    }
                ]) %}


and add after it

                {% set buttons_action = buttons_action|merge([
                    {
                        "onclick": "unitProductAction(this, 'duplicate noimage=1');",
                        "icon": "content_copy",
                        "label": "Duplicate without images"|trans({}, 'Admin.Actions')
                    }
                ]) %}

3. Modification of file html/ADMINFOLDER/themes/default/js/bundle/product/catalog.js

look for this function and 

function unitProductAction(element, action) {
  ...
}

and do like this (only two changes)

 function unitProductAction(element, action) {
  a = action.split(' '); action = a[0]; params = (a.length == 1) ? '' : a[1]; // <-- add this line
  var form = $('form#product_catalog_list');

  // save action URL for redirection and update to post to bulk action instead
  // using form action URL allow to get route attributes and stay on the same page & ordering.
  var urlHandler = $(element).closest('[data-uniturl]');
  var redirectUrlHandler = $(element).closest('[redirecturl]');
  var redirectionInput = $('<input>')
    .attr('type', 'hidden')
    .attr('name', 'redirect_url').val(redirectUrlHandler.attr('redirecturl'));

  switch (action) {
    case 'delete':
      // Confirmation popup and callback...
      $('#catalog_deletion_modal').modal('show');
      $('#catalog_deletion_modal button[value="confirm"]').off('click');
      $('#catalog_deletion_modal button[value="confirm"]').on('click', function () {
        form.append($(redirectionInput));
        var url = urlHandler.attr('data-uniturl').replace(/duplicate/, action);
        form.attr('action', url);
        form.submit();

        $('#catalog_deletion_modal').modal('hide');
      });
      return;
    // Other cases, nothing to do, continue.
    //default:
  }

  form.append($(redirectionInput));
  var url = urlHandler.attr('data-uniturl').replace(/duplicate/, action) + (params.length > 0 ? '&' + params : ''); // <-- and change this line
  form.attr('action', url);
  form.submit();
}

4. Clear cache in Performance and clear your browser cache.

 

That's all.

Have good clients $)

Edited by slashdev (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 6 months later...
  • 2 months later...
On 10/31/2021 at 9:16 AM, Designinfo.in said:

@slashdevi have done this above, but on click, the page goes to the dashboard, normal duplicate button works though.

You won't see the changes at the bottom of product edit page but at the product list if you hover over the three dots beside the edit button of the product.

Link to comment
Share on other sites

On 4/20/2021 at 9:13 PM, slashdev said:

Hello everyone.

I have good news for you. I've done it. See below how to duplicate product without images:

1. Modification of file /html/src/Adapter/Product/AdminProductDataUpdater.php

look for 

use Validate;

and add after it

use Tools;

look for

if (!Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {

and change to

if (!Tools::getValue('noimage') && !Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {

2. Modification of file html/src/PrestaShopBundle/Resources/views/Admin/Product/CatalogPage/Lists/list.html.twig

look for this block

                {% set buttons_action = buttons_action|merge([
                    {
                        "onclick": "unitProductAction(this, 'duplicate');",
                        "icon": "content_copy",
                        "label": "Duplicate"|trans({}, 'Admin.Actions')
                    }
                ]) %}


and add after it

                {% set buttons_action = buttons_action|merge([
                    {
                        "onclick": "unitProductAction(this, 'duplicate noimage=1');",
                        "icon": "content_copy",
                        "label": "Duplicate without images"|trans({}, 'Admin.Actions')
                    }
                ]) %}

3. Modification of file html/ADMINFOLDER/themes/default/js/bundle/product/catalog.js

look for this function and 

function unitProductAction(element, action) {
  ...
}

and do like this (only two changes)

 function unitProductAction(element, action) {
  a = action.split(' '); action = a[0]; params = (a.length == 1) ? '' : a[1]; // <-- add this line
  var form = $('form#product_catalog_list');

  // save action URL for redirection and update to post to bulk action instead
  // using form action URL allow to get route attributes and stay on the same page & ordering.
  var urlHandler = $(element).closest('[data-uniturl]');
  var redirectUrlHandler = $(element).closest('[redirecturl]');
  var redirectionInput = $('<input>')
    .attr('type', 'hidden')
    .attr('name', 'redirect_url').val(redirectUrlHandler.attr('redirecturl'));

  switch (action) {
    case 'delete':
      // Confirmation popup and callback...
      $('#catalog_deletion_modal').modal('show');
      $('#catalog_deletion_modal button[value="confirm"]').off('click');
      $('#catalog_deletion_modal button[value="confirm"]').on('click', function () {
        form.append($(redirectionInput));
        var url = urlHandler.attr('data-uniturl').replace(/duplicate/, action);
        form.attr('action', url);
        form.submit();

        $('#catalog_deletion_modal').modal('hide');
      });
      return;
    // Other cases, nothing to do, continue.
    //default:
  }

  form.append($(redirectionInput));
  var url = urlHandler.attr('data-uniturl').replace(/duplicate/, action) + (params.length > 0 ? '&' + params : ''); // <-- and change this line
  form.attr('action', url);
  form.submit();
}

4. Clear cache in Performance and clear your browser cache.

 

That's all.

Have good clients $)

Thank you for this helpful hack!

Link to comment
Share on other sites

  • 1 year later...
On 4/20/2021 at 10:13 PM, slashdev said:

Hello everyone.

I have good news for you. I've done it. See below how to duplicate product without images:

1. Modification of file /html/src/Adapter/Product/AdminProductDataUpdater.php

 

A million thanks! You cannot imagine the amount of time you saved me! <3

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...