Tengo un observador que quita los artículos del carro si están agotados (es decir, el cliente regresa a su carrito x tiempo, y un artículo en el carro se ha agotado), y muestra un mensaje al usuario.Magento recalcula el total del carrito en el observador
La eliminación de los elementos funciona, pero la actualización del total del carrito no. ¡Cualquier ayuda sería muy apreciada!
Mi observador observa el evento sales_quote_save_before:
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');
}
puede aceptar la respuesta para que otros sepan que está resuelta –