2

As this is marketplace multi vendor site, we are displaying vendor product information in frontend.

List of products informations are displaying as in image :

enter image description here

If we want to edit any information like "Product name, Price, sku, qty....etc", at the last column, you can see "Action" column, below that there is a Edit button, we will click on that and new page will open as below image :

enter image description here

than we will enter the new "Qty value" and click on "save" button. Its working awesome without any problem.

we are using this code for editing quanity button : app/design/frontend/default/default/template/mpassignproduct/editassignproduct.phtml

<li class="fields">
<div class="customer-name">
<div class="field">
<label class="required" for="qty"><em>*</em><?php echo $helper->__('Quantity')?></label>
<div class="input-box">
<input type="text" name="qty" id="qty" value="<?php echo intval($mpAssignProductModel->getQty()) ?>"
 class="required-entry validate-zero-or-greater input-text"/>
</div>
</div>
</div>
</li>

but i want to provide an option to edit the quantity without clicking the "Edit" button present below "Action" column. in the 1st image , you can see "edit" button below "Qty". once we click on that, its displaying as following image :

enter image description here

once we change the value and click on "Update" buton, it show the updated value. but once we refresh the page, it show old value only.

I used same code in mpassignproduct.phtml . but it didt worked for me.

means code worked editassignproduct.phtml didt worked mpassignproduct.phtml

or did i missed some code ?

so we used following code for editing qty, but this also same problem.

`app/design/frontend/default/default/template/mpassignproduct/mpassignproduct.phtml`  [full code : http://pastebin.com/TSd7CVxC ]

PHtml

    <td>
    <span class="label qty" id="valueqty_<?php echo $assinproducts->getId(); ?>">
        <?php echo intval($assinproducts['qty']); ?>
    </span>

    <input type = "text" id = "qty_<?php echo $assinproducts->getId(); ?>" onkeydown="validateNumbers(event)" 
    name="stock" value="<?php echo intval($assinproducts['qty']); ?>" style="display:none;"/>

    <span class="label wk_action" id="edit_link_<?php echo $assinproducts->getId(); ?>">
        <img onclick="showField('<?php echo $assinproducts->getId(); ?>'); return false;" 
        src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
    </span>

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

    <button id="update_button_<?php echo $assinproducts->getId(); ?>" class="button wk_mp_btn1" 
    onclick="updateField('<?php echo $assinproducts->getId(); ?>',<?php echo intval($assinproducts['qty']); ?>); return false;" style="display:none" >
        <span>
            <span style="font-size:12px;"><?php echo $helper->__('Update') ?></span>
        </span>
    </button>

    <button id="reset_button_<?php echo $assinproducts->getId(); ?>" type="reset" class="cancel" 
    onclick="hideReset('<?php echo $assinproducts->getId(); ?>'); return false;" style="display:none"></button> 
</td>

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 showField(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).show();
        $wk_jq(editLink).hide();
        $wk_jq(updateButton).show();
        $wk_jq(updateButton).prop('disabled', false);//just in case
        $wk_jq(resetButton).show();

        return false;
    }



    function updateField(product_id,assignqty)
    {

    //  alert("Hello! I am an alert box!!");
        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 = assignqty+parseInt($qty) ;

        new Ajax.Request(url, {
            method: 'post',
            parameters: {id: product_id, qty: tmpQty},
            onComplete: function (transport) {
            //  alert(tmpQty);
                jQuery(priceId).val($price);                
        jQuery(updatedqty).show().delay(2000).fadeOut();
                $updateButton.prop('disabled', false);
            }
        });
    }

controllers.php

