As this is marketplace multi vendor site, we are displaying vendor product information in frontend.
List of products informations are displaying as in image :
If we want to edit any information like "Product name, Price, sku, qty....etc"
, at the last column, you can see "Action" column, below that there is a Edit button, we will click on that and new page will open as below image :
than we will enter the new "Qty value" and click on "save" button. Its working awesome without any problem.
we are using this code for editing quanity button : app/design/frontend/default/default/template/mpassignproduct/editassignproduct.phtml
<li class="fields">
<div class="customer-name">
<div class="field">
<label class="required" for="qty"><em>*</em><?php echo $helper->__('Quantity')?></label>
<div class="input-box">
<input type="text" name="qty" id="qty" value="<?php echo intval($mpAssignProductModel->getQty()) ?>"
class="required-entry validate-zero-or-greater input-text"/>
</div>
</div>
</div>
</li>
but i want to provide an option to edit the quantity without clicking the "Edit" button present below "Action" column. in the 1st image , you can see "edit" button below "Qty". once we click on that, its displaying as following image :
once we change the value and click on "Update" buton, it show the updated value. but once we refresh the page, it show old value only.
I used same code in mpassignproduct.phtml . but it didt worked for me.
means code worked editassignproduct.phtml didt worked mpassignproduct.phtml
or did i missed some code ?
so we used following code for editing qty, but this also same problem.
`app/design/frontend/default/default/template/mpassignproduct/mpassignproduct.phtml` [full code : http://pastebin.com/TSd7CVxC ]
PHtml
<td>
<span class="label qty" id="valueqty_<?php echo $assinproducts->getId(); ?>">
<?php echo intval($assinproducts['qty']); ?>
</span>
<input type = "text" id = "qty_<?php echo $assinproducts->getId(); ?>" onkeydown="validateNumbers(event)"
name="stock" value="<?php echo intval($assinproducts['qty']); ?>" style="display:none;"/>
<span class="label wk_action" id="edit_link_<?php echo $assinproducts->getId(); ?>">
<img onclick="showField('<?php echo $assinproducts->getId(); ?>'); return false;"
src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>"/>
</span>
<p id="updatedqty_<?php echo $assinproducts->getId(); ?>" style = "display:none;color:red;">Updated</p><br/>
<button id="update_button_<?php echo $assinproducts->getId(); ?>" class="button wk_mp_btn1"
onclick="updateField('<?php echo $assinproducts->getId(); ?>',<?php echo intval($assinproducts['qty']); ?>); return false;" style="display:none" >
<span>
<span style="font-size:12px;"><?php echo $helper->__('Update') ?></span>
</span>
</button>
<button id="reset_button_<?php echo $assinproducts->getId(); ?>" type="reset" class="cancel"
onclick="hideReset('<?php echo $assinproducts->getId(); ?>'); return false;" style="display:none"></button>
</td>
Script
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 showField(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).show();
$wk_jq(editLink).hide();
$wk_jq(updateButton).show();
$wk_jq(updateButton).prop('disabled', false);//just in case
$wk_jq(resetButton).show();
return false;
}
function updateField(product_id,assignqty)
{
// alert("Hello! I am an alert box!!");
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(tmpQty);
jQuery(priceId).val($price);
jQuery(updatedqty).show().delay(2000).fadeOut();
$updateButton.prop('disabled', false);
}
});
}
controllers.php
public function updateFieldAction(){
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
$id= $this->getRequest()->getParam('id');
$pro=Mage::getModel('catalog/product')->load($id);
$selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($id);
$customerid=Mage::getSingleton('customer/session')->getCustomerId();
$collection_product = Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('mageproductid',array('eq'=>$id))->addFieldToFilter('userid',array('eq'=>$customerid));
//Mage::getSingleton('core/session')->setEditProductId($id);
if($selllermpassignproduct['seller_id']==$customerid)
{
$assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
$newq=$pro->getQty()-$assignqty;
$newqty=$this->getRequest()->getParam('qty')+$newq;
$connectionresource = Mage::getSingleton('core/resource');
$connectionWrite = $connectionresource->getConnection('core_write');
$table1 = $connectionresource->getTableName('mpassignproduct/mpassignproduct');
$connectionWrite->beginTransaction();
$data = array(
'assignqty' => $this->getRequest()->getParam('qty'),
);
$connectionWrite->update($table1, $data, array(
'seller_id = ?' => $customerid,
'mageproductid = ?' => $id,
));
$connectionWrite->commit();
}else {
$assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
$newqty=$this->getRequest()->getParam('qty')+$assignqty;
}
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
$stockItem->setData('manage_stock', 1);
$stockItem->setData('qty', $newqty);
$stockItem->save();
$response['message'] = 'Your Product Is Been Sucessfully Updated';
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
//Mage::getSingleton('core/session')->addSuccess(Mage::helper('marketplace')->__('Your Product Is Been Sucessfully Updated'));
}
there are JS errors in console, is there any chance because of following js code , quantity is not saving ? if so how to resolve these errors.