-
- Luiz Alvaro

-
Total Posts: 11
Joined: 2010-12-29
|
Hello Folks,
I Trying to update .data-table table with ajax after delete some item from magento cart, I couldn’t figure out who put this to work.
Delete function
public function deleteAction(){ $id = (int) $this->getRequest()->getParam('id'); if ($id) { try { $this->_getCart()->removeItem($id) ->save(); $this->_getSession()->setCartWasUpdated(true); if (!$this->_getCart()->getQuote()->getHasError()){ $response['status'] = 'SUCCESS'; $response['message'] = $message; $this->loadLayout(); $block = $this->getLayout()->getBlock('checkout.cart'); Mage::register('referrer_url', $this->_getRefererUrl()); $checkout = $block->toHtml(); $response['checkout'] = $checkout; } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); return; } catch (Exception $e) { $this->_getSession()->addError($this->__('Cannot remove the item.')); Mage::logException($e); } } }
default.phtml button/script
<script type="text/javascript"> function setLocationAjax(url,id){ url += '&isAjax;=1'; url = url.replace("checkout/cart","ajax/index"); try { jQuery.ajax( { url : url, dataType : 'json', success : function(data) { if(jQuery('.data-table')){ jQuery('.data-table').replaceWith(data.checkout); } } }); } catch (e) { } } </script>
<td class="a-center"><a href="[removed]void(0)" onclick="setLocationAjax('<?php echo $this->getDeleteUrl(); ?>','<?php echo $_item->getId()?>')" title="<?php echo $this->__('Remove item')?>" class="btn-remove btn-remove2"><?php echo $this->__('Remove item')?></a></td>
sry about my english >.<
|