【发布时间】:2018-07-04 10:20:36
【问题描述】:
当产品有货时,我需要向客户发送 SMS(通过使用任何 SMS API)。
我重写了 Mage_ProductAlert_Model_Observer 类并在我的 自定义模块 的 Observer.php 文件中添加了 SMS API,但它不向客户发送 SMS。为什么?
此外,它只显示两个客户的详细信息,而不是所有订阅产品库存警报的客户。这是我的代码
Observer.php
<?php
class My_Alert_Model_ProductAlert_Observer
{
public function process()
{
$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);
}
}
}
?>
config.xml
<?xml version="1.0"?>
<config>
<modules>
<My_Alert>
<version>0.0.1</version>
</My_Alert>
</modules>
<global>
<models>
<my_alert>
<class>My_Alert_Model</class>
</my_alert>
</models>
</global>
<crontab>
<jobs>
<my_alert>
<schedule>
<cron_expr>*/5 * * * *</cron_expr>
</schedule>
<run>
<model>my_alert_productalert/observer::process</model>
</run>
</my_alert>
</jobs>
</crontab>
<frontend>
<routers>
<My_Alert_First>
<use>standard</use>
<args>
<module>My_Alert</module>
<frontName>my-alert</frontName>
</args>
</My_Alert_First>
</routers>
</frontend>
</config>
谁能分享这是什么问题以及为什么没有发送短信? 我正在使用 Magento 1.9。
【问题讨论】: