2013-03-14 69 views
3

我正在使用Magento 1.7.0.2。在产品页面上,如果客户尝试添加比我们库存更多的数量,他们会收到一条消息,指出“..所请求的数量不可用”。Magento - 产品页面上的库存不足通知

当发生这种情况时,magento是否有任何电子邮件或日志的方式?即我收到一封自动发送的电子邮件,指出客户已尝试添加X号物品X?这可以让我确定由于我们没有足够的特定物品库存而导致销售损失?

有没有人遇到过这样的事情,或者这甚至有可能吗?

预先感谢您

迈克·普伦蒂斯

+0

此社区网站对你而言可能是有趣的http://magento.stackexchange.com/ – 2013-03-14 10:28:51

回答

0

是的,这是可能的 你必须为此编码。 我遇到过这个问题一次,我有这样做下面。

我已经做了一个观察员事件来检查客户是否请求数量更多然后如果是这样我发送电子邮件给管理员。

你可以做的是创建一个观察者chekout_cart_add_before事件在这个事件中你可以把你的逻辑。

或者以其他方式,你可以使用Magento的功能延期交货您可以在库存标签上找到此,如果启用此则客户可以订购甚至请求的数量>可用数量,客户可以看到购物车页约缺货一条消息。

0

下面是我如何做到这一点,以便当客户尝试订购超过可用库存水平的产品时,它会发送一个谷歌分析跟踪事件。

首页复印:应用程序/代码/核心/法师/ CatalogInventory /型号/库存/ Item.php

要:应用程序/代码/本地/法师/ CatalogInventory /型号/库存/ Item.php

这样你就不会修改核心文件。

应用程序/代码/本地/法师/ CatalogInventory /型号/库存/ 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())来调用你的新函数。在它设置每个错误消息之后和返回语句之前。

所以:

public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0) 
{ 
    .... 
    if ($this->getMinSaleQty() && ($qty) < $this->getMinSaleQty()) { 
     $result->setHasError(true) 
      ->setMessage(
       $_helper->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1) 
      ) 
      ->setQuoteMessage($_helper->__('Some of the products cannot be ordered in requested quantity.')) 
      ->setQuoteMessageIndex('qty'); 

      //** Call to new function ** 
      $this->notifyOutOfStock($this->getProductId()); 

     return $result; 
    } 
    ..... 
     ->setQuoteMessageIndex('qty'); 

      //** Call to new function ** 
      $this->notifyOutOfStock($this->getProductId()); 

     return $result; 
    ..... 

这样做是添加你的产品SKU在结账会话的数组。 这意味着在页面加载显示“库存不足”通知后,您将有权访问模板文件中的该信息。

因此,在您的一个模板文件中,您可以添加一些代码来呈现必要的JavaScript。 我选择了header.phtml,因为它在每个页面上加载。 (用户可以在购物车页面以及产品视图页面上将大量商品添加到购物车中)。

应用程序/设计/前端/ CUSTOMNAME /默认/模板/页/ 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> 

能否证实这个作品以及在我看来,比电子邮件或RSS提要更好,因为您可以将其与其他分析结果一起分析。