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 4/20/2021 at 7: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 $)

Expand  

Thank you for this helpful hack!

Link to comment
Share on other sites

  • 1 year later...
  On 4/20/2021 at 7: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

 

Expand  

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

Link to comment
Share on other sites

  • 1 year later...
  On 8/28/2024 at 6:26 PM, Geronimo2012 said:

I have the same, in Prestashop 8.1.7.

I cleared the cache and browser data but still I get redirected to dashboard.

 

Expand  

The url change does not work anymore, it results in:
 

/admin/index.php/sell/catalog/products/unit/duplicate%20noimage=1/index.php?controller=AdminDashboard&token=xxxxxxxxxxxxxxxxxxxxxxxxxx

 

Link to comment
Share on other sites

  • 5 months later...

Dear 'slashdev'. My most thanks for the code you gave us. Thats why I love this forum and still being with Prestashop since 2009. You saved me endless time for the following years. I can believe that instead of making it easier in PS1.7, they made it more difficult vs PS1.6.

Is there also a solution to automatically receive the 'Caption' text from the product title instead of clicking each image to add it and save it. In PS1.6 i first added the title and then  added the images which automatically inherited the title to the images Caption (ie alt text).

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...