1

we are using 1.9.0

we are trying to save the quantity in frontend, but its not working. we doubt it may be issue with jquery errors present in console.

we wrote phtml code first and script in bottom of the file.

how to fix the errors present in below image.

enter image description here enter image description here

Phtml code :

<?php
$helper=Mage::helper('mpassignproduct');
$isPartner= Mage::getModel('marketplace/userprofile')->isPartner(); 
if($isPartner==1){ ?>
    <script type="text/javascript">
    if (typeof jQuery == 'undefined'){
        document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
    }
    </script>
    <script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <div>   
        <div class="page-title">
            <h1><?php echo $helper->__('My Assign Product List') ?></h1>
        </div>
        <div class="wk_mp_design">
            <div class="block block-account">   
                <div class="block-title">   
                    <strong><span><h4><?php echo $helper->__('My Assign Product List'); ?></h4></span></strong>
                </div>
            </div>
            <div class="fieldset wk_mp_fieldset">
                <div class="grid">
                    <div class="hor-scroll">
                        <?php 
                            if(count($this->getCollection())==0): ?>        
                                <div class="fieldset wk_mp_fieldset">
                                    <div class="wk_emptymsg">
                                        <?php echo $helper->__('No Product Available') ?>
                                    </div>
                                </div>
                        <?php else: ?>
                            <form action="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" method="post">
                                <table cellspacing="0" class="border wk_mp_list_table">
                                    <thead>
                                        <tr id="wk_mp_tr_heading">
                                            <th><span><?php echo $helper->__('Product Name') ?></span></th>
                                            <th><span><?php echo $helper->__('Date') ?></span></th>
                                            <th><span><?php echo $helper->__('Product Status') ?></span></th>
                                            <th><span>&nbsp;</span></th>
                                        </tr>
                                    </thead>
                                    <tbody class="wk_mp_body">
                                        <tr>
                                            <td>
                                                <input type="text" class="input-text" name="s" placeholder='<?php echo $helper->__('Search by product name') ?>' value="<?php echo $this->getRequest()->getParam('s')?>"/>
                                            </td>
                                            <td>
                                                <span class="wk_mp_td_span">
                                                    <?php echo $helper->__('From: ') ?>
                                                    <input name="from_date" id="special_from_date" class="input-text" value="<?php echo $this->getRequest()->getParam('from_date')?>" />
                                                </span>                             
                                                <span class="wk_mp_td_span">
                                                    <?php echo $helper->__('To: ') ?>
                                                    <input name="to_date" id="special_to_date" class="input-text" value="<?php echo $this->getRequest()->getParam('to_date')?>" />
                                                </span>
                                            </td>
                                            <td>
                                                <select name="prostatus" class="input-text">
                                                    <option value=""><?php echo $helper->__('All') ?></option>
                                                    <option value="1" <?php if($this->getRequest()->getParam('prostatus') == 1) echo 'selected="selected"'?>>
                                                        <?php echo $helper->__('Approved') ?>
                                                    </option>
                                                    <option value="2" <?php if($this->getRequest()->getParam('prostatus') == 2) echo 'selected="selected"'?>>
                                                        <?php echo $helper->__('Unapproved') ?>
                                                    </option>
                                                </select>
                                            </td>
                                            <td>
                                                <button class="button" title="Save" type="submit">
                                                    <span><span><span><?php echo $helper->__('Submit') ?></span></span></span>
                                                </button>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </form>
                            <form name="formmassdelete" id="form-customer-product-delete" method="post" action="<?php echo $this->getUrl('mpassignproduct/index/massdeletepro') ?>">
                                <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
                                <button id="mass_delete_butn" style="float: left;padding: 5px 5px 5px 0;" type="submit" title="Delete Sellers" class="button">
                                    <span><span>Delete Products</span></span>
                                </button>
                                <table cellspacing="0" class="border wk_mp_list_table wk_mp_list_container_table">
                                    <thead>
                                        <tr class="wk_content">
                                            <th class="wk_check_first_td">
                                                <span><input type="checkbox" id="mpselecctall" value="all" name="mpselecctall"></span>
                                            </th>
                                            <th class="wk_first_td">
                                                <span class="label "><?php echo $helper->__('Product Name')?></span>
                                            </th>
                                            <th>
                                                <span class="label name"><?php echo $helper->__('Price')?></span>
                                            </th>

                                            <th>
                                                <span class="label name"><?php echo $helper->__('SKU')?></span>
                                            </th>

                                            <th>
                                                <span class="label name"><?php echo $helper->__('Delivery Time')?></span>
                                            </th>

                                            <th>
                                                <span class="label name"><?php echo $helper->__('Replacement Guarantee')?></span>
                                            </th>

                                            <th>
                                                <span class="label qty"><?php echo $helper->__('Status')?></span>
                                            </th>  


                                            <th>
                                                <span class="label qty"><?php echo $helper->__('Qty.')?></span>
                                            </th> 


                                            <th>
                                                <span class="label qty"><?php echo $helper->__('Condition')?></span>
                                            </th> 

                                            <th>
                                                <span class="label"><?php echo $helper->__('Action')?></span>
                                            </th>   

                                        </tr>
                                    </thead>

                                    <tbody>
                                        <?php foreach($this->getCollection() as $assinproducts):  ?>
                                            <?php $products=Mage::getModel('catalog/product')->load($assinproducts->getProductId()); ?>
                                            <tr class="wk_row_view ">
                                                <td class="wk_check_first_td">
                                                    <span>
                                                        <input type="checkbox" value="<?php echo $assinproducts->getMpassignproductId(); ?>" class="mpcheckbox" name="product_mass_delete[]">
                                                    </span>
                                                </td>
                                                <td class="wk_first_td">
                                                    <span class="label name" title="<?php echo $products->getName(); ?>">
                                                        <?php 
                                                            $productname=strlen($products->getName())>7?substr($products->getName(),0,7)."..":$products->getName();
                                                            echo $products->getName();
                                                        ?>
                                                    </span>
                                                </td>
                                                <td>
                                                    <span class="label price">
                                                        <?php echo Mage::helper('core')->currency($assinproducts->getPrice(), true, false);?>
                                                    </span> 
                                                </td>

                                                <td>
                                                    <span class="label sku">
                                                        <?php echo $assinproducts->getsku() ?>
                                                    </span> 
                                                </td>

                                                <td>
                                                    <span class="label replacement">
                                                        <?php echo $assinproducts->getdeliverytime() ?>
                                                    </span> 
                                                </td>

                                                <td>
                                                    <span class="label delivery">
                                                        <?php echo $assinproducts->getreplacement() ?>
                                                    </span> 
                                                </td>


                                                <td>
                                                    <span class="label pro_status">
                                                        <?php if($assinproducts['flag']==1): ?>
                                                            <?php echo Mage::helper('mpassignproduct')->__('Approved')?>
                                                        <?php else: ?>
                                                            <?php echo Mage::helper('mpassignproduct')->__('Un-Approved')?>
                                                        <?php endif; ?>
                                                    </span> 


    </td>


<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>







                                                <td>
                                                    <span class="label">
                                                        <?php 
                                                            if($assinproducts['product_condition']=='new')
                                                                echo Mage::helper('mpassignproduct')->__('New');
                                                            else
                                                                echo Mage::helper('mpassignproduct')->__('Used');
                                                        ?>
                                                    </span> 
                                                </td>
                                                <td>
                                                    <span class="label wk_action">
                                                        <img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $assinproducts->getMpassignproductId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>
                                                        <img data-type="<?php echo $assinproducts->getMpassignproductId(); ?>" src="<?php echo $this->getSkinUrl('marketplace/images/icon-trash.png'); ?>" alt="<?php echo $helper->__('Delete')?>" title="<?php echo $helper->__('Delete')?>" class="mp_delete"/>
                                                    </span> 
                                                </td>                       
                                            </tr>               
                                        <?php endforeach; ?>                            
                                    </tbody>

                                </table>
                            </form>
                        <?php endif; ?>
                    </div>
                </div>
                <?php echo $this->getPagerHtml(); ?>
            </div>
        </div>
        <div class="buttons-set">
            <p class="back-link">
                <a href="javascript:;" onclick="javascript: window.history.back();" class="left">&laquo; <?php echo Mage::helper('marketplace')->__('Back') ?></a>
            </p>
        </div>
    </div>
<?php }else{
    echo "<h2 class='wk_new_msg'>".$helper->__("To BECOME SELLER PLEASE CONTACT TO ADMIN.")."</h2>";
}?>

