我們一直在使用第三方來包裝和運送我們的包裹。因此我們看不到所有經過的訂單。Magento:訂購特定商品時發送通知
但有幾種產品我們必須自己手動供應,比如數字禮品卡。當客戶訂購了特定SKU時,是否可以讓Magento向我們發送電子郵件?例如,要通知我們,我們需要爲客戶創建一張禮品卡?
我不想看到我們的郵箱中的每一個訂單,只是一些特定的SKU。
感謝, 緬
我們一直在使用第三方來包裝和運送我們的包裹。因此我們看不到所有經過的訂單。Magento:訂購特定商品時發送通知
但有幾種產品我們必須自己手動供應,比如數字禮品卡。當客戶訂購了特定SKU時,是否可以讓Magento向我們發送電子郵件?例如,要通知我們,我們需要爲客戶創建一張禮品卡?
我不想看到我們的郵箱中的每一個訂單,只是一些特定的SKU。
感謝, 緬
是的,這可以用自定義模塊來實現。創建你的模塊並添加一個事件觀察者到它的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的線是/否,然後掃描所訂購的東西產品在該屬性中爲是的值。比您正在尋找的SKU硬編碼更易於管理;)
您可以爲此功能創建自定義模塊。因此,在新模塊中,您必須掛鉤Observer事件:checkout_onepage_controller_success_action。 你可以像如下:
<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>
而且,在這個sendEmailToCustomerForSales()方法,它可以根據特定的SKU發送電子郵件給客戶。
請參閱驗證碼:
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*/
}
}
}
這似乎是一個很好的解決方案。我以前沒有爲Magento創建過自定義模塊,但希望能有一些很好的教程。使用自定義屬性時,如何改變上述代碼的任何想法?這絕對看起來像是要走的路。 – 2014-12-03 11:11:18
真的很高興它有幫助。要使用自定義屬性,而不是: if($ product-> getSku()==('123'||'234'||'345')){/// 這樣做; ($ product); $ getAttribute('your_attr_code') - > getFrontend() - > getValue($ product); $ getAttribute('your_attr_code') - > getTextValue = $ product-> getResource() if($ attrValue =='Yes'){/// – PixieMedia 2014-12-03 11:42:37