有没有人知道我如何根据他们订购的类别向客户发送简讯电子邮件?例如,我想每月向购买考试手套的客户发送电子邮件,以补充供应。
答案 0 :(得分: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
希望这是有帮助的