2014-12-01 3 views
1

우리는 제 3자를 사용하여 패키지를 포장하고 발송했습니다. 그러므로 우리는 더 이상 통과하는 모든 명령을 보지 못합니다.Magento : 특정 품목 주문시 알림 보내기

하지만 디지털 선물 카드와 같이 수동으로 직접 공급해야하는 제품이 몇 가지 있습니다. 고객이 특정 SKU를 주문한 경우 Magento가 이메일을 보내도록 할 수 있습니까? 예를 들어 고객을 위해 기프트 카드를 만들어야한다고 알려주는 경우?

이메일 상자의 모든 주문을보고 싶지 않습니다. 일부 SKU가 포함되어 있습니다.

감사합니다, 메노

답변

1

예 이것은 사용자 정의 모듈을 달성 할 수있다. 모듈을 생성하고 이벤트 관찰자를 config.xml에 추가하십시오.

<events> 
     <checkout_onepage_controller_success_action> 
      <observers> 
       <copymein> 
        <type>singleton</type> 
        <class>dispatcher/observer</class> 
        <method>ccMyEmail</method> 
       </copymein> 
      </observers> 
     </checkout_onepage_controller_success_action> 
    </events> 

그런 다음 Model/Observer.php에서 함수를 선언하십시오.

public function ccMyEmai($observer) { 

    $order_ids = $observer->getData('order_ids'); 

    if(isset($order_ids)) { 
     foreach ($order_ids as $order_id) : 

     $sendToMe = false; 
     $order = Mage::getModel('sales/order')->load($order_id); 
      if (isset($order)) { 

       $orderItems = $order->getAllItems(); 
       foreach ($orderItems as $_item) { 

        $product = Mage::getModel('catalog/product')->load($item->getData('product_id')); 
        if($product->getSku() == ('123' || '234' || '345')) { // Your SKUs 
           $sendToMe = true; 
        } 

       } 
      } 

     if($sendToMe) { 
     $mail = Mage::getModel('core/email'); 
     $mail->setToName('Your name'); 
     $mail->setToEmail('[email protected]'); 
     $mail->setBody('Order number '.$order->getIncrementId().' has items that need action'); 
     $mail->setSubject('Order '.$order->getIncrementId().' needs attention'); 
     $mail->setFromName('Your from name'); 
     $mail->setFromEmail('[email protected]'); 
     $mail->setType('text'); 

       try { 
        $mail->send(); 
       } catch (Exception $e) { 
        Mage::log($e); 
       } 
      } 



     endforeach; 
    } 
} 

그냥 제품이 당신의주의를 필요로하는지가 정의하는 프론트 엔드에서 볼 밤은 제품 속성을 생성하는 것이 더 효율적이 될 것이라고 메모 - needs_attention의 라인 예/아니오, 다음 명령을 스캔 따라 뭔가를 해당 속성에서 예 값에 대한 제품.)

+0

훌륭한 솔루션처럼 보인다. 전에 Magento 용 사용자 정의 모듈을 만들지는 않았지만 좋은 튜토리얼이있을 것입니다. 사용자 정의 속성을 사용할 때 위 코드를 어떻게 변경할 수 있습니까? 그건 분명히 갈 길 같습니다. –

+0

도움이 정말 기쁩니다. 다음과 같이 사용자 지정 특성을 사용하려면 : if ($ product-> getSku() == ('123'| '234'|| '345')) {/// 이렇게하십시오. $ attrValue = $ product-> getResource() -> getAttribute ('your_attr_code') -> getFrontend() -> getValue ($ product); if ($ attrValue == '예') {/// – PixieMedia

1

이 기능에 대한 사용자 지정 모듈을 만들 수 있습니다. 따라서 새 모듈에서는 Observer 이벤트 (checkout_onepage_controller_success_action)를 연결해야합니다. 그것은 특정 SKU에 따라 고객에게 이메일을 보낼 수 있습니다,이 sendEmailToCustomerForSales() 메소드에서,

 <checkout_onepage_controller_success_action> 
      <observers> 
       <xxx_checkout_success> 
        <type>singleton</type> 
        <class>[Your Module Name]/observer</class> 
        <method>sendEmailToCustomerForSales</method> 
       </xxx_checkout_success> 
      </observers> 
     </checkout_onepage_controller_success_action> 

을 그리고 : 당신은 다음과 같이 할 수 있습니다.

이 코드를 참조하십시오 :

public function sendEmailToCustomerForSales($observer) { 
    $orderId = (int)current($observer->getEvent()->getOrderIds()); 
    $order = Mage::getModel('sales/order')->load($orderId); 
    $itemCollection = $order->getItemsCollection(); 
    foreach($itemCollection as $item) { 
     $_product = Mage::getModel('catalog/product')->load($item->getProductId()); 
     if($_product->getSku() == '[Your specific sku]') { 
      /*send an email to the customer*/ 
     } 
    } 
}