1

有没有人知道我如何根据客户订购的类别向客户发送时事通讯电子邮件?例如,我想每月向购买了检查手套的客户发送一封电子邮件,以补充他们的供应。

4

1 回答 1

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)向这些客户发送特定模板(请参阅此问题的第一个答案中的代码)在 Magento 中以编程方式发送电子邮件失败

希望这有帮助

于 2012-12-20T22:56:57.583 回答