1

注文したカテゴリに基づいて、ニュースレターのメールを顧客に送信する方法について誰かが考えていますか?たとえば、試験用手袋を購入した顧客に毎月メールを送信して、補給品を補充したいと思います。

4

1 に答える 1

3

これを実行する1つの方法は次のとおりです。

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 に答える