1

Magento: using duplicate product button, but emptying Url Key

We are using the duplicate product button. SKU is cleared, but the Url Key is still there. Sometimes we save the product ... and oops! a rewrite is created.

How can we also clear the Url Key (when we duplicate)

This is the action resulting from the button click 'catalog_product/duplicate/id'

Help appreciated

[update] Let's change our strategy and copy what already exists. We see that SKU is emptied on every duplicate action. Where and how?

  • duplicateAction is called
  • that calls Mage_Catalog_Model_Resource_Product_duplicate
  • but I don't see where the SKU is emptied
  • so I can copy the step for emptying the url_ley
  • What version of magento you are using? – Siarhey Uchukhlebau Apr 20 '16 at 9:07
  • 1.9.2.4.: why was this behavior changed? – snh_nl Apr 20 '16 at 9:21
2

You need to rewrite the Mage_Catalog_Model_Product::duplicate() method. It is called from the Controller after _initProduct() and in it your SKU and some other info is getting erased.

/* @var $newProduct Mage_Catalog_Model_Product */
        $newProduct = Mage::getModel('catalog/product')->setData($this->getData())
            ->setIsDuplicate(true)
            ->setOriginalId($this->getId())
            ->setSku(null)
            ->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
            ->setCreatedAt(null)
            ->setUpdatedAt(null)
            ->setId(null)
            ->setStoreId(Mage::app()->getStore()->getId());

Next, the duplicate product will be saved and will be returned for editing.

  • Thanks, I added ->setUrlKey(null) but does not seem to do anything ... thanks – snh_nl Apr 20 '16 at 11:06

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.