2011-10-03 16 views
11

में कार्ट कुल का पुनर्मूल्यांकन करता है मेरे पास एक पर्यवेक्षक है जो कार्ट से वस्तुओं को हटा देता है अगर वे स्टॉक से बाहर हैं (यानी ग्राहक अपने कार्ट एक्सटर समय पर वापस आते हैं, और कार्ट में एक आइटम स्टॉक से बाहर हो गया है), और उपयोगकर्ता को एक संदेश दिखाता है।Magento पर्यवेक्षक

आइटम (ओं) कार्यों को हटा रहा है, लेकिन कार्ट कुल को अद्यतन नहीं करता है। किसी भी मदद की सराहना की जाएगी! * _save_after अवलोकन और बदलने के लिए एक ही वस्तु के लिए मजबूर करने की कोशिश कर रहा द्वारा सामान्य रूप से फिर से बचाने के लिए कॉल करेगा: दिन के लिए

public function checkStockStatus($observer) 
{ 
    // return if disabled or observer already executed on this request 
    if (!Mage::helper('stockcheck')->isEnabled() || Mage::registry('stockcheck_observer_executed')) { 
     return $this; 
    } 

    $quote = $observer->getEvent()->getQuote(); 
    $outOfStockCount = 0; 

    foreach ($quote->getAllItems() as $item) { 
     $product = Mage::getModel('catalog/product')->load($item->getProductId()); 
     $stockItem = $product->getStockItem(); 
     if ($stockItem->getIsInStock()) { 
      // in stock - for testing only 
      $this->_getSession()->addSuccess(Mage::helper('stockcheck')->__('in stock')); 
      $item->setData('calculation_price', null); 
      $item->setData('original_price', null); 
     } 
     else { 
      //remove item 
      $this->_getCart()->removeItem($item->getId()); 
      $outOfStockCount++; 
      $this->_getSession()->addError(Mage::helper('stockcheck')->__('Out of Stock')); 
     } 
    } 

    if ($outOfStockCount) > 0) {  
     $quote->setTotalsCollectedFlag(false)->collectTotals(); 
    } 

    Mage::register('stockcheck_observer_executed', true); 

    return $this;   
} 

protected function _getCart() 
{ 
    return Mage::getSingleton('checkout/cart'); 
} 

protected function _getSession() 
{ 
    return Mage::getSingleton('checkout/session'); 
} 

उत्तर