【发布时间】:2016-04-04 18:00:47
【问题描述】:
我们有 magento 网站。我们为供应商提供了编辑多个产品的所有文本字段并通过单击一个“更新”按钮保存所有文本字段的选项。
我们正在使用以下代码来节省一个文本字段的价格。
价格
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());
}
}
我们正在使用以下代码来节省一个文本字段的数量。
数量
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'));
}
我们使用以下代码通过单个更新按钮保存价格和数量的所有文本字段。价格在起作用。但数量不起作用。
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/');
}}
【问题讨论】:
标签: javascript php database magento