简体   繁体   中英

Category based newsletter emails? Magento CE 1/6/2

does anyone have an idea on how I could send newsletter emails to customers based on the category that they ordered from? So for instance, i would like to send a monthly email to customers who purchased exam gloves to restock their supply.

Here is one way to go about it:

1) get all of the (recent) orders

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

Note: replace '2012-04-16 15:56:33' with correct date and timestamp.

2) Get the product's ordered

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) Find out what category the product comes from

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) Send out a specific template to those customers (see code in first answer of this question) Sending e-mail programmatically in Magento is failing

Hope this was helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM