【问题标题】:Magento - Insufficient Stock Notification on Product PageMagento - 产品页面上的库存不足通知
【发布时间】:2013-03-14 10:20:21
【问题描述】:

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

发生这种情况时,magento 有什么方法可以发送电子邮件或记录? IE。我收到一封自动电子邮件,说明客户已尝试添加 X 件商品 X?这将使我能够确定由于我们没有足够的特定商品库存而导致的销售损失?

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

提前谢谢你

迈克·普伦蒂斯

【问题讨论】:

标签: php magento notifications e-commerce


【解决方案1】:

是的,这是可能的 你必须为此编写代码。 我曾经遇到过这个问题,我在下面做了这样的事情。

我已经做了一个观察者事件来检查客户是否要求数量超过可用数量,如果是这样,我向管理员发送了电子邮件。

您可以做的是为chekout_cart_add_before 事件创建一个观察者,在此事件中您可以放置​​您的逻辑。

或者你可以使用magento功能延期交货你可以在库存标签中找到这个,如果你启用这个,那么客户可以订购甚至请求数量>可用数量,客户可以在购物车页面中看到一条消息关于延期交货。

【讨论】:

    【解决方案2】:

    没有通过电子邮件通知产品数量不足的标准功能。
    但是有RSS通知http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/system_config/edit/cataloginventory

    扩展此功能以满足您的需求。
    您可以编写一些脚本来解析 RSS,并发送电子邮件等。

    编辑

    这里有一些你可能喜欢的扩展http://www.magentocommerce.com/magento-connect/low-stock-email-notification.html
    但是不是免费的。

    【讨论】:

      【解决方案3】:

      以下是我的做法,以便在客户尝试订购超过可用库存水平时发送谷歌分析跟踪事件。

      第一个副本: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()); 调用新函数。

      所以:

       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,因为它会在每个页面上加载。 (用户可以在购物车页面以及产品查看页面中将商品数量添加到购物车)。

      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>
      

      可以确认这很有效,并且在我看来比电子邮件或 RSS 提要更好,因为您可以将其与其他分析一起分析。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-08
        • 1970-01-01
        • 2012-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多