0

we are using following code to update quantity through vendor dashboard. but its not saving in database

Phtml

<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" class="ama1" value = "<?php echo (int) $SellerQty; ?>" />



<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;"  >
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>

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



                }
            });
        }

Controllers.php

public function updateFieldAction(){
        $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));
        //Mage::getSingleton('core/session')->setEditProductId($id);
        $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($id);
        $stockItem->setData('manage_stock', 1);
        $stockItem->setData('qty', $this->getRequest()->getParam('qty'));

        $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'));
      }

we are using following code for update all products by one update button

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

        $special= $this->getRequest()->getParam('quantity');

        $local= $this->getRequest()->getParam('local');
        $regional= $this->getRequest()->getParam('regional');
        $state= $this->getRequest()->getParam('state');
        $cod= $this->getRequest()->getParam('cod');

        foreach ($ids as $key => $value) {
    $product = Mage::getModel('catalog/product')->load($value);
    $product->setPrice($price[$key]);
    $product->setSpecialPrice($special[$key]);

    $product->setQty($qty);
    $product->setMpLocalShippingCharge($local[$key]);

    $product->setMpRegionalShippingCharge($regional[$key]);
    $product->setMpStateShippingCharge($state[$key]);
    $product->setCodAvailable($cod[$key]);

$product->save();
        }
        Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Products has been sucessfully deleted from your account'));
        $this->_redirect('marketplace/marketplaceaccount/myproductslist/');


    }}
3
  • Is this a frontend controller since you are using Mage::getSingleton('customer/session')? If so you will need to see the store id to admin for it to save. – Renon Stewart Feb 22 '16 at 16:51
  • Thanks a lot for your valuable hint. i will check it and let you know about this : - ) – Baby in Magento Feb 22 '16 at 16:53
  • Debug in controller qty and id. are you getting that parameter in controller or not? – Prashant Valanda Feb 22 '16 at 17:07
1

in phtml change <input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" class="ama1" value = "<?php echo (int) $SellerQty; ?>" />

to <input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock[]" class="ama1" value = "<?php echo (int) $SellerQty; ?>" /> in controller

$qty= $this->getRequest()->getParam('stock');

replace this $product->setQty($qty);

with

$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($value);
        $stockItem->setData('manage_stock', 1);
        $stockItem->setData('qty', $qty[$key]);

        $stockItem->save();
1
  • i checked it, but still not saving – Baby in Magento Feb 23 '16 at 7:17
0

Try to set the $stockItem->setData('in_stock', 1); also try to reindex stock from backend, maybe that is the issue

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.