0

我创建了一个名为“catalog_product_import_profile_after”的新自定义事件。此事件在产品导入运行配置文件完成过程后调用。如果我为 2 个产品运行配置文件,那么它工作正常并且触发了自定义事件,但是当我为数千种产品运行相同的配置文件时,它正在工作并且不会触发自定义事件。

这是observer.php文件的代码——

<?php
class GWB_ClearOrphan_Model_Observer
{

            public function disableProducts(Varien_Event_Observer $observer)
            {

                try{    
                    $collection = Mage::getModel('catalog/product')->getCollection()
                            ->addAttributeToSelect('sku')
                            ->addAttributeToFilter('attribute_set_id',9)
                            ->load();
                }
                catch(Exception $e) {
                    //Mage::log($e->getMessage(), null, 'collection.log');
                }

                try{
                    $resource = Mage::getModel('core/resource');
                    $readConnection = $resource->getConnection('core_read');
                    $writeConnection = $resource->getConnection('core_write');
                }
                catch(Exception $e) {
                    //Mage::log($e->getMessage(), null, 'developer.log');
                }

                foreach($collection as $val) {
                    $sku = $val->getSku();

                    $query = "SELECT * FROM feed_products WHERE feed_sku='".$sku."'";
                    $results = $readConnection->fetchAll($query);
                    $feed_sku = $results[0]['feed_sku'];

                    if($feed_sku != ''){
                        $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
                        $product->setStatus(2);
                        try {
                            $product->save();
                            //$product->delete();
                        }
                        catch (Exception $e) {
                            Mage::log($e->getMessage(), null, 'product_disable.log');
                        }   
                    }               
                }

                try{
                    $writeConnection->query("TRUNCATE TABLE feed_products");
                } 
                catch(Exception $e){
                    echo $e;
                }
            }

}

?>

我已经在“ProfileController.php”文件下注册了这个事件,这里是这个函数的代码---

<?php

    public function batchFinishAction()
        {   
            $batchId = $this->getRequest()->getParam('id');
            if ($batchId) {
                $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
                /* @var $batchModel Mage_Dataflow_Model_Batch */

                if ($batchModel->getId()) {
                    $result = array();
                    try {
                        $batchModel->beforeFinish();
                    } catch (Mage_Core_Exception $e) {
                        $result['error'] = $e->getMessage();
                    } catch (Exception $e) {
                        $result['error'] = Mage::helper('adminhtml')->__('An error occurred while finishing process. Please refresh the cache');
                    }

            Mage::dispatchEvent('catalog_product_import_profile_after', array('adapter'=>$this));

                    $batchModel->delete();
                    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
                }
            }
        }

?>
4

1 回答 1

0

这取决于您触发事件的确认记录。这可能是您从后端或 cli 运行批处理并在“前端”节点中触发事件。这里最好在全局节点中描述此事件的配置。

于 2013-10-25T21:10:27.830 回答