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?




<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'); ?>"/> -->

<p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p>

<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 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>


      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;


             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/')?>';



            $qty = $wk_jq(qtyId).val();

            var tmpQty=parseInt(assignqty)+ parseInt($qty) ;

            new Ajax.Request(url, {
                method: 'post',
                parameters: {id: product_id, qty: $qty},
                onComplete: function (transport) {
            // $wk_jq(priceId).setValue($price);


                    $updateButton.prop('disabled', false);

                    // $wk_jq(qtyId).setValue($qty);





   public function updateFieldAction(){
        $id= $this->getRequest()->getParam('id');
        $collection_product = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('mageproductid',array('eq'=>$id))->addFieldToFilter('userid',array('eq'=>$customerid));
        $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
        $stockItem->setData('manage_stock', 1);
        $stockItem->setData('qty', $newqty);


        $response['message'] = 'Your Product Is Been Sucessfully Updated';
        //Mage::getSingleton('core/session')->addSuccess(Mage::helper('marketplace')->__('Your Product Is Been Sucessfully Updated'));

2 Answers 2


In your template's function function updateField(product_id,assignqty), you see

var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';

Which generates a url like http://example.com/marketplace/marketplaceaccount/updateField where you will be sending Ajax request. It will hit updateFieldAction() method defined in your controller.

Now, in your controller, you will get data sent from template form using $id= $this->getRequest()->getParam('id');.

Next, you have $selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($id); which is used to get instance of Model with mpassignproduct/mpassignproduct. In extension's etc/config.xml file, you will find nodes like


Which will give your model path, so Mage::getModel('mpassignproduct/mpassignproduct'); gives an instance of class Namespace_Modulename_Model_Mpassignproduct and getAssignProDetails() function will be defined in your model, which by the given name seems will take an argument product id, and return assigned product details of the product whose id you will send as function argument.

  • Nice, thanks for awesome explaination. just for experiment, i used public function updateFielAction() instead of updateFieldAction() . but still it working, after i changed the function name ? Commented Feb 28, 2016 at 7:36
  • Where you've changed it? Clear your magento/browser cache and it should work. Also, have you changed updateFileAction() to updateFielAction() or you have added new function updateFielAction() to test it ?
    – amitshree
    Commented Feb 28, 2016 at 7:39
  • I didt added, but just renamed it. cache was disabled in site before doing changes. but you are right. it''s browser problem. Commented Feb 28, 2016 at 7:45

You can't update field value in database without help of controller.

controllers are responsible for processing all requests made via a url.

From your code you request to update qty field.

Simply increase value of field you can use jquery but if you want to update field in model you need to call controller for save field.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.