【问题标题】:magento save all Textfields by clicking one Update Button - Quantity not workingmagento 通过单击一个更新按钮保存所有文本字段 - 数量不起作用
【发布时间】:2016-01-08 11:38:08
【问题描述】:

我们正在使用以下代码通过单击一个按钮来编辑所有产品的 价格、数量 文本字段。价格运行良好。 数量无效

价格的 Phtml 代码

<input class="ama1" type = "text" id = "price_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "price[]" value = "<?php echo $products->getPrice(); ?>" style = ""/>

<input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?php echo $products->getId(); ?>" value="<?php echo $products->getPrice(); ?>" />

<p id="updatedprice_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>

<button id="price_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetPrice('<?php echo $products->getId(); ?>','<?php echo $products->getPrice(); ?>'); return false;">

<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>
</span>

数量的 Phtml 代码

<?php
$selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($products->getId());
//Zend_Debug::dump($selllermpassignproduct,null,true);
$stock_item=Mage::getModel('cataloginventory/stock_item')->loadByProduct($products->getId());

$SellerQty=isset($selllermpassignproduct['sellerqty'])?$selllermpassignproduct['sellerqty']:$stock_item->getQty();
$assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
?>


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


<p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>


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

一键更新所有产品价格和数量的代码

controller.php

 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');
        $qty = $this->getRequest()->getParam('qty');
        foreach ($ids as $key => $value) {
    $product = Mage::getModel('catalog/product')->load($value);
    $product->setPrice($price[$key]);   // price
    $product->setQty($qty[$key]);       //qty



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


    }}

【问题讨论】:

    标签: php magento


    【解决方案1】:
    <input class="ama1" type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" value = "<?php echo (int) $SellerQty; ?>" />
    

    您已调用名称qty 并且您的字段名称为stock 将其更改为

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

    【讨论】:

    • 还是同样的问题
    • 之后刷新缓存
    • 试试print_r($qty); 看看你有没有得到错误?
    • 是的,我得到数量,因为当我尝试通过其他按钮更新时,它的工作请检查prntscr.com/9ni87h“更新”工作“全部保存”不工作
    • 价格更新了吗?
    猜你喜欢
    • 2016-04-04
    • 2014-06-20
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    相关资源
    最近更新 更多