【问题标题】:SMS not Sending to Customers from Observer.php短信未从 Observer.php 发送给客户
【发布时间】: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。

【问题讨论】:

    标签: php api magento sms alert


    【解决方案1】:

    在 Magento 中处理 Product Stock Alert 收集的方法。我们的客户有超过 40.000 名订阅者,超过 30.000 名正在等待状态从“缺货”更改为“有货”。因此,当 Magento 尝试将 40.000 条记录从表 product_alert_stock 加载到集合以获取它们时,由于内存限制 php 失败。

    我认为你没有更改核心文件,你可以使用你的扩展程序覆盖这个 link 帮助你。

    【讨论】:

    • 是的,我已经创建了我的自定义模块。请检查我更新的问题。但是短信仍然没有发送给客户。为什么?
    • 你能查一下这张表product_alert_stock里面有多少记录吗?
    • 是的,记录在那里。此外,我已经为每五分钟设置了最短的 cron 时间,并且工作正常。因此确认产品警报邮件正在发送给客户,没有任何问题。但唯一的问题是短信不发送。为什么?
    • 不,我已经直接测试过并且工作正常。你能检查我上面的模块吗?
    • 是否获取所有 $customer_mobile 的手机号码?
    猜你喜欢
    • 2023-03-08
    • 2017-06-22
    • 2017-12-15
    • 1970-01-01
    • 2015-08-05
    • 2021-08-15
    • 2014-10-13
    • 1970-01-01
    相关资源
    最近更新 更多