php商品低库存报警,Magento中产品库存不报警解决方案
简单说来,这个事件在Magento处理产品报库存警的集合方法里。我们的客户有超过40000封订阅和超过30000个需要将“缺货”状态改为“有货”。所以当Magento尝试从product_alert_stock表读取40000条记录到集合里的时候,由于内存限制而失败了。可能你的product_alert_stock表有超过20000记录时,产品库存报警功能就失效了。
解决方案相对简单。通过以1000为集合创建分页来遍历超过30000条记录。正如Magento在系统中所做的那样。新的功能是通过遍历所有的这些记录,循环出status=0(未处理)的记录,检查产品现在是否有货。当true=> set status=1就发送电子邮件通知客户。
那么,让我们创建我们的模块,Alwayly_ProductAlert,这将提高Magento方法。
1. Create file in app/etc/modules/ Alwayly_ProductAlert.xml with the following content:
true
local
2. Create file in app/code/local/Alwayly/ProductAlert/etc/ config.xml with the following content:
1.0.0.0
Alwayly_ProductAlert_Model_Observer
你可以看到我们重写了Mage_ProductAlert_Model_Observer类
Create file in /www/app/code/local/Alwayly/ProductAlert/Model/ Observer.php with the following content:
/*
* ProductAlert observer
*/
class Alwayly_ProductAlert_Model_Observer extends Mage_ProductAlert_Model_Observer
{
/**
* Process stock emails
*
* @param Mage_ProductAlert_Model_Email $email
* @return Mage_ProductAlert_Model_Observer
*/
protected function _processStock(Mage_ProductAlert_Model_Email $email)
{
$email->setType('stock');
foreach ($this->_getWebsites() as $website) {
/* @var $website Mage_Core_Model_Website */
if (!$website->getDefaultGroup() || !$website->getDefaultGroup()->getDefaultStore()) {
continue;
}
if (!Mage::getStoreConfig(
self::XML_PATH_STOCK_ALLOW,
$website->getDefaultGroup()->getDefaultStore()->getId()
)) {
continue;
}
try {
$wholeCollection = Mage::getModel('productalert/stock')
->getCollection()
// ->addWebsiteFilter($website->getId())
->addFieldToFilter('website_id', $website->getId())
->addFieldToFilter('status', 0)
;
// $wholeCollection->getSelect()->order('alert_stock_id DESC');
/* table: !product_alert_stock!
alert_stock_id: 1
customer_id: 1
product_id: 1
website_id: 1
add_date: 2013-04-26 12:08:30
send_date: 2013-04-26 12:28:16
send_count: 2
status: 1
*/
}
catch (Exception $e) {
Mage::log('error-1-collection $e=' . $e->getMessage(), false, 'product_alert_stock_error.log', true);
$this->_errors[] = $e->getMessage();
return $this;
}
$previousCustomer = null;
$email->setWebsite($website);
try {
$originalCollection = $wholeCollection;
$count = null;
$page = 1;
$lPage = null;
$break = false;
while ($break !== true) {
$collection = clone $originalCollection;
$collection->setPageSize(1000);
$collection->setCurPage($page);
$collection->load();
if (is_null($count)) {
$count = $collection->getSize();
$lPage = $collection->getLastPageNumber();
}
if ($lPage == $page) {
$break = true;
}
Mage::log('page=' . $page, false, 'check_page_count.log', true);
Mage::log('collection=' . (string)$collection->getSelect(), false, 'check_page_count.log', true);
$page ++;
foreach ($collection as $alert) {
try {
if (!$previousCustomer || $previousCustomer->getId() != $alert->getCustomerId()) {
$customer = Mage::getModel('customer/customer')->load($alert->getCustomerId());
if ($previousCustomer) {
$email->send();
}
if (!$customer) {
continue;
}
$previousCustomer = $customer;
$email->clean();
$email->setCustomer($customer);
}
else {
$customer = $previousCustomer;
}
$product = Mage::getModel('catalog/product')
->setStoreId($website->getDefaultStore()->getId())
->load($alert->getProductId());
/* @var $product Mage_Catalog_Model_Product */
if (!$product) {
continue;
}
$product->setCustomerGroupId($customer->getGroupId());
if ($product->isSalable()) {
$email->addStockProduct($product);
$alert->setSendDate(Mage::getModel('core/date')->gmtDate());
$alert->setSendCount($alert->getSendCount() + 1);
$alert->setStatus(1);
$alert->save();
}
}
catch (Exception $e) {
Mage::log('error-2-alert $e=' . $e->getMessage(), false, 'product_alert_stock_error.log', true);
$this->_errors[] = $e->getMessage();
}
}
}
Mage::log("\n\n", false, 'check_page_count.log', true);
} catch (Exception $e) {
Mage::log('error-3-steps $e=' . $e->getMessage(), false, 'product_alert_stock_error.log', true);
}
if ($previousCustomer) {
try {
$email->send();
}
catch (Exception $e) {
$this->_errors[] = $e->getMessage();
}
}
}
return $this;
}
/**
* Run process send product alerts
*/
public function process()
{
Mage::log('ProductAlert started @' . now(), false, 'product_alert_workflow.log', true);
$email = Mage::getModel('productalert/email');
/* @var $email Mage_ProductAlert_Model_Email */
$this->_processPrice($email);
$this->_processStock($email);
$this->_sendErrorEmail();
Mage::log('ProductAlert finished @' . now(), false, 'product_alert_workflow.log', true);
return $this;
}
}
你可以看到,我们重写了process()和 _processStock()方法。在process()方法中,我们添加了Mage::log()创建起止时间到var/log/product_alert_workflow.log。这样我们就能知道脚本是否执行完成。同样的,我们增强_processStock()方法的功能,我们增加了一些Mage:log()调用来跟踪,看所有的行为是否按期待的方式表现。
最后,如果你不想等待你的Cron被触发,你可以在Magento根目录下创建一个文件,让我们调用它。
Alwayly_cron.php
require_once 'app/Mage.php';
Mage::app();
try {
Mage::getModel('productalert/observer')->process();
} catch (Exception $e) {
Mage::log('error-0-start $e=' . $e->getMessage() . ' @' . now(), false, 'product_alert_stock_error.log', true);
}
就是这些了,这个解决思路同样适用于产品价格报警。
(责任编辑:最模板)
php商品低库存报警,Magento中产品库存不报警解决方案相关推荐
- 浅析B2C电商产品中的“库存”概念
电商产品最复杂的模块莫过于"后台模块",而后台模块中较为复杂的又莫过于"库存管理",而一般来讲B2C电商产品中的库存包括七大部分,分别是:可销售库存.订单占用库 ...
- Magento根据产品SKU查询产品库存状态
//根据SKU查询产品库存状态$product = Mage::getModel('catalog/product')->loadByAttribute('sku','HB400');$stoc ...
- Magento 中产品属性筛选器的使用
在Magento中,提供了使用商品属性对产品进行筛选的功能,在分类页的侧栏中显示,如果没有设定好要进行筛选的属性,那么默认只显示 使用子分类进行产品筛选.筛选器的默认标题是 shop by 上图中的c ...
- oracle错误1327,Oracle中的PGA监控报警分析(r11笔记第97天)
最近接到一个数据库报警,让我颇有些意外,这是一个PGA相关的报警.听起来感觉是应用端的资源调用出了问题. 报警内容大体如下: 报警内容: PGA Alarm on alltest ---------- ...
- Magento中直接使用SQL语句
原理: magento是基于Zend Framework的,所以底层用的还是zend的zend db 在文件app/code/core/Mage/Catalog/model/Resource/Eav ...
- 用于Power BI Desktop中的库存数据分析的烛台图
Candlestick chart for stock data analysis in Power BI Desktop 用于Power BI Desktop中的库存数据分析的烛台图 Power B ...
- 货物与产品的区别_商品与一般物品和其他产品有什么区别?
展开全部 1.定义不同. 商品是为了出售而生产的人62616964757a686964616fe4b893e5b19e31333431356665类劳动成果,是用于交换的劳动产品.一般物品指的是实体的 ...
- wpf中图片滚动效果demo_如何将商品视觉化运用到店铺中?小型文具店货架效果图文具店货架图片...
开一家小店,守一纸书香,是我的一个小小的愿望.2014年也曾开过饮食店,因为不喜欢,还因为一些特殊原因最终以转让收场.2015年找了个单位,朝八晚五的上了一年班,每天重复着无聊的日子,又感觉生活没了动 ...
- ABAP 中历史库存
mard里记载的是当前库存的数量,但是期间并不一定是当月.比如你物料4月一整月都没有库存数量变化(没收没发),那么5月初你看mard里的条目期间数还是4月而非5月. 当 某个期间发生货物移动的时候,系 ...
最新文章
- sklearn(五)计算acc:使用metrics.accuracy_score()计算分类的准确率
- Excel随机排考号方法
- 67 个节省开发者时间的实用工具、库与资源(前端向)
- 锂电系统上位—数据中心更高效率运营
- android 固定大小,android 固定大小取图片缩略图
- Educational Codeforces Round 47 (Rated for Div. 2) :E. Intercity Travelling
- REST / HTTP方法:POST与PUT与PATCH
- 互联网晚报 | 12月31日 星期五 | 滴滴发布上市后首份财报;商汤科技正式登陆港交所;我国高铁运营里程突破4万公里...
- bat执行java文件_.bat文件执行java程序
- Hibernate bean 对象配制文件
- 推荐两个漂亮的编程字体
- Cobar-Client 实现策略总结
- Python3.x伪随机,元素重排,矩阵
- Python处理CSV大文件特定行数据
- Step by Step-构建自己的ORM系列-ORM改进方案思考(上)
- alidoing --使用JS实现多语言框架、喜欢的请进、、瓦特平台!
- 《Java编程思想第五章》:初始化与内存
- css 中的度量单位
- Vue3.0----综合案例(第七章)
- PHP学习记录【php数据类型】
热门文章
- Intel 64/x86_64/IA-32/x86处理器 - 指令格式(2) - 8086/16位指令格式概述
- python变量的赋值操作_Python中关于变量赋值操作的实例分享
- 双稳态电路的两个稳定状态是什么_利用SR锁存器实现SPDT开关消抖电路
- java 字符串 面试_JAVA中String介绍及常见面试题小结
- Unity有哪些让做项目事半功倍的插件值得推荐?
- Xcode8 + Swift3.0 创建一个app基础框架
- layDate1.0正式公布,您一直在寻找的的js日期控件
- Hadoop集群部署权限总结
- fgetc与EOF的错综复杂关系
- lamp软件包安装(rpm)