【问题标题】:Error in update value in database Magento数据库 Magento 中的更新值错误
【发布时间】:2016-03-11 11:15:55
【问题描述】:

我必须创建一个扩展,其中当购物车中允许的最小数量 > 库存时,其设置的购物车中允许的最小数量 = 数量。

事件在保存订单后生效。

我的代码如下:

public function updateminqtynew(Varien_Event_Observer $observer)
            {
            $quote = $observer->getEvent()->getOrder();
            $orderIncrementId = $quote->getIncrementId();
            $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
             $items = $order->getAllItems(); 
              $itemcount=count($items);

                foreach ($items as $itemId => $item)
                {
                                    $sku = $item->getSku();
                                    $_Pdetails = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
                                    $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_Pdetails->getId());
                                    $minqty = $stock->getMinSaleQty();
                                    $allqty = $stock->getQty();         
                                //  Mage::log("minqty".$_Pdetails->getId().round($minqty), null, 'logfileif.log');
                                    //Mage::log("allqty".round($allqty), null, 'logfileif.log');

                                if(intval($minqty)>intval($allqty))
                                    {
                                        Mage::log("if working", null, 'logfileif.log');

                                        $stock->setMinSaleQty($allqty);
                                        $stock->setQtyIncrements($stock->getQty());
                                        $stock->save();


                                            Mage::log("save", null, 'logfileif.log');
                                    }
                                    else
                                    {
                                            //Mage::log("NO", null, 'logfileif.log');
                                    }


                        }
            }

值在日志文件中打印,但在数据库中不更新。

【问题讨论】:

    标签: magento


    【解决方案1】:

    请试试这个,让我知道它对你有用。

     if(intval($minqty)>intval($allqty))
                                        {
                                            Mage::log("if working", null, 'logfileif.log');
    ///--- another pattern to save data if logically  all are correct as you mentioned. 
                                        $stock->setData('min_sale_qty',$allqty);
                                        $stock->setData('qty_increments',$stock->getQty());
                                        $stock->save();
    
    
                                            Mage::log("save", null, 'logfileif.log');
                                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 2018-06-15
      相关资源
      最近更新 更多