我们有市场多供应商/卖家网站。我们为卖方提供了通过前端更新产品信息的选项.....
由于它是市场网站,我们有很多卖家。
卖家A在前端上传了产品A [quantity = 20]
如果卖家B有相同的产品,他会将相同的产品分配到他的帐户[quantity = 5]
在后端显示20 + 5 = 25数量。
现在的问题是,当卖家A将数量从20更新为40时,它在前端显示40,一旦我们刷新页面,它只显示35。刷新后显示数量 [卖家A数量 - 卖家B数量]
但应显示卖家A 数量。
在它正常工作之前,我们稍后进行了一些代码更改,而不是我们面临的这个问题。
在qty文本字段看起来像在图像中之前一旦我们点击图片中的“编辑”按钮,它就像下图:
但我们决定在下面显示图片:
因此我们将代码更改为上图。比这个问题发生了。
代码前: [一切正常]
<td> <?php $selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($products->getId()); //Zend_Debug::dump($selllermpassignproduct,null,true); $stock_item=Mage::getModel('cataloginventory/stock_item')->loadByProduct($products); $SellerQty=isset($selllermpassignproduct['sellerqty'])?$selllermpassignproduct['sellerqty']:$stock_item->getQty(); $assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0; ?> <span id="valueqty_<?php echo $products->getId(); ?>"><?php echo (int) $SellerQty; ?></span> <input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" value = "<?php echo (int) $SellerQty; ?>" style = "display:none"/> <span class="label wk_action" id="edit_link_<?php echo $products->getId(); ?>"> <img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/> </span> <p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red;">Updated</p> <br/> <button id="update_button_<?php echo $products->getId(); ?>" class="buttons" onclick="updateField('<?php echo $products->getId(); ?>',<?php echo $assignqty;?>); return false;" style="display:none" > <span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span> </button> <button id="reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideReset('<?php echo $products->getId(); ?>'); return false;" style="display:none" > <span><span><?php echo $helper->__('Cancel') ?></span></span> </button>
脚本
function hideReset(product_id) { var qtyId='#qty_'+ product_id; var editLink="#edit_link_"+ product_id; var updateButton="#update_button_"+ product_id; var resetButton="#reset_button_"+ product_id; $wk_jq(qtyId).hide(); $wk_jq(editLink).show(); $wk_jq(updateButton).hide(); $wk_jq(resetButton).hide(); } function updateField(product_id,assignqty) { var qtyId = '#qty_'+ product_id; var valueId = '#valueqty_'+ product_id; var updatedqty = '#updatedqty_'+ product_id; var editLink = "#edit_link_"+ product_id; var updateButton = "#update_button_"+ product_id; var resetButton = "#reset_button"+ product_id; var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>'; $wk_jq(qtyId).toggle() $wk_jq(editLink).hide(); $wk_jq(updateButton).show(); $wk_jq(resetButton).show(); $qty = $wk_jq(qtyId).val(); jQuery(valueId).html($qty); hideReset(product_id); var tmpQty=assignqty+ parseInt($qty) ; new Ajax.Request(url, { method: 'post', parameters: {id: product_id, qty: tmpQty}, onComplete: function (transport) { //alert(transport.responseText); jQuery(priceId).val($price); // $wk_jq(priceId).setValue($price); jQuery(updatedqty).show().delay(2000).fadeOut(); $updateButton.prop('disabled', false); // $wk_jq(qtyId).setValue($qty); } }); }
现有代码
在上面的代码中,我们评论了一些行,我们替换了一些代码,如下所示。
评论代码
<!-- <img onclick="showField('<?php echo $products->getId(); ?>'); return false;" src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?> --> **script** //$wk_jq(qtyId).toggle() //$wk_jq(updateButton).show(); //hideReset(product_id); //jQuery(updatedqty).show().delay(2000).fadeOut();
替换代码1)
<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" value = "<?php echo (int) $SellerQty; ?>" style = "display:none"/>
以
<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" class="ama1" value = "<?php echo (int) $SellerQty; ?>" />
替换代码2)
var tmpQty=assignqty+ parseInt($qty) ; new Ajax.Request(url, { method: 'post', parameters: {id: product_id, qty: tmpQty},
以
var tmpQty=parseInt(assignqty)+ parseInt($qty) ; new Ajax.Request(url, { method: 'post', parameters: {id: product_id, qty: $qty},
答案 0 :(得分:0)
我找到了第一个问题的解决方案。
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');
$i=1;
foreach ($ids as $key => $value) {
$i=$i+1;
$qty = $this->getRequest()->getParam('stock'.$i);
$product = Mage::getModel('catalog/product')->load($value);
$product->setPrice($price[$key]);
$product->setSpecialPrice($special[$key]);
//$product->setQty($qty);
$product->save();
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($value);
$stockItem->setData('manage_stock', 1);
$stockItem->setData('qty', $qty);
$stockItem->save();
}
Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully deleted from your account'));
$this->_redirect('marketplace/marketplaceaccount/myproductslist/');
}}