php - Ajax delete product from cart in magento -


i have been working magento cart pro extension. ajax add cart functionality, have followed following link excellance magento blog

its working fine.but have searched lot regarding ajax delete item cart, google returns me 3rd party extension. can't find tutorial delete product cart. thought, take referrance 1 of free 3rd party extension have both add cart , delete cart functionality. found following extension have above both function , working rock. ajax cart pro .

i have checked extension coding part. i'm confused, can't find code doing delete functionality. have overwrite deleteaction in controller file only, think.i can't understand i'm doing.i need guidance add ajax delete functionality.

if have idea or found tutorial of this, please share me thoughts friends.

diving ajaxcart extension, in controller's action, find (yeah, right!), following line removing item:

$this->_getcart()->removeitem($id)->save();

public function deleteaction() {     $id = (int) $this->getrequest()->getparam('id');     if ($id) {         try {             $this->_getcart()->removeitem($id)                     ->save();         } catch (exception $e) {             $_response = mage::getmodel('ajaxcart/response');             $_response->seterror(true);             $_response->setmessage($this->__('cannot remove item.'));             $_response->send();              mage::logexception($e);         }     }      $_response = mage::getmodel('ajaxcart/response');      $_response->setmessage($this->__('item removed.'));      //append updated blocks     $this->getlayout()->getupdate()->addhandle('ajaxcart');     $this->loadlayout();      $_response->addupdatedblocks($_response);      $_response->send(); } 

so answering question "which code doing delete", it's therein;)

and understand whole process, should have in mind these points:

  • ajaxcart.js - they're overriding magento's setlocation function , doing ajax call(in ajaxcartsubmit method):

    var oldsetlocation = setlocation; var setlocation = (function() {     return function(url){        if( url.search('checkout/cart/add') != -1 ) {             //its simple/group/downloadable product             ajaxcart.ajaxcartsubmit(url); 
  • to render a button use url helper, this:

    <button type="button" title="add cart" class="button btn-cart"     onclick="setlocation('<?php echo $this->helper('checkout/cart')->getaddurl($_product, $additional = array('qty' => 1));?>')">  + </button> 
  • updateblocks. there observer , response models grabs list of blocks update/replace on frontend, renders contents , put em json reponse.

    $updated_blocks = unserialize(mage::getstoreconfig('ajaxcart/general/update_blocks')); // ... each $layout->getblock('<blockname>')->tohtml() , add json responce 
  • a blocks definitions taken core layout , additional ajaxcart handle (layout/ajaxcart.xml). (cart_sidebar, top.links & etc.)


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -