0

I need to send SMS (By using any SMS API) to customers when products are back in stock.

I have added my SMS API in Mage_ProductAlert_Model_Observer class under public_html/app/code/core/Mage/ProductAlert/Model/Observer.php file but its not sending SMS to customers. Why?

Also its only showing two customers details instead of all customers subscribed to product stock alert. Here is my code

 public function process()
    {
        $email = Mage::getModel('productalert/email');
        /* @var $email Mage_ProductAlert_Model_Email */
        $this->_processPrice($email);
        $this->_processStock($email);
        $this->_sendErrorEmail();

        return $this;

    $customer_stock_alerts = Mage::getModel('productalert/stock')->getCollection()->addStatusFilter(0)->setCustomerOrder();
    foreach ($customer_stock_alerts as $alert){
      $stock_back_product = $alert->getProductId();
      $current_product=Mage::getModel('catalog/product')->load($stock_back_product);
      $current_product_name = $current_product->getName();
      $customer_info = Mage::getModel('customer/customer')->load($alert->getCustomerId());
      $customer_name = $customer_info->getPrimaryBillingAddress()->getFirstname();
      $customer_mobile = $customer_info->getPrimaryBillingAddress()->getTelephone(); 
      $message = 0;     
      $message = "Dear $customer_name, Product $current_product_name is back in Stock";
      $message=urlencode($message);
      $sendsms = "http://api.msg91.com/api/sendhttp.php?sender=MSGIND&route=4&mobiles=$customer_mobile&authkey=xxxxxxxxxxxxxxxxxxx&country=91&message=$message";
      file_get_contents($sendsms);     
    }
    }

Can anyone share what's the issue this & why SMS is not sending?

Thanks.

0

The Magento core uses the method Mage_ProductAlert_Model_Observer::process() to send email alerts. You can either rewrite this class and connect it to your SMS API, or take the functionality of this class as an inspiration to setup your own class with custom configuration settings.

  • Hi, Can you please let me know how to rewrite this class it to my SMS API? Because I can't able to use this into my custom module's Observer.php. So send me the code. – Mesk Jan 18 '18 at 17:35
  • Hi, I have rewrite that class in my module's observer.php and tried to connect my SMS API. But its not working. Can you please let me know how to get the customers list who needs product back in stock alerts programatically? – Mesk Jan 19 '18 at 6:14
  • No, I can't. I don't know your SMS provider, and I don't know your current code. I also don't know the error - and "it's not working" is not an error description ;) – simonthesorcerer Jan 19 '18 at 16:20
  • Ok. @simonthesorcerer Please check my code and updated question above. – Mesk Jan 24 '18 at 10:28
0

You can try checking this codebase as reference and follow it.

https://github.com/pmclain/module-twilio?files=1

Or

If you don't know how to rewrite use Magento 2 module generation tools like below to rewrite the classes. It will provide you a skeleton. Later you can change the logic accordingly.

1.http://mage2gen.com 2. http://www.silksoftware.com/magento-module-creator/magento2x.php

  • Hi, For your information my Magento version is 1.9. Will your answer is compatible for 1.9 version as well? – Mesk Jan 19 '18 at 3:33
  • Hi, you can try below for Magento 1.x This is a sample module you can follow and understand github.com/kojoman/magento-twilio-integration To rewrite Magento 1.x classes, you can try this Magento 1 module generation tool silksoftware.com/magento-module-creator – Kalyan Chakravarthi V Jan 19 '18 at 5:49
  • Hi, its not helped me. I know that Mage_ProductAlert_Model_Observer::process() will send emails when product back in stock. Same way I have rewrite that class in my module's observer.php and tried to connect my SMS API. But its not working. Why? – Mesk Jan 19 '18 at 6:10
  • 1. There will be a way to test the SMS API. Did you test and SMS are going? 2. If SMS is going normally, then it should work with the observer. please share or post the module code, it will help us to analyze more about the problem. – Kalyan Chakravarthi V Jan 19 '18 at 9:38
  • Ok. @KalyanChakravarthi Please check my code and updated question above. – Mesk Jan 24 '18 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.