更改重复产品的 Magento 默认状态 [英] Change Magento default status for duplicated products

查看:24
本文介绍了更改重复产品的 Magento 默认状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了一个 Magento 商店,当产品在后端复制时,Magento 默认将其状态设置为禁用.我不希望这种情况发生,复制的产品也应该从原始产品复制其状态.

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.

这篇文章中,部分解决方案是给.我看到在哪里可以找到 config.xml 并进行必要的更改.但是,我在哪里放置这样的观察者类?我应该使用/创建哪个文件并且需要对 config.xml 输入进行任何更改?

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!

推荐答案

试试这个:

创建:app/code/local/MagePal/EnableDuplicateProductStatus/etc/config.xml

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>

创建:app/code/local/MagePal/EnableDuplicateProductStatus/Model/Observer.php

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;
    }
}

创建:app/etc/modules/MagePal_EnableDuplicateProductStatus.xml

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.

阅读更多@:

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

在 magento 中默认激活新产品

这篇关于更改重复产品的 Magento 默认状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