Php Magento-产品页面上的库存通知不足
我正在使用Magento 1.7.0.2。在产品页面上,如果客户试图添加的数量超过我们的库存,他们会收到一条消息,说明“所需数量不可用” 发生这种情况时,magento有没有办法发送电子邮件或登录?即,我收到一封自动电子邮件,说明客户已尝试添加项目X的X号?这将使我能够确定由于我们没有足够的库存而导致的销售损失 以前有没有人遇到过这样的事情,或者这可能吗 先谢谢你Php Magento-产品页面上的库存通知不足,php,magento,notifications,e-commerce,Php,Magento,Notifications,E Commerce,我正在使用Magento 1.7.0.2。在产品页面上,如果客户试图添加的数量超过我们的库存,他们会收到一条消息,说明“所需数量不可用” 发生这种情况时,magento有没有办法发送电子邮件或登录?即,我收到一封自动电子邮件,说明客户已尝试添加项目X的X号?这将使我能够确定由于我们没有足够的库存而导致的销售损失 以前有没有人遇到过这样的事情,或者这可能吗 先谢谢你 迈克·普伦蒂斯(Mike Prentice)没有通过电子邮件通知低数量产品的标准功能。 但是有RSS通知 扩展此功能以满足您的需要。
迈克·普伦蒂斯(Mike Prentice)没有通过电子邮件通知低数量产品的标准功能。
但是有RSS通知 扩展此功能以满足您的需要。
您可以编写一些脚本来解析RSS、发送电子邮件等 编辑 这里有一些您可能喜欢的扩展
但是不是免费的。是的,这是可能的 你必须为此编写代码。 我有一次遇到这个问题,下面就是我所做的 我有一个观察员事件,以检查客户是否要求数量超过可用数量,如果是这样,我发送电子邮件给管理员 您可以为
chekout\u cart\u add\u在事件之前创建一个观察者。在此事件中,您可以放置逻辑
或者,您可以使用magento功能缺货您可以在库存选项卡中找到此功能,如果启用此功能,则客户甚至可以订购请求数量>可用数量,客户可以在购物车页面上看到一条关于缺货的消息。以下是我如何做到的,这样每当客户试图订购超过可用库存水平的商品时,它就会发送一个google analytics跟踪事件
第一个副本:app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
收件人:app/code/local/Mage/CatalogInventory/Model/Stock/Item.php
这样您就不会修改核心文件
在app/code/local/Mage/CatalogInventory/Model/Stock/Item.php中添加此函数
public function notifyOutOfStock($productId){
$session = Mage::getSingleton('checkout/session');
//Initialise as empty array, or use existing session data
$outOfStockItems = array();
if ($session->getOutOfStock()){
$outOfStockItems = $session->getOutOfStock();
}
try {
$product = Mage::getModel('catalog/product')->load($productId);
$sku = $product->getSKu();
if($sku){
//Add the current sku to our out of stock items (if not already there)
if(! isset($outOfStockItems[$sku]) ) {
$outOfStockItems[$sku] = 0;
}
}
} catch (Exception $e){
//Log your error
}
Mage::getSingleton('checkout/session')->setOutOfStock($outOfStockItems);
}
在同一个文件中还有另一个函数,名为checkQuoteItemQty。
在该函数中,您需要使用$this->notifyOutOfStock($this->getProductId())调用新函数设置每个错误消息之后和return语句之前
因此:
公共函数checkQuoteItemQty($qty,$summaryQty,$origQty=0)
{
....
如果($this->getMinSaleQty()&($qty)<$this->getMinSaleQty()){
$result->setHasError(真)
->设置消息(
$\u helper->\uuuuu('允许购买的最小数量为%s',$this->getMinSaleQty()*1)
)
->setQuoteMessage($\u helper->\uuuuu('无法按要求数量订购某些产品'))
->setQuoteMessageIndex(“数量”);
//**调用新函数**
$this->notifyOutOfStock($this->getProductId());
返回$result;
}
.....
->setQuoteMessageIndex(“数量”);
//**调用新函数**
$this->notifyOutOfStock($this->getProductId());
返回$result;
.....
这样做的目的是在签出会话中将产品sku添加到阵列中。
这意味着您可以在页面加载并显示“库存不足”通知后立即访问模板文件中的信息
因此,您可以在其中一个模板文件中添加一些代码来呈现必要的JavaScript。
我选择header.phtml,因为它会在每个页面上加载。(用户可以在购物车页面以及产品视图页面中向购物车添加大量的项目)
app/design/frontend/CUSTOMNAME/default/template/page/html/header.phtml
在代码底部的某个地方添加以下内容:
<!-- GA tracking for out of stock items -->
<script>
try {
<?php
$session = Mage::getSingleton('checkout/session');
if ($session->getOutOfStock()){
$outOfStockItems = $session->getOutOfStock();
foreach($outOfStockItems as $sku=>$value) {
if($value==0){
//Render the GA tracking code
echo "_gaq.push(['_trackEvent', 'AddToCart', 'ProductQtyNotAvailable', '".$sku."']); \r\n";
//Set it to 1 so we know not to track it again this session
$outOfStockItems[$sku] = 1;
}
}
//Update the main session
Mage::getSingleton('checkout/session')->setOutOfStock($outOfStockItems);
}
?>
}
catch(err) {
//console.log(err.message);
}
</script>
试一试{
这个社区网站可能会让你感兴趣
<!-- GA tracking for out of stock items -->
<script>
try {
<?php
$session = Mage::getSingleton('checkout/session');
if ($session->getOutOfStock()){
$outOfStockItems = $session->getOutOfStock();
foreach($outOfStockItems as $sku=>$value) {
if($value==0){
//Render the GA tracking code
echo "_gaq.push(['_trackEvent', 'AddToCart', 'ProductQtyNotAvailable', '".$sku."']); \r\n";
//Set it to 1 so we know not to track it again this session
$outOfStockItems[$sku] = 1;
}
}
//Update the main session
Mage::getSingleton('checkout/session')->setOutOfStock($outOfStockItems);
}
?>
}
catch(err) {
//console.log(err.message);
}
</script>