Script

<script>
    function validateNumbers(e)
    {
        if (jQuery.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
            // Allow: Ctrl+A, Command+A
            (e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) || 
            // Allow: home, end, left, right, down, up
            (e.keyCode >= 35 && e.keyCode <= 40)) {
                // let it happen, don't do anything
                return;
        }

        // Ensure that it is a number and stop the keypress
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    }

    var $wk_jq = jQuery.noConflict();

    (function($wk_jq){
            $wk_jq( "#special_from_date" ).datepicker({dateFormat: "yy-mm-dd"});
            $wk_jq( "#special_to_date" ).datepicker({dateFormat: "yy-mm-dd"});
            $wk_jq('#mpselecctall').click(function(event) {
            if(this.checked) {
                $wk_jq('.mpcheckbox').each(function() {
                    this.checked = true;      
                });
            }else{
                $wk_jq('.mpcheckbox').each(function() {
                    this.checked = false;           
                });         
            }
        });

        $wk_jq('body').delegate('.mp_edit','click',function(){
            var id=$wk_jq(this).attr("data-type");  
                    var dicision=confirm('<?php echo $helper->__(" Are you sure you want to edit this product ? ")?>');
                    if(dicision==true){         
                            var $type_id=$wk_jq(this).attr('data-type');                
                            window.location = "<?php echo $this->getUrl('mpassignproduct/index/edit/') ?>".concat("id/",id);    
                    }
        });

        $wk_jq('.mp_delete').click(function(){
                    var id=$wk_jq(this).attr("data-type");
                    var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete this product ? ")?>');
                    if(dicisionapp==true)
                            window.location = "<?php echo $this->getUrl('mpassignproduct/index/delete/') ?>".concat("id/",id);
            });

            $wk_jq('#mass_delete_butn').click(function(e){
                    var flag =0;
                    $wk_jq('.mpcheckbox').each(function(){
                            if (this.checked == true){
                                    flag =1;
                            }
                    });
                    if (flag == 0){
                            alert("<?php echo $helper->__(' No Checkbox is checked') ?>");
                            return false;
                    }
                    else{
                            var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete these product ? ")?>');
                            if(dicisionapp==true){
                                    $wk_jq('#form-customer-product-delete').submit();
                            }else{
                                    return false;
                            }
                    }
            });
    })($wk_jq);


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






</script>
  • put this line var $wk_jq = jQuery.noConflict(); first in <script> and use $wk_jq instead of jQuery – Minesh Patel Mar 18 '16 at 9:04
2

you error message clearly indicate that you jQuery variable is not defined. simply change this

var $wk_jq = jQuery.noConflict();

to

var $wk_jq = $.noConflict();

3

You are not loading jQuery properly, check your source code & see the order you load your scripts

https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

Your Answer

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