magento站点单击取消正在更改其他一些文本字段值

时间:2015-12-23 11:19:24

标签: javascript magento

我们正在使用magento marketplace多供应商网站。

我们为供应商提供了一个更新前端产品详细信息的选项。

我们正在使用此代码更新价格。工作正常。

PHTML

<input class="ama1" type = "text" id = "price_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "price[]" value = "<?php echo $products->getPrice(); ?>" style = ""/>

<input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?php echo $products->getId(); ?>" value="<?php echo $products->getPrice(); ?>" />

<p id="updatedprice_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>

<button id="price_update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateFieldPrice('<?php echo $products->getId(); ?>'); return false;" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>

<button id="price_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetPrice('<?php echo $products->getId(); ?>','<?php echo $products->getPrice(); ?>'); return false;">
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>

JS

<script>

function hideResetPrice(product_id,priceold) { 

var qtyId='#price_'+ product_id; 
var currprice='#curr_'+ product_id; 
var editLink="#price_edit_link_"+ product_id; 
var updateButton="#price_update_button_"+ product_id; 
var valueprice="#valueprice_"+ product_id; 
var resetButton="#price_reset_button_"+ product_id; 


$wk_jq(valueprice).show(); 
$wk_jq(qtyId).val( $wk_jq(currprice).val()); 
$wk_jq(editLink).show(); 

}



function showFieldPrice(product_id)
        {

            var qtyId='#price_'+ product_id;

            var editLink="#price_edit_link_"+ product_id;
            var valueprice="#valueprice_"+ product_id;
            var updateButton="#price_update_button_"+ product_id;
            var resetButton="#price_reset_button_"+ product_id;

            $wk_jq(qtyId).show();
            $wk_jq(valueprice).hide();

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(updateButton).prop('disabled', false);//just in case
            $wk_jq(resetButton).show();

            return false;


        }


function updateFieldPrice(product_id) 
{ 
var priceId = '#price_'+ product_id; 
var currprice='#curr_'+ product_id; 
var updatedqty = '#updatedprice_'+ product_id; 
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldPrice/')?>'; 
$price = $wk_jq(priceId).val(); 
$wk_jq(currprice).val($price); 
new Ajax.Request(url, { 
method: 'post', 
parameters: {id: product_id, price: $price}, 
onComplete: function (transport) { 
//alert(transport.responseText); 

jQuery(updatedqty).show().delay(2000).fadeOut(); 

} 
}); 
}

我们正在使用以下代码来处理属性&#34; local&#34;值。 最初我们会修改价格值。一旦我们输入一些本地值的数字,如果我们点击本地的取消按钮,它显示以前更新的价值&#34;价格&#34; 不是本地价值

本地代码

<?php $attribute = $products->getResource()->getAttribute('local');?>
<?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= "price[]" value = "<?php echo $attribute_value; ?>" style = ""/>
<?php endif; ?>


<input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?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_update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateFieldLocal('<?php echo $products->getId(); ?>'); return false;" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>

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

JS

function hideResetLocal(product_id,localold) { 

var qtyId='#local_'+ product_id; 
var currlocal='#curr_'+ 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 showFieldLocal(product_id)
        {

            var qtyId='#local_'+ product_id;

            var editLink="#local_edit_link_"+ product_id;
            var valuelocal="#valuelocal_"+ product_id;
            var updateButton="#local_update_button_"+ product_id;
            var resetButton="#local_reset_button_"+ product_id;

            $wk_jq(qtyId).show();
            $wk_jq(valuelocal).hide();

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(updateButton).prop('disabled', false);//just in case
            $wk_jq(resetButton).show();

            return false;


        }




function updateFieldLocal(product_id) 
{ 
var localId = '#local_'+ product_id; 
var currlocal='#curr_'+ 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(); 

} 
}); 
}

1 个答案:

答案 0 :(得分:0)

您必须更改本地的ID

 <input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?php echo $products->getId(); ?>" value="<?php echo $products->getLocal(); ?>" />  

更改 改为

 <input type="hidden" name="localcurr_<?php echo $products->getId(); ?>" id="localcurr_<?php echo $products->getId(); ?>" value="<?php echo $products->getLocal(); ?>" /> 

与js中的相同

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

} 
}); 
}