I am using an extension, in that they wrote some code in phtml and in some controller file. I posted the code below.
But I want to know how it's linked, I guess they are using some get(), but I believe there should be common words in both the file, then only it will work. but in below code, I can't find any common words.
Also without the help of the controller file, can we update using Ajax?
<?php $selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($products->getId()); //Zend_Debug::dump($selllermpassignproduct,null,true); $stock_item=Mage::getModel('cataloginventory/stock_item')->loadByProduct($products); $SellerQty=isset($selllermpassignproduct['sellerqty'])?$selllermpassignproduct['sellerqty']: $stock_item->getQty(); $assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0; ?> <input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock<?php echo $j ?>" class="ama1" value = "<?php echo (int) $SellerQty; ?>" /> <span class="label wk_action" id="edit_link_<?php echo $products->getId(); ?>"> <!-- <img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/> --> </span> <p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p> <br/> <button id="update_button_<?php echo $products->getId(); ?>" class="buttons" onclick="updateField('<?php echo $products->getId(); ?>',<?php echo $assignqty;?>); return false;" style="display:none" > <span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span> </button> <button id="reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideReset('<?php echo $products->getId(); ?>'); return false;" > <span><span><?php echo $helper->__('Cancel') ?></span></span> </button> <script> function hideReset(product_id) { var qtyId='#qty_'+ product_id; var editLink="#edit_link_"+ product_id; var updateButton="#update_button_"+ product_id; var resetButton="#reset_button_"+ product_id; $wk_jq(qtyId).hide(); $wk_jq(editLink).show(); $wk_jq(updateButton).hide(); $wk_jq(resetButton).hide(); } function updateField(product_id,assignqty) { var qtyId = '#qty_'+ product_id; var valueId = '#valueqty_'+ product_id; var updatedqty = '#updatedqty_'+ product_id; var editLink = "#edit_link_"+ product_id; var updateButton = "#update_button_"+ product_id; var resetButton = "#reset_button"+ product_id; var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>'; //$wk_jq(qtyId).toggle() $wk_jq(editLink).hide(); //$wk_jq(updateButton).show(); $wk_jq(resetButton).show(); $qty = $wk_jq(qtyId).val(); jQuery(valueId).html($qty); //hideReset(product_id); var tmpQty=parseInt(assignqty)+ parseInt($qty) ; new Ajax.Request(url, { method: 'post', parameters: {id: product_id, qty: $qty}, onComplete: function (transport) { //alert(transport.responseText); jQuery(priceId).val($price); // $wk_jq(priceId).setValue($price); //jQuery(updatedqty).show().delay(2000).fadeOut(); $updateButton.prop('disabled', false); // $wk_jq(qtyId).setValue($qty); } }); } </script> Controllers
<?php public function updateFieldAction(){ $id= $this->getRequest()->getParam('id'); $selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($id); $customerid=Mage::getSingleton('customer/session')->getCustomerId(); $collection_product = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('mageproductid',array('eq'=>$id))->addFieldToFilter('userid',array('eq'=>$customerid)); //Mage::getSingleton('core/session')->setEditProductId($id); $assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0; $newqty=$this->getRequest()->getParam('qty')+$assignqty; $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id); $stockItem->setData('manage_stock', 1); $stockItem->setData('qty', $newqty); $stockItem->save(); $response['message'] = 'Your Product Is Been Sucessfully Updated'; $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); //Mage::getSingleton('core/session')->addSuccess(Mage::helper('marketplace')->__('Your Product Is Been Sucessfully Updated')); }