2012-12-20 55 views
1

沒有人有關於如何發送通訊電子郵件給客戶基於他們訂購的類別的想法嗎?因此,例如,我想每月發送一封電子郵件給購買檢測手套以補充其供應的客戶。基於類別的新聞郵件? Magento CE 1/6/2

+0

或者如果它是做很多工作至少可以根據訂購的類別輸出客戶姓名/電子郵件地址列表。我知道它在數據庫中導出... – Joeymetro

+0

您可以編寫一個查詢來從數據庫中提取數據。將產品鏈接到訂單商品和訂單信息。 – JNDPNT

回答

3

這裏是去做一個辦法:

1)獲取所有的(最近)的訂單

$orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('created_at', '2012-04-16 15:56:33'); 

注:更換'2012-04-16 15:56:33'用正確的日期和時間戳。

2)獲取產品的訂購

foreach($orders as $order): 
    // let's get some the order info 
    $orderData = $order->getData(); 
    // extract the order ID from the order objecj (so we can load the whole order) 
    $orderId = $orderData['entity_id']; 
    // extract the customer's ID (so that we can find out customer's email) 
    $customerId = $orderData['customer_id']; 
    // load the customer by ID 
    $customer = Mage::getModel('customer/address')->load($customerId)->getData(); 
    // get customer's email address 
    $customerEmail = $customer['email']; 
    // load the full order (so that we can get a list of product's ordered 
    $fullOrder = Mage::getModel('sales/order')->load($orderId); 
    // extract the products from the order 
    $products = $fullOrder->getAllItems(); 
endforeach; 

3)找出類別中的產品來自

foreach ($products as $product): 
    // let's get an object with the ordered product's data 
    $productInfo = $product->getData(); 
    // extract the product ID (so that we can load the product) 
    $prodId = $productInfo['item_id']; 
    // load the product 
    $product = Mage::getModel('catalog/product')->load($prodId); 
    // get all (names of) categories that this product is associated with 
    $categories = $product->getCategoryCollection()->addAttributeToSelect('name'); 
endforeach; 

4)發送一個特定的模板,這些客戶(見代碼第一個答案這個問題)Sending e-mail programmatically in Magento is failing

希望這有幫助