2013-04-24 1 views
0

"catalog_product_import_profile_after"라는 이름으로 새 사용자 정의 이벤트를 생성했습니다. 제품 가져 오기 실행 프로파일 완료 프로세스 후이 이벤트 호출 2 제품에 대한 프로필을 실행하면 작업이 잘되고 사용자 지정 이벤트가 트리거되지만 수천 개의 제품에 대해 동일한 프로필을 실행하면 작동하고 사용자 지정 이벤트가 트리거되지 않습니다. 여기 Magento 관측자가 제품 가져 오기 프로파일 실행 후 트리거하지 않음

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

?> 
+0

이벤트를 실행하는 코드를 게시 할 수 있습니까? – Andrew

+0

@Andrew 이벤트를 등록한 곳의 코드를 업데이트했습니다. 업데이트 된 코드를 확인하십시오. –

+0

코드에 버그가 표시되지 않았습니다. 나는 오류가 일괄 처리 프로세스에서 실행되기를 바랍니다. 너도 그걸 확인해 주시겠습니까 .. –

답변

0

그것은 당신이 당신의 이벤트를 발화하는주의 사항에 따라 다릅니다. 백엔드 또는 cli에서 배치 프로세스를 실행하고 이벤트를 "프론트 엔드"노드에서 실행 한 경우 일 수 있습니다. 글로벌 노드에서이 이벤트의 구성을 설명하는 것이 좋습니다.

관련 문제