Problems when updating the quantity button

we have marketplace site, where each seller/vendor have their own account. they can see list of products. sku ,qty in their account

Initially its displaying like this : image 1 =http://prnt.sc/8wm25g

we are using following code to update the quantity in frontend : but we facing some problems.

a)We click on edit button and than update the quantity and quantity is saving in database. but its visible in frontend [seller account] only after refreshing the page. even edit button is visible only after refeshing the page

b)we click on “edit” button, than “cancel” button, than its displaying like this : image 2 = http://prnt.sc/8wm2fv . but after clicking cancel, it should display as like image 1

<?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>
  <input type = "text" id = "qty_<?php echo $products->getId(); ?>" name = "qty" value = "<?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>" 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>  

    <br/>
    <button id="update_button_<?php echo $products->getId(); ?>" class="button wk_mp_btn1" onclick="updateField('<?php echo $products->getId(); ?>'); return false;" >
        <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 type = "text/javascript" >

        var $wk_jq = jQuery.noConflict();

        function hideReset(product_id) {
            var editLink = "#edit_link_"+ product_id;
            var updateButton = "#update_button_"+ product_id;
            var resetButton = "#reset_button"+ product_id;

            $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).toggle()

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(resetButton).show();

            $qty = $wk_jq(qtyId).val();


        }
        function updateField(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;
        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();

            new Ajax.Request(url, {
                method: 'post',
                parameters: {id: product_id, qty: $qty},
        onComplete: function (transport) {


                alert(transport.responseText);
        $wk_jq(qtyId).setValue($qty);

            }
            });} <script>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s