Get customer product alert subscriptions list in Magento

Some things are easy, some things are not. This one is easy-peasy.

If you want to get the product list that a customer has been subscribed to (price or stock alert), you need to use the productalert model.

  • Product stock alert list
$customer_id = Mage::getSingleton('customer/session')->getCustomer()->getId();
$customer_stock_alerts = Mage::getModel('productalert/stock')
         ->getCollection()
         ->addFieldToFilter('customer_id', $customer_id);
foreach ( $customer_stock_alerts as $alert )
{
 echo $alert->getProductId();
}
  • Product price alert list
$customer_id = Mage::getSingleton('customer/session')->getCustomer()->getId();
$customer_price_alerts = Mage::getModel('productalert/price')
         ->getCollection()
         ->addFieldToFilter('customer_id', $customer_id);
foreach ( $customer_price_alerts as $alert )
{
 echo $alert->getProductId();
}

3 comments

  1. Reply

    But Here, you are not write where I put this code. For this I need to make the Module using the Module Creator or need to set this code in any File. please Help me.

    Thanks

      • Pau on April 11, 2013 at 5:29 am
      • Author

      Reply

      Hi rixitrixit,

      You should include your module into your block or model, that’s up to your needs!

    • idan abada on January 10, 2014 at 1:36 am

    Reply

    it didn’t work… I tried putting it in the file at the end of: Subscriber.php
    but it shows nothing. I tried to put it as an html on a page in magento also did not work. I will be SO HAPPY if you can tell me to create a new file that I can put a code in and see all the product alerts to back in stock items!

    thank you so much!!!!!

Leave a Reply

Your email address will not be published.