Update all textfields of multiple products by clicking one update button
-
19-10-2020 - |
سؤال
we are using magento multi vendor site.
For single Product we are displaying price, selling price , quantity...etc in vendor account.
we gave an option for vendor to update all the textfields of single product by clicking on one "update" button.
we are using following code for this.
PHTML
<button id="update_button_<?php echo $products->getId(); ?>" class="button wk_mp_btn1" onclick="updateAllFields('<?php echo $products->getId(); ?>'); return false;" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>
Javascript
function updateAllFields(product_id) {
updateFieldPrice(product_id);
updateFieldSpecialPrice(product_id);
updateField(product_id);
}
Now we want to provide an option for update all textfields of multiple products by clicking on one "update" button. Ex: for one product we will edit price , for second we will edit price and qty, for third price, quantity , special price . we edit all textfield values and enter the button "save all".
In the image, last but one column, you can see "save all" button. once we click on that button it should save all the field values.
المحلول
you can add product id
as in array
same as for price field
and special price field
<input type="hidden" name="product_mass_update[]" value="<?php echo $products->getEntityId(); ?>"/>
<input class="ama1" type = "text" id = "price_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "price[]" value = "<?php echo $products->getPrice(); ?>" style = ""/>
<input class="ama1" type = "text" id = "specialprice_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "specialprice[]" value = "<?php echo $products->getSpecialPrice(); ?>" onblur="updateFieldSpecialPrice('<?php echo $products->getId(); ?>')" style = ""/>
for massupdate
for all record
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');
$special= $this->getRequest()->getParam('specialprice');
foreach ($ids as $key => $id) {
$product = Mage::getModel('catalog/product')->load($id);
$product->setPrice($price[$key]);
$product->setSpecialPrice($special[$key]);
$product->save();
}
Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully deleted from your account'));
$this->_redirect('marketplace/marketplaceaccount/myproductslist/');
}}