javascript - magento 编辑数量而不重定向到另一个页面

标签 javascript php html css magento

我们有一个市场网站。每个卖家/vendor 都有自己的帐户。

我们在他们的帐户中显示卖家产品、数量、sku...等的列表。

http://prntscr.com/8vgul0

我们使用这段代码来显示这些信息:

<?php 
$isPartner= Mage::getModel('marketplace/userprofile')->isPartner(); 
$helper= Mage::helper('marketplace');
if($isPartner==1){
    ?>
    <script type="text/javascript">
    if (typeof jQuery == 'undefined'){
        document.write(unescape("%3Cscript src='//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 class="page-title">
        <h1 style="float:left;"><?php echo $helper->__('My Product List') ?></h1>
    </div>  
    <div class="wk_mp_design">
        <div class="block block-account">   
            <div class="block-title">   
                <strong><span><h4><?php echo $helper->__('Product List') ?></h4></span></strong>
            </div>
        </div>
        <div class="fieldset wk_mp_fieldset">
            <div class="grid">
                <div class="hor-scroll">
                    <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>
                    <?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 $this->getUrl('marketplace/marketplaceaccount/massdeletesellerpro') ?>" method="post" id="formmassdelete" name="formmassdelete">
                            <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
                            <button class="button" title="<?php echo $helper->__('Delete Products') ?>" type="submit" style="float: left;padding: 5px 5px 5px 0;"  id="mass_delete_butn">
                                <span><span><?php echo $helper->__('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" name="mpselecctall" value="all" id="mpselecctall"/>
                                            </span>
                                        </th>
                                        <th class="wk_first_td">
                                            <span class="label name">
                                                <?php echo $helper->__('Product')?>
                                            </span>
                                        </th>
                                        <th class="wk_first_td">
                                            <span class="label name">
                                                <?php echo $helper->__('sku')?>
                                            </span>
                                        </th>
                                        <th>
                                            <span class="label pro_status">
                                                <?php echo $helper->__('Status')?>
                                            </span>
                                        </th>

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

                                        <th>
                                            <span class="label">
                                                <?php echo $helper->__('Earn Amount')?>
                                            </span>
                                        </th>
                                        <th>
                                            <span class="label">
                                                <?php echo $helper->__('Action')?>
                                            </span>
                                        </th>                       
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                                    $i = 0;
                                    foreach($this->getCollection() as $products){
                                        $i++;
                                        $productMediaConfig = Mage::getModel('catalog/product_media_config');
                                        $salesdetail=Mage::getModel('marketplace/saleslist')->getSalesdetail($products->getEntityId());
                                        ?>
                                        <tr class="wk_row_view <?php echo $class = ($i == count($this->getCollection()))? 'wk_last_tr':''?>">
                                            <td class="wk_check_first_td">
                                                <span>
                                                    <input type="checkbox" name="product_mass_delete[]" class="mpcheckbox" value="<?php echo $products->getEntityId(); ?>"/>
                                                </span>
                                            </td>
                                            <td class="wk_first_td">
                                                <input type="hidden" class="hidden_id" value="<?php echo $products->getEntityId(); ?>" />
                                                <div class="label name" title="<?php echo $products->getName(); ?>">
                                                    <div class="wk_pro_divide1">
                                                        <img src="<?php echo Mage::helper('catalog/image')->init($products,'thumbnail');?>" class="image" />
                                                    </div>
                                                    <div class="wk_pro_divide2">
                                                        <div style="width:100%;">
                                                            <a href="<?php echo $this->getUrl($products->getUrlPath())?>" target="blank">
                                                                <?php echo $products->getName();?>
                                                            </a>
                                                        </div>
                                                        <div style="width:100%;float:left;">
                                                            <?php echo Mage::helper('core')->currency($products->getPrice(), true, false);?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </td>

                                            <td>
                                            <?php echo $sku = Mage::getModel('catalog/product')->load($products->getId())->getSku();?>
                                            </td>


                                            <?php 
                                            if($products->getStatus()==2) { ?>
                                                <td>        
                                                    <span class="label pro_status">
                                                        <?php echo $helper->__('Pending')?>
                                                    </span>
                                                </td>
                                                <td>
                                                    <span class="label qty">
                                                        <?php echo $helper->__('Pending')?>
                                                    </span>
                                                </td>
                                                <td>
                                                    <span class="label qty">
                                                        <?php echo $helper->__('Pending')?>
                                                    </span> 
                                                </td>
                                                <td>
                                                    <span class="label qty">
                                                        <?php echo $helper->__('Pending')?>
                                                    </span> 
                                                </td>
                                                <td>
                                                    <span class="label qty">
                                                        <?php echo $helper->__('Pending')?>
                                                    </span> 
                                                </td>                                   
                                            <?php }
                                            else{ 
                                                $id=$products->getId();
                                                $productsolddetail=Mage::getModel('marketplace/saleslist')->getProductSalesDetailById($id);
                                                $qtycom=0;
                                                $com=0;
                                                foreach($productsolddetail as $key){
                                                    $qtycom+=$key['magequantity'];
                                                    $com+=$key['actualparterprocost'];
                                                }   ?>

                                                <td>        
                                                    <span class="label pro_status">
                                                        <?php echo $helper->__('Approved')?>
                                                    </span>
                                                </td>

                                                <!--    edit qty -->
                                                <td>

                                                <?php echo (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>

                                                     <span class="label wk_action">
                                                    <img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $products->getTypeId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>

                                                     </span>    
                                                </td>

                                               <!-- edit qty end -->


                                                <!--
                                                <td>
                                                    <span class="label qty">
                                                        <?php echo $salesdetail['quantitysoldconfirmed']; ?>
                                                    </span>
                                                </td>
                                                <td>
                                                    <span class="label qty">
                                                        <?php echo $salesdetail['quantitysoldpending']; ?>
                                                    </span> 
                                                </td>
                                                <td>
                                                    <span class="label qty">
                                                        <a href="<?php echo $this->getUrl('mpshippingmanager/shipping/salesdetail/')."id/".$products->getId(); ?>"><?php echo $salesdetail['quantitysold']; ?></a>
                                                    </span> 
                                                </td>
                                                -->
                                                <td>
                                                    <span class="label price">
                                                        <?php echo Mage::helper('core')->currency($salesdetail['amountearned'], true, false); ?>
                                                    </span> 
                                                </td>
                                                <?php 
                                            }?>
                                            <td>
                                                <span class="label wk_action">
                                                    <img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $products->getTypeId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>
                                                    <img 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
                                    }?>
                                </tbody>
                            </table>
                        </form>
                        <?php
                    }?>
                </div>
            </div>
            <?php echo $this->getPagerHtml(); ?>        
        </div>  
        <div class="buttons-set">
            <p class="back-link">
                <a href="javascript:;" onclick="javascript: window.history.back();" class="left">&laquo; <?php echo $helper->__('Back') ?></a>
            </p>
        </div>
    </div>
    <script> 
    var $wk_jq=jQuery.noConflict();
    var newCustomerProductForm1 = new VarienForm('formmassdelete', true);
    (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('body').delegate('.mp_edit','click',function(){
            var id=$wk_jq(this).parents('.wk_row_view').find('.hidden_id').val();   
            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');                
                if($type_id=='simple')
                    window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/editapprovedsimple/') ?>".concat("id/",id); 
                if($type_id=='downloadable')
                    window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/editapproveddownloadable/') ?>".concat("id/",id);           
                if($type_id=='virtual')
                    window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/editapprovedvirtual/') ?>".concat("id/",id);        
                if($type_id=='configurable')
                    window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/editapprovedconfigurable/') ?>".concat("id/",id);
                if($type_id=='grouped')
                    window.location = "<?php echo $this->getUrl('mpgroupproduct/index/editapprovedgrouped/') ?>".concat("id/",id);
                    <?php
                    //echo $this->getChildHtml('mpgrouped_productslist');
                    // echo $this->getChildHtml('mpbundle_productslist');
                    ?>
                if($type_id=='bundle')
                    window.location = "<?php echo $this->getUrl('mpbundleproduct/index/editbundle/') ?>".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-new').submit();
                }else{
                    return false;
                }
            }
        });

        $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('.mp_delete').click(function(){
            var id=$wk_jq(this).parents('.wk_row_view').find('.hidden_id').val();
            var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete this product ? ")?>');
            if(dicisionapp==true)
                window.location = "<?php echo $this->getUrl('marketplace/marketplaceaccount/delete/') ?>".concat("id/",id);
        });
    })($wk_jq);
    </script>
    <?php 
}else{
    echo "<h2 class='wk_new_msg'>".$helper->__("To BECOME SELLER PLEASE CONTACT TO ADMIN.")."</h2>";
}?>

我们在“数量”旁边有一个编辑按钮,如果我们点击那个编辑按钮,它会重定向到另一个页面,然后卖家编辑信息并保存。

我们正在使用以下代码进行编辑:

<span class="label wk_action">
<img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $products->getTypeId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>

</span> 

我们需要的是,如果我们点击“编辑”按钮,那么它应该像image 中一样显示文本字段。以及下方的更新和取消按钮。

最佳答案

管理网格请引用以下网址:

http://www.atwix.com/magento/inline-editing-in-magento-backend-grids/

我不确定,但这可能对你有帮助。尝试以下前端:

第 1 步:在编辑图像上创建 onclick 事件并调用 javascript 函数

eg :  onclick="updateField(this, '. $product_id .'); return false";

第 2 步: 创建您在图像的 onclick 中定义的 javascript 函数。

<?php $url='Mage::getUrl('module_name/index/updateField/');' ?>
<script type="text/javascript">

function updateField(image, product_id)
{
    new Ajax.Request('<?php echo $url ?>', {
        method: 'post',
        parameters: { id: fieldId, field: $(button).previous('input').getValue() }
    });
}
</script>

步骤:3 在您的 Controller 中创建您在 java 脚本 ajax url 中定义的函数。

public function updateFieldAction()
{
    $fieldId = (int) $this->getRequest()->getParam('id');
    $field = $this->getRequest()->getParam('field');
    if ($fieldId) {
        $model = Mage::getModel('modulename/model')->load($fieldId);
        $model->setField($field);
        $model->save();
    }
}

关于javascript - magento 编辑数量而不重定向到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33344358/

相关文章:

html - 基于子元素的CSS样式

javascript - Fancybox 无法工作,并且控制台中没有错误

javascript - 如何在 Typescript ES6 类中扩展 Backbone.Events?

javascript - 我正在尝试学习 Angular - 为什么我的对象没有使用 ng-repeat 出现?

javascript - 如何在 JavaScript 数组上使用模和按位 XOR 运算符反转算法?

php - 使用 PHPTAL 进行斑马条纹?

javascript - Angular2 loadChildren 在 webpacked 之后,产生 __webpack_require__ is not a function

php - 如何使用jquery删除wordpress菜单中的空链接?

php - UniqueEntity 不起作用 - DefaultQuoteStrategy.php 第 97 行中的 FatalThrowableError

javascript - Leaflet -> 删除 CircleLayer 不起作用