通过单击一个更新按钮保存所有文本字段 [英] save all textfields by clicking on one update button

查看:71
本文介绍了通过单击一个更新按钮保存所有文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有magento网站.我们为供应商提供了选择,可以通过单击一个"更新"按钮来编辑多个产品的所有文本字段并保存所有文本字段.

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

我们正在使用以下代码来节省一个文本字段的价格.

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

价格

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.

数量

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


    }}

推荐答案

setQty在magento中不起作用.数量通常会在产品中而不是库存中保存.删除

setQty not working in magento. quantity generally save on stock not in product. remove

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

来自您的控制器.

这是部分答案,但希望它能向正确的方向发送信息. 您可以尝试通过controller.php中的以下代码节省数量

This is a partial answer, but hopefully it sends you in the right direction. You can try to save quantity by below code in controller.php

 $product->setStockData(
   array( 
          'is_in_stock' => 1, 
          'qty' => $qty[$key],
          'manage_stock' => 1,
          'use_config_notify_stock_qty' => 1
   )
 );

或 你可以 尝试使用此 controller.php :

or you can Try this controller.php instead:

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

,然后像以前一样设置并保存您的更改. 您可以此 a>.

and then set and save your changes as before. you can check this.

这是您进行数量更新的全部功能

this is your full function for quantity update

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();
        $product = Mage::getModel('catalog/product')->load( 'id' );
        $product->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'));
      }

控制器代码

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->setStockData(
       array( 
        'is_in_stock' => 1, 
        'qty' => $qty[$key],
        'manage_stock' => 1,
        'use_config_notify_stock_qty' => 1
       )
    );


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


}}

这篇关于通过单击一个更新按钮保存所有文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