we are using magento marketplace multivendor site.
we gave an option for vendor to update the product details in frontend.
we are using this code for updating the price. its working fine.
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();
}
});
}
we are using following code for attribute "local" value. initially we edit price value. than once we enter some number in local value and if we click on cancel button of local, its showing previously updated value of "price" not local value
Local Code
<?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();
}
});
}