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
asked Apr 20, 2016 at 9:04
2
  • What version of magento you are using? Commented Apr 20, 2016 at 9:07
  • 1.9.2.4.: why was this behavior changed? Commented Apr 20, 2016 at 9:21

1 Answer 1

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.

answered Apr 20, 2016 at 10:28
1
  • Thanks, I added ->setUrlKey(null) but does not seem to do anything ... thanks Commented Apr 20, 2016 at 11:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.