3

How to Remove Duplicate button in product Create/Edit page - Magento2. enter image description here

2 Answers 2

1

If you look at vendor/magento/module-catalog/Block/Adminhtml/Product/Edit.php and vendor/magento/module-catalog/Block/Adminhtml/Product/Edit/Button/Save.php you see that on the location where the button is created it checks if the product is duplicable:

if (!$this->getRequest()->getParam('popup') && $this->getProduct()->isDuplicable()) {
    $options[] = [
        'id' => 'duplicate-button',
        'label' => __('Save & Duplicate'),
        'data_attribute' => [
            'mage-init' => [
                'button' => ['event' => 'saveAndDuplicate', 'target' => '[data-form=edit-product]'],
            ],
        ],
    ];
}

So the most obvious way I could think of is to make sure the $product->isDuplicable() will return false. It is a public method so you could use a plugin / interceptor to let it return false, or hook into the product loading and do something like $product->setIsDuplicable(false);

Note the isDuplicable() is a method of \Magento\Catalog\Model\Product and is not defined in it's service contract. Haven't tested it yet, but I'm not sure that writing an interceptor for the service contract will pick it up.

1
  • 1
    Thanx for the Answer but I checked both files code remove but it's not working. plugin things I don't know how it uses. can you explain about it? Jul 13, 2017 at 7:56
1

Implementation of Giel Berkers answer:

MyCompany/MyModule/etc/adminhtml/di.xml

<type name="Magento\Catalog\Model\Product">
    <plugin name="disable_product_duplicate" type="MyCompany\MyModule\Plugin\ProductPlugin" sortOrder="100"/>
</type>

MyCompany\MyModule\Plugin\ProductPlugin

namespace MyCompany\MyModule\Plugin;

class ProductPlugin
{
    /**
     * Checks product can be duplicated
     *
     * @return boolean
     */
    public function afterIsDuplicable(\Magento\Catalog\Model\Product $product, $result)
    {
        return false;
    }

}

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.