1つの更新ボタンをクリックしてすべての製品を更新するすべての属性値
-
28-09-2020 - |
質問
Magentoマルチベンダーサイトを使用しています。
単一の製品には、ベンダーアカウントの価格、販売価格、属性などが表示されています。
ベンダーには、1つの「更新」ボタンをクリックして単一の製品のすべてのテキストフィールドを更新するためのオプションを付けました。
これには次のコードを使用しています。その作業罰金
phtml
<?php $attribute = $products->getResource()->getAttribute('mp_local_shipping_charge');?>
<?php if($attribute):?>
<?php $attribute_value = $attribute ->getFrontend()->getValue($products); ?>
<input class="ama1" type = "text" id = "local_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "local[]" value = "<?php echo $attribute_value; ?>" style = ""/>
<?php endif; ?>
<input type="hidden" name="localcurr_<?php echo $products->getId(); ?>" id="localcurr_<?php echo $products->getId(); ?>" value="<?php echo $products->getLocal(); ?>" />
<p id="updatedlocal_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>
<button id="local_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetLocal('<?php echo $products->getId(); ?>','<?php echo $products->getPrice(); ?>'); return false;">
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>
</span>
.
JavaScript
function hideResetLocal(product_id,localold) {
var qtyId='#local_'+ product_id;
var currlocal='#localcurr_'+ product_id;
var editLink="#local_edit_link_"+ product_id;
var updateButton="#local_update_button_"+ product_id;
var valuelocal="#valuelocal_"+ product_id;
var resetButton="#local_reset_button_"+ product_id;
$wk_jq(valuelocal).show();
$wk_jq(qtyId).val( $wk_jq(currlocal).val());
$wk_jq(editLink).show();
}
function updateFieldLocal(product_id)
{
var localId = '#local_'+ product_id;
var currlocal='#localcurr_'+ product_id;
var updatedqty = '#updatedlocal_'+ product_id;
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldLocal/')?>';
$local = $wk_jq(localId).val();
$wk_jq(currlocal).val($local);
new Ajax.Request(url, {
method: 'post',
parameters: {id: product_id, local: $local},
//parameters: {id: product_id, local: $local},
onComplete: function (transport) {
//alert(transport.responseText);
jQuery(updatedqty).show().delay(2000).fadeOut();
}
});
}
.
controller.php
public function updateFieldLocalAction(){
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_local = $this->getRequest()->getParam('local');
$product = Mage::getModel('catalog/product')->load($id);
$product->setData('mp_local_shipping_charge',$upd_local);
$product->getResource()->saveAttribute($product,'mp_local_shipping_charge');
// $product->setLocal($upd_local);
$product->save();
echo $local = $product->getLocal();
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());
}
}
.
今すぐ、1つの「更新」ボタンをクリックして、複数の製品のすべてのテキストフィールドを更新するためのオプションを提供します。
EX:1つの製品のために私たちは価格を編集します、2番目の価格と数量、数量、特別価格のために価格と数量を編集します。すべてのテキストフィールド値を編集して、「すべてを保存」ボタンを入力します。
これには、次のコードを使用しています。
のカスタム属性のために機能しません。attribute id : mp_local_shipping_charge and attribute label is : Local
.
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');
$special= $this->getRequest()->getParam('specialprice');
$local= $this->getRequest()->getParam('mp_local_shipping_charge');
foreach ($ids as $key => $value) {
$product = Mage::getModel('catalog/product')->load($value);
$product->setPrice($price[$key]);
$product->setSpecialPrice($special[$key]);
$product->setLocal($mp_local_shipping_charge[$key]);
$product->save();
}
Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully deleted from your account'));
$this->_redirect('marketplace/marketplaceaccount/myproductslist/');
}}
. 解決
あなたのパラメータはあなたのコントローラのlocal
あなたが呼び出しているあなたが呼び出しているあなたの属性コードはそれ以上の$local= $this->getRequest()->getParam('mp_local_shipping_charge');
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');
$local= $this->getRequest()->getParam('local');
foreach ($ids as $key => $value) {
$product = Mage::getModel('catalog/product')->load($value);
$product->setPrice($price[$key]);
$product->setSpecialPrice($special[$key]);
$product->setMpLocalShippingCharge($local[$key]);
$product->save();
}
Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully deleted from your account'));
$this->_redirect('marketplace/marketplaceaccount/myproductslist/');
}}
. 所属していません magento.stackexchange