2

we have multi vendor site. we are giving option for vendor to edit all textfields of multiple products and save all by clicking on one "Update" button....

we are using following code for saving price of one text field.

Price

public function updateFieldPriceAction(){
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);      
    $id= $this->getRequest()->getParam('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);

    try{
    $upd_price = $this->getRequest()->getParam('price');
    $product = Mage::getModel('catalog/product')->load($id);        
    //$product->setData('price', $upd_price);
    $product->setPrice($upd_price);

    //$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
    //$stockItem->setData('manage_stock', 1);
    //$stockItem->setData('qty', $this->getRequest()->getParam('qty'));
    $product->save();

    echo $price = $product->getPrice();
    echo $name = $product->getName();

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


    //endif;
    }catch(Exception $e){
    echo "Not Saving"; exit;    
    Mage::log($e->getMessage());
    }

  }

we are using following code to save quantity of one text field.

Quantity

public function updateFieldAction(){
        $id= $this->getRequest()->getParam('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);
        $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
        $stockItem->setData('manage_stock', 1);
        $stockItem->setData('qty', $this->getRequest()->getParam('qty'));

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

we are using following code to save all textfields of price and quantity by single update button. Price is working. but quantity is not working.

controller.php

public function massupdatesellerproAction(){
    if($this->getRequest()->isPost()){
        if(!$this->_validateFormKey()){
             $this->_redirect('marketplace/marketplaceaccount/myproductslist/');
        }
        $ids= $this->getRequest()->getParam('product_mass_update');
        $price= $this->getRequest()->getParam('price');
        $qty = $this->getRequest()->getParam('qty');
        foreach ($ids as $key => $value) {
    $product = Mage::getModel('catalog/product')->load($value);
    $product->setPrice($price[$key]);
    $product->setQty($qty[$key]);
    $product->save();
        }
        Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully saved from your account'));
        $this->_redirect('marketplace/marketplaceaccount/myproductslist/');


    }}

enter image description here

2
  • post you fields too.. Commented Dec 31, 2015 at 4:29
  • tell me what code fields code you want ? Commented Dec 31, 2015 at 5:13

1 Answer 1

2

you can achieve functionality with below code

function updateAllField(product_id) 
{ 
var priceId = '#price_'+ product_id; // for price 
var SpecpriceId = '#specialprice_'+ product_id; // for special price 
var quantity = '#quantity_'+ product_id; // for quantity 
var currprice='#curr_'+ product_id; 
var updatedqty = '#updatedprice_'+ product_id; 
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/singlerowupdate/')?>'; 
$price = $wk_jq(priceId).val(); 
$specialprice = $wk_jq(SpecpriceId).val(); 
$quantity = $wk_jq(quantity).val(); 
$wk_jq(currprice).val($price); 
new Ajax.Request(url, { 
method: 'post', 
parameters: {id: product_id, price: $price, speprice: $specialprice,quantity:$quantity}, 
onComplete: function (transport) { 
//alert(transport.responseText); 

jQuery(updatedqty).show().delay(2000).fadeOut(); 

} 
}); 
}

for controller

public function singlerowupdateAction(){
    if($this->getRequest()->isPost()){
        if(!$this->_validateFormKey()){
             $this->_redirect('marketplace/marketplaceaccount/myproductslist/');
        }
        $id= $this->getRequest()->getParam('id');
        $price= $this->getRequest()->getParam('price');
        $speprice= $this->getRequest()->getParam('speprice');
        $qty = $this->getRequest()->getParam('quantity');

    $product = Mage::getModel('catalog/product')->load($id);
    $product->setPrice($price);
    $product->setSpecialPrice($price);
    $product->setQty($qty);
    $product->save();

        Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully saved from your account'));
        $this->_redirect('marketplace/marketplaceaccount/myproductslist/');


    }}
2
  • i added your code, but its not working.... Commented Dec 31, 2015 at 5:13
  • it is a sample code add you original ids. and on button click call this function Commented Dec 31, 2015 at 5:19

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.