【问题标题】:How to get the next order id of orders in Magento如何在 Magento 中获取订单的下一个订单 ID
【发布时间】:2014-08-06 02:39:17
【问题描述】:

我一直在使用下面的代码来获取 Magento 中的下一个订单 ID

     $getNewOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);

这工作正常,但此代码的问题在于它将表 eav_entity_store 中的 increment_last_id 字段更改为这个新的订单 ID。

因此,如果您的订单未处理,则订单 ID 已经增加,因此订单 ID 会丢失,因为下次创建订单之前,Magento 将在表中增加此值并处理订单。

如何在不增加表中的值的情况下获取下一个订单id,显然在后面的代码中创建订单时会改变这个表中的值。

我正在使用这段代码以编程方式创建订单

【问题讨论】:

  • Tx 我做了,但在我的情况下它不起作用。我正在使用自定义代码以编程方式输入一些订单,链接中的解决方案适用于结帐页面订单。

标签: php magento magento-1.7


【解决方案1】:

试试这个:

$entityStoreConfig = Mage::getModel('eav/entity_store')->loadByEntityStore($this->getId(), $storeId);

$incrementInstance = Mage::getModel($this->getIncrementModel())
            ->setPrefix($entityStoreConfig->getIncrementPrefix())
            ->setPadLength($this->getIncrementPadLength())
            ->setPadChar($this->getIncrementPadChar())
            ->setLastId($entityStoreConfig->getIncrementLastId())
            ->setEntityTypeId($entityStoreConfig->getEntityTypeId())
            ->setStoreId($entityStoreConfig->getStoreId());

$nextId = $incrementInstance->getNextId();

代码取自fetchNewIncrementId 方法。我只是省略了保存部分。

【讨论】:

  • 感谢您的提示将深入挖掘。
  • @Pradino。您无需深入挖掘。这就是您需要的确切代码。将其包装在帮助器或模型中的方法中并使用它。
  • 是的,就是这样做的。我不得不添加一些东西,一切都完成了。 Mage::getModel('eav/entity_type')->loadByCode('order'); 获取一些值。
猜你喜欢
  • 1970-01-01
  • 2011-01-12
  • 1970-01-01
  • 2017-10-27
  • 1970-01-01
  • 2012-01-08
  • 2014-07-30
  • 2014-03-12
  • 2017-08-26
相关资源
最近更新 更多