public function updateFieldAction(){

            $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
            $id= $this->getRequest()->getParam('id');
            $pro=Mage::getModel('catalog/product')->load($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);
            if($selllermpassignproduct['seller_id']==$customerid)
            {

             $assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
             $newq=$pro->getQty()-$assignqty;
             $newqty=$this->getRequest()->getParam('qty')+$newq;
             $connectionresource = Mage::getSingleton('core/resource');
             $connectionWrite = $connectionresource->getConnection('core_write');
             $table1 = $connectionresource->getTableName('mpassignproduct/mpassignproduct');

            $connectionWrite->beginTransaction();

                      $data = array(

                          'assignqty' => $this->getRequest()->getParam('qty'),


                      );

                      $connectionWrite->update($table1, $data, array(
                              'seller_id = ?' => $customerid,
                              'mageproductid = ?' => $id,


                          ));
                      $connectionWrite->commit();

            }else {

            $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'));
          }

there are JS errors in console, is there any chance because of following js code , quantity is not saving ? if so how to resolve these errors.

enter image description here

5
  • how many time you posted this question i think it's already solved Commented Mar 10, 2016 at 5:11
  • No, this is related to assign product, you only solved normal products , its asigned products
    – user33510
    Commented Mar 10, 2016 at 5:13
  • you have update the assign product too with qunatity Commented Mar 10, 2016 at 5:15
  • add this table information.. mpassignproduct Commented Mar 10, 2016 at 5:19
  • please check here : prntscr.com/adcz1k
    – user33510
    Commented Mar 10, 2016 at 5:22

3 Answers 3

3
+50

you have to update the assign quantity too

 public function updateFieldAction(){
            //echo "gfggggg";
            //die;
            $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
            $id= $this->getRequest()->getParam('id');
            $pro=Mage::getModel('catalog/product')->load($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);
            if($selllermpassignproduct['seller_id']==$customerid)
            {

             $assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
             $newq=$pro->getQty()-$assignqty;
             $newqty=$this->getRequest()->getParam('qty')+$newq;
             $connectionresource = Mage::getSingleton('core/resource');
             $connectionWrite = $connectionresource->getConnection('core_write');
             $table1 = $connectionresource->getTableName('mpassignproduct/mpassignproduct');

            $connectionWrite->beginTransaction();

                      $data = array(

                          'assignqty' => $this->getRequest()->getParam('qty'),


                      );

                      $connectionWrite->update($table1, $data, array(
                              'seller_id = ?' => $customerid,
                              'mageproductid = ?' => $id,


                          ));
                      $connectionWrite->commit();

            }else {

            $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'));
          }
3
  • i replaced this function in controllers, but it didt worked. can i use same function for both normal and assigned products?
    – user33510
    Commented Mar 10, 2016 at 5:43
  • yes do some debug with check the for error and other thing what quantity is updated or not Commented Mar 10, 2016 at 5:54
  • okay, i will try and inform you.....
    – user33510
    Commented Mar 10, 2016 at 5:55
1

There is an exit() before you save()

1
  • i removed it, but still it did't worked.
    – user33510
    Commented Mar 10, 2016 at 5:23
1

I've found a logical problem regarding the "ids" and another problem when reloade the page.
in your code you are using this custom model

Mage::getModel('mpassignproduct/mpassignproduct')

in the phtml file you use:

<button id="update_button_<?php echo $assinproducts->getId(); ?>" class="button wk_mp_btn1" 
onclick="updateField('<?php echo $assinproducts->getId(); ?>',<?php echo intval($assinproducts['qty']); ?>); return false;" style="display:none" >
    <span>
        <span style="font-size:12px;"><?php echo $helper->__('Update') ?></span>
    </span>
</button>

after than in the js file you write :

function updateField(product_id,assignqty)

but $assinproducts->getId() IS NOT the product id but the id of the mpassignproduct entity.
you should use $assinproducts->getProductId() to get the product id.

The controller will then update correctly the product quantity in the stock item but when you refresh the page you are showing:

<span class="label qty" id="valueqty_<?php echo $assinproducts->getId(); ?>">
    <?php echo intval($assinproducts['qty']); ?>
</span>

you are usng the $assinproducts['qty'] value and not the product->stockitem->qty so I think that your controller MUST UPDATE both the product stock and the assinproducts['qty']

Hope this help Giuseppe

1
  • as you said, instead of $assinproducts->getId() , i tried this code : $assinproducts->getProductId() and please give me updated code for controllers to use both $assinproducts['qty'] & product->stockitem->qty
    – user33510
    Commented Mar 31, 2016 at 13:22

Your Answer

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