Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

duplicates - Change Magento default status for duplicated products

I have a Magento store installed, and when a product is duplicated in the backend, Magento sets its status to Disabled by default. I don't want that to happen, the duplicated product should have its status copied from the original product as well.

In this post a partial solution was given. I see where I can find the config.xml and make the necessarry changes. However, where do I put such an observer class? Which file should I use/create and would that require any changes to the config.xml input?

Or does somebody have an overall solution for this issue? Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this:

Create: app/code/local/MagePal/EnableDuplicateProductStatus/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MagePal_EnableDuplicateProductStatus>
            <version>1.0.1</version>
        </MagePal_EnableDuplicateProductStatus>
    </modules>

    <global>
        <models>
            <enableduplicateproductstatus>
                <class>MagePal_EnableDuplicateProductStatus_Model</class>
            </enableduplicateproductstatus>
        </models>
         <events>
            <catalog_model_product_duplicate>
                <observers>
                    <enableduplicateproductstatus>
                        <type>singleton</type>
                        <class>enableduplicateproductstatus/observer</class>
                        <method>productDuplicate</method>
                    </enableduplicateproductstatus>
                </observers>
            </catalog_model_product_duplicate>
        </events>
    </global>
</config>

Create: app/code/local/MagePal/EnableDuplicateProductStatus/Model/Observer.php

class MagePal_EnableDuplicateProductStatus_Model_Observer 
{
    /**
     * Prepare product for duplicate action.
     *
     * @param Varien_Event_Observer $observer
     * @return object
     */
    public function productDuplicate(Varien_Event_Observer  $observer)
    {
        $newProduct = $observer->getEvent()->getNewProduct();
        $newProduct->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);

        return $this;
    }
}

Create: app/etc/modules/MagePal_EnableDuplicateProductStatus.xml

  <?xml version="1.0"?>
    <config>
           <modules>
                  <MagePal_EnableDuplicateProductStatus>
                          <active>true</active>
                          <codePool>local</codePool>
                  </MagePal_EnableDuplicateProductStatus>
           </modules>
    </config>

Then clear cache and try duplicating a product.

read more @ :

http://magento4u.wordpress.com/2009/06/08/create-new-module-helloworld-in-magento/

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method

make a new product active by default in magento


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...