2013-03-14 68 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提要更好,因爲您可以將其與其他分析結果一起分析。