1

we have multi vendor site and we gave an option for vendor to update product information from frontend. we are using following code for price.

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


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

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

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

      }

we are using similar code for quantity and its not working fine

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

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

      }

we are using following code to update both price and quantity. only price is working, quantity is not updating.

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 deleted from your account'));
        $this->_redirect('marketplace/marketplaceaccount/myproductslist/');


    }}
1

replace this

$product->setQty($qty[$key]);

with

afte see you website you have to give separate name for every quantity field. because for some product quantity is not there.

$j=0;
  foreach ($ids as $key => $value) {
$j=$j+1;
$qty = $this->getRequest()->getParam('qty'.$j);
$product = Mage::getModel('catalog/product')->load($value);

$product->setPrice($price[$key]); 

$product->save();

 $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($value);

        $stockItem->setData('manage_stock', 1);
        $stockItem->setData('qty', $qty);
        $stockItem->save();
 }
2

Try this

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

      $stockItem =Mage::getModel('cataloginventory/stock_item')->loadByProduct($value);
      $stockItemId = $stockItem->getId();
      $product->set('price',$price[$key]); 
      $stockItem->setData('manage_stock', 1);
      $stockItem->setData('qty', (integer)$qty[$key]);

      $stockItem->save();

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


}}
  • Fatal error: Call to a member function set() on a non-object in line : $product->set('price',$price[$key]); – Baby in Magento Feb 24 '16 at 7:24
  • did you debug $price[$key] and $qty[$key] they return any value? – Shakir Khan Feb 24 '16 at 7:29
  • no, how to debug? – Baby in Magento Feb 24 '16 at 7:30
  • for stock Mage::getModel('cataloginventory/stock_item') this model used but you was using wrong model – Shakir Khan Feb 24 '16 at 7:30
  • just after foreach type echo '<pre>'; print_r($price[$key]); echo '</pre>'; – Shakir Khan Feb 24 '16 at 7:31
1

Try this

$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
$stockItemId = $stockItem->getId();
//echo $stockItemId;
if ($stockItemId) {
        if($Qty==0):
           $stockItem->setData('use_config_manage_stock', 0);
           $stockItem->setData('manage_stock', 1);
           $stockItem->setData('is_in_stock', 0);
           $stockItem->setData('qty', 0);

        else:
           $stockItem->setData('use_config_manage_stock', 1);
           $stockItem->setData('manage_stock', 0);
           $stockItem->setData('is_in_stock', 1);
           $stockItem->setData('qty', $Qty);

        endif;
        $stockItem->save();
        unset($stockItem);
        echo "Done";
    }
  • sorry, it did't worked for me, still values are not updating – Baby in Magento Feb 25 '16 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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