make a new product active by default in magento
When duplicating a product in the backend in magento the new product status is 开发者_StackOverflow社区Disabled by default. That confuses the store admins who expect the product to show on the frontend.
How can I make the product status Enabled by default?
THanks
In your custom module you need to:
in config.xml file:
<config>
<adminhtml>
<events>
<catalog_model_product_duplicate>
<observers>
<custom_catalog_product_duplicate>
<class>custom_module/observer</class>
<method>catalogModelProductDuplicate</method>
</custom_catalog_product_duplicate>
</observers>
</catalog_model_product_duplicate>
</events>
</adminhtml>
</config>
Create an observer class with method like this:
class Custom_Module_Model_Observer
{
/**
* Prepare product for duplicate action.
*
* @param Varien_Event_Observer $observer
* @return object
*/
public function catalogModelProductDuplicate(Varien_Event_Observer $observer)
{
$newProduct = $observer->getEvent()->getNewProduct();
$newProduct->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
return $this;
}
}
精彩评论