Magento 提交订单时不增加 id

发布于 2024-11-24 22:43:58 字数 5802 浏览 0 评论 0原文

我最近一直在做一个扩展。然而,我刚刚遇到了一个障碍,我想知道是否应该重新安装 Magento。我遇到的问题是昨天发生的。我相信我已经追根溯源,但我不知道如何解决它。当我尝试提交订单时,在下完第一个订单后,出现以下错误:

There was an error processing your order. Please contact us or try 
again later.exception 'PDOException' with message 'SQLSTATE[23000]: 
Integrity constraint violation: 1062 Duplicate entry '' for key 
'UNQ_INCREMENT_ID'' in 
/Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Statement/Pdo.php:228

Stack trace:
#0 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#2 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `sa...', Array)
#4 /Users/jmax/Documents/websites/max_magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(337): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `sa...', Array)
#5 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Adapter/Abstract.php(574): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `sa...', Array)
#6 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(414): Zend_Db_Adapter_Abstract->insert('sales_flat_orde...', Array)
#7 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Sales/Model/Mysql4/Order/Abstract.php(417): Mage_Core_Model_Mysql4_Abstract->save(Object(Mage_Sales_Model_Order))
#8 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Model/Abstract.php(318): Mage_Sales_Model_Mysql4_Order_Abstract->save(Object(Mage_Sales_Model_Order))
#9 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Model/Resource/Transaction.php(150): Mage_Core_Model_Abstract->save()
#10 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Sales/Model/Service/Quote.php(183): Mage_Core_Model_Resource_Transaction->save()
#11 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Sales/Model/Service/Quote.php(238): Mage_Sales_Model_Service_Quote->submitOrder()
#12 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Checkout/Model/Type/Onepage.php(745): Mage_Sales_Model_Service_Quote->submitAll()
#13 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Checkout/controllers/OnepageController.php(499): Mage_Checkout_Model_Type_Onepage->saveOrder()
#14 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Controller/Varien/Action.php(420): Mage_Checkout_OnepageController->saveOrderAction()
#15 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(253): Mage_Core_Controller_Varien_Action->dispatch('saveOrder')
#16 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#17 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Model/App.php(340): Mage_Core_Controller_Varien_Front->dispatch()
#18 /Users/jmax/Documents/websites/max_magento/app/Mage.php(627): Mage_Core_Model_App->run(Array)
#19 /Users/jmax/Documents/websites/max_magento/index.php(80): Mage::run('', 'store')
#20 {main}

我尝试的第一件事:我完全禁用了我的扩展程序。所以,这不是我的扩展,但也许它导致数据库发生了一些变化。我一直在使用正确的编码方法开发我的扩展(不修改核心文件,并尽可能地扩展而不是覆盖)。

订单的增量 ID 似乎未设置!我回到 Mage_Eav_Model_Entity_Type -> fetchNewIncrementId(第141行),发现没有增量模型后,在第145行返回了void

144: if (!$this->getIncrementModel()) {
145:    return false;
146: }

并且,这是导致问题的SQL查询(显然不是增量id):

INSERT INTO `sales_flat_order` (`coupon_code`, `protect_code`, `shipping_description`, 
`is_virtual`, `store_id`, `customer_id`, `base_discount_amount`, `base_grand_total`, 
`base_shipping_amount`, `base_shipping_tax_amount`, `base_subtotal`, `base_tax_amount`,
`base_to_global_rate`, `base_to_order_rate`, `discount_amount`, `grand_total`, 
`shipping_amount`, `shipping_tax_amount`, `store_to_base_rate`, `store_to_order_rate`, 
`subtotal`, `tax_amount`, `total_qty_ordered`, `customer_is_guest`, `customer_note_notify`, 
`customer_group_id`, `gift_message_id`, `quote_id`, `base_shipping_discount_amount`, 
`base_subtotal_incl_tax`, `shipping_discount_amount`, `subtotal_incl_tax`, `weight`, 
`customer_dob`, `increment_id`, `applied_rule_ids`, `base_currency_code`, `customer_email`, 
`customer_firstname`, `customer_lastname`, `customer_middlename`, `customer_prefix`, 
`customer_suffix`, `customer_taxvat`, `discount_description`, `global_currency_code`, 
`order_currency_code`, `remote_ip`, `shipping_method`, `store_currency_code`, `store_name`, 
`x_forwarded_for`, `customer_note`, `created_at`, `updated_at`, `total_item_count`, 
`customer_gender`, `hidden_tax_amount`, `base_hidden_tax_amount`, `shipping_hidden_tax_amount`, 
`base_shipping_hidden_tax_amount`, `shipping_incl_tax`, `base_shipping_incl_tax`) VALUES (NULL, 
'aa53a6', 'Flat Rate - Fixed', '0', '1', '4', '0', '55', '5', '0', '50', '0', '1', '1', '0', 
'55', '5', '0', '1', '1', '50', '0', '1', '0', '1', '1', NULL, '38', '0', '50', '0', '50', 
'1', NULL, '', '', 'USD', '[email protected]', 'J', 'Max', NULL, NULL, NULL, NULL, '', 'USD', 
'USD', '127.0.0.1', 'flatrate_flatrate', 'USD', 
'Main Website\nMain Website Store\nDefault Store View', NULL, NULL, '2011-07-19 15:23:28', 
'2011-07-19 15:23:28', '1', NULL, '0', '0', '0', '0', '5', '5')

我可以提供任何其他信息来帮助找到解决方案吗?太感谢了!

最大J

I've been working on an extension recently. However, I just ran into a snag, and I am wondering if I should reinstall Magento. The problem that I am running into happened yesterday. I believe that I have traced it to the root, but I don't know how to fix it. When I attempt to submit an order, after the first one has been placed, I get the following error:

There was an error processing your order. Please contact us or try 
again later.exception 'PDOException' with message 'SQLSTATE[23000]: 
Integrity constraint violation: 1062 Duplicate entry '' for key 
'UNQ_INCREMENT_ID'' in 
/Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Statement/Pdo.php:228

Stack trace:
#0 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#2 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `sa...', Array)
#4 /Users/jmax/Documents/websites/max_magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(337): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `sa...', Array)
#5 /Users/jmax/Documents/websites/max_magento/lib/Zend/Db/Adapter/Abstract.php(574): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `sa...', Array)
#6 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(414): Zend_Db_Adapter_Abstract->insert('sales_flat_orde...', Array)
#7 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Sales/Model/Mysql4/Order/Abstract.php(417): Mage_Core_Model_Mysql4_Abstract->save(Object(Mage_Sales_Model_Order))
#8 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Model/Abstract.php(318): Mage_Sales_Model_Mysql4_Order_Abstract->save(Object(Mage_Sales_Model_Order))
#9 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Model/Resource/Transaction.php(150): Mage_Core_Model_Abstract->save()
#10 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Sales/Model/Service/Quote.php(183): Mage_Core_Model_Resource_Transaction->save()
#11 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Sales/Model/Service/Quote.php(238): Mage_Sales_Model_Service_Quote->submitOrder()
#12 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Checkout/Model/Type/Onepage.php(745): Mage_Sales_Model_Service_Quote->submitAll()
#13 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Checkout/controllers/OnepageController.php(499): Mage_Checkout_Model_Type_Onepage->saveOrder()
#14 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Controller/Varien/Action.php(420): Mage_Checkout_OnepageController->saveOrderAction()
#15 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(253): Mage_Core_Controller_Varien_Action->dispatch('saveOrder')
#16 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#17 /Users/jmax/Documents/websites/max_magento/app/code/core/Mage/Core/Model/App.php(340): Mage_Core_Controller_Varien_Front->dispatch()
#18 /Users/jmax/Documents/websites/max_magento/app/Mage.php(627): Mage_Core_Model_App->run(Array)
#19 /Users/jmax/Documents/websites/max_magento/index.php(80): Mage::run('', 'store')
#20 {main}

First thing I tried: I completely disabled my extension. So, it is not my extension, but maybe it caused some change in the database that caused that. I have been developing my extension using the proper coding methods (not modifying core files, and extending as opposed to overriding as much as possible).

It appears as if the order's increment id is not being set! I went back to Mage_Eav_Model_Entity_Type -> fetchNewIncrementId (line 141), and found that it returns void on line 145 after finding there is not increment model:

144: if (!$this->getIncrementModel()) {
145:    return false;
146: }

And, here is the SQL query that causes the problem (obviously it is not increment id):

INSERT INTO `sales_flat_order` (`coupon_code`, `protect_code`, `shipping_description`, 
`is_virtual`, `store_id`, `customer_id`, `base_discount_amount`, `base_grand_total`, 
`base_shipping_amount`, `base_shipping_tax_amount`, `base_subtotal`, `base_tax_amount`,
`base_to_global_rate`, `base_to_order_rate`, `discount_amount`, `grand_total`, 
`shipping_amount`, `shipping_tax_amount`, `store_to_base_rate`, `store_to_order_rate`, 
`subtotal`, `tax_amount`, `total_qty_ordered`, `customer_is_guest`, `customer_note_notify`, 
`customer_group_id`, `gift_message_id`, `quote_id`, `base_shipping_discount_amount`, 
`base_subtotal_incl_tax`, `shipping_discount_amount`, `subtotal_incl_tax`, `weight`, 
`customer_dob`, `increment_id`, `applied_rule_ids`, `base_currency_code`, `customer_email`, 
`customer_firstname`, `customer_lastname`, `customer_middlename`, `customer_prefix`, 
`customer_suffix`, `customer_taxvat`, `discount_description`, `global_currency_code`, 
`order_currency_code`, `remote_ip`, `shipping_method`, `store_currency_code`, `store_name`, 
`x_forwarded_for`, `customer_note`, `created_at`, `updated_at`, `total_item_count`, 
`customer_gender`, `hidden_tax_amount`, `base_hidden_tax_amount`, `shipping_hidden_tax_amount`, 
`base_shipping_hidden_tax_amount`, `shipping_incl_tax`, `base_shipping_incl_tax`) VALUES (NULL, 
'aa53a6', 'Flat Rate - Fixed', '0', '1', '4', '0', '55', '5', '0', '50', '0', '1', '1', '0', 
'55', '5', '0', '1', '1', '50', '0', '1', '0', '1', '1', NULL, '38', '0', '50', '0', '50', 
'1', NULL, '', '', 'USD', '[email protected]', 'J', 'Max', NULL, NULL, NULL, NULL, '', 'USD', 
'USD', '127.0.0.1', 'flatrate_flatrate', 'USD', 
'Main Website\nMain Website Store\nDefault Store View', NULL, NULL, '2011-07-19 15:23:28', 
'2011-07-19 15:23:28', '1', NULL, '0', '0', '0', '0', '5', '5')

Is there any other information that I can provide to help come to a solution? Thank you SO much!

JMax

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毅然前行 2024-12-01 22:43:58

您是否向销售/订单模型添加了任何属性?其中,如果在添加属性 sales/order 时不指定增量模型,则会丢失其增量模型。即使您再次关闭分机,该信息也会保留。

$installer->installEntities(
    'order'    => array(
        'entity_model'        => 'order',
        'table'               => 'sales/order',
        'increment_model'     => 'eav/entity_increment_numeric', //<-- This is important and might have caused the trouble!!!
        'increment_per_store' => true,
        'backend_prefix'      => 'sales_entity/order_attribute_backend',
        'attributes'          => array(
            'my_new_attribute' => array(
            'label'            => 'Omx Gift Certificates',
            'type'             => 'text',
            'global'           => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'visible'          => true,
            'required'         => false,
            'user_defined'     => true,
        ),
    )
);

如果这是来源,您可以执行以下操作:
从 sales_flat_order 表中删除添加的列(在本例中为:my_new_attribute),然后重新运行扩展的安装程序(当然使用指定的increment_model...)。

j。

Did you add any attributes to the sales/order model? In that, if you do not specifiy the increment model when adding the attribute sales/order will lose it's increment model. This will stay even if you switch off your extension again.

$installer->installEntities(
    'order'    => array(
        'entity_model'        => 'order',
        'table'               => 'sales/order',
        'increment_model'     => 'eav/entity_increment_numeric', //<-- This is important and might have caused the trouble!!!
        'increment_per_store' => true,
        'backend_prefix'      => 'sales_entity/order_attribute_backend',
        'attributes'          => array(
            'my_new_attribute' => array(
            'label'            => 'Omx Gift Certificates',
            'type'             => 'text',
            'global'           => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
            'visible'          => true,
            'required'         => false,
            'user_defined'     => true,
        ),
    )
);

If that is the source you can do the following:
Erase the added columns (in this case: my_new_attribute) from the sales_flat_order table and rerun the installer of your extension (with specified increment_model of course...).

j.

梦冥 2024-12-01 22:43:58

我不确定这应该是一个答案,但我需要一些空间,这篇文章甚至可能会有帮助,所以我将其发布为答案;

由于 $this->getIncrementModel() 失败,我认为您应该检查您的数据库是否正常。
我对我安装的 magento 之一进行了一些查询,结果如下:

mysql> select * from eav_entity_store;
+-----------------+----------------+----------+------------------+-------------------+
| entity_store_id | entity_type_id | store_id | increment_prefix | increment_last_id |
+-----------------+----------------+----------+------------------+-------------------+
|               1 |              1 |        0 | 0                | 000008430         |
|               2 |             11 |        1 | 1                | 100017253         |
|               3 |             16 |        1 | 1                | 100015639         |
|               4 |             19 |        1 | 1                | 100003448         |
|               5 |             23 |        1 | 1                | 100000676         |
|               6 |             11 |        3 | 3                | 300000088         |
|               7 |             19 |        3 | 3                | 300000019         |
|               8 |             16 |        3 | 3                | 300000072         |
|               9 |             11 |        4 | 4                | 400000004         |
|              10 |             11 |        5 | 5                | 500000102         |
|              11 |             16 |        5 | 5                | 500000049         |
|              12 |             11 |        7 | 7                | 700000001         |
|              13 |             16 |        7 | 7                | 700000001         |
|              14 |             23 |        3 | 3                | 300000003         |
|              15 |             19 |        5 | 5                | 500000006         |
+-----------------+----------------+----------+------------------+-------------------+
15 rows in set (0.00 sec)

mysql> select entity_type_id, entity_type_code, entity_model from eav_entity_type;
+----------------+----------------------+--------------------------------+
| entity_type_id | entity_type_code     | entity_model                   |
+----------------+----------------------+--------------------------------+
|              1 | customer             | customer/customer              |
|              2 | customer_address     | customer/address               |
|              3 | catalog_category     | catalog/category               |
|              4 | catalog_product      | catalog/product                |
|              5 | quote                | sales/quote                    |
|              6 | quote_item           | sales/quote_item               |
|              7 | quote_address        | sales/quote_address            |
|              8 | quote_address_item   | sales/quote_address_item       |
|              9 | quote_address_rate   | sales/quote_address_rate       |
|             10 | quote_payment        | sales/quote_payment            |
|             11 | order                | sales/order                    |
|             12 | order_address        | sales/order_address            |
|             13 | order_item           | sales/order_item               |
|             14 | order_payment        | sales/order_payment            |
|             15 | order_status_history | sales/order_status_history     |
|             16 | invoice              | sales/order_invoice            |
|             17 | invoice_item         | sales/order_invoice_item       |
|             18 | invoice_comment      | sales/order_invoice_comment    |
|             19 | shipment             | sales/order_shipment           |
|             20 | shipment_item        | sales/order_shipment_item      |
|             21 | shipment_comment     | sales/order_shipment_comment   |
|             22 | shipment_track       | sales/order_shipment_track     |
|             23 | creditmemo           | sales/order_creditmemo         |
|             24 | creditmemo_item      | sales/order_creditmemo_item    |
|             25 | creditmemo_comment   | sales/order_creditmemo_comment |
+----------------+----------------------+--------------------------------+
25 rows in set (0.00 sec)

请对您的数据库进行相同的选择,让我们比较结果。无论如何我都会重新安装magento,但首先你应该找到并修复导致数据损坏的错误(如果有的话)。

I'm not sure this should be an answer but I need some space and this post may even be helpfull so I'm posting it as an answer;

Since the $this->getIncrementModel() fails I think you should check that your database is OK.
I did some queries on one of my installed magentos and here are the results:

mysql> select * from eav_entity_store;
+-----------------+----------------+----------+------------------+-------------------+
| entity_store_id | entity_type_id | store_id | increment_prefix | increment_last_id |
+-----------------+----------------+----------+------------------+-------------------+
|               1 |              1 |        0 | 0                | 000008430         |
|               2 |             11 |        1 | 1                | 100017253         |
|               3 |             16 |        1 | 1                | 100015639         |
|               4 |             19 |        1 | 1                | 100003448         |
|               5 |             23 |        1 | 1                | 100000676         |
|               6 |             11 |        3 | 3                | 300000088         |
|               7 |             19 |        3 | 3                | 300000019         |
|               8 |             16 |        3 | 3                | 300000072         |
|               9 |             11 |        4 | 4                | 400000004         |
|              10 |             11 |        5 | 5                | 500000102         |
|              11 |             16 |        5 | 5                | 500000049         |
|              12 |             11 |        7 | 7                | 700000001         |
|              13 |             16 |        7 | 7                | 700000001         |
|              14 |             23 |        3 | 3                | 300000003         |
|              15 |             19 |        5 | 5                | 500000006         |
+-----------------+----------------+----------+------------------+-------------------+
15 rows in set (0.00 sec)

mysql> select entity_type_id, entity_type_code, entity_model from eav_entity_type;
+----------------+----------------------+--------------------------------+
| entity_type_id | entity_type_code     | entity_model                   |
+----------------+----------------------+--------------------------------+
|              1 | customer             | customer/customer              |
|              2 | customer_address     | customer/address               |
|              3 | catalog_category     | catalog/category               |
|              4 | catalog_product      | catalog/product                |
|              5 | quote                | sales/quote                    |
|              6 | quote_item           | sales/quote_item               |
|              7 | quote_address        | sales/quote_address            |
|              8 | quote_address_item   | sales/quote_address_item       |
|              9 | quote_address_rate   | sales/quote_address_rate       |
|             10 | quote_payment        | sales/quote_payment            |
|             11 | order                | sales/order                    |
|             12 | order_address        | sales/order_address            |
|             13 | order_item           | sales/order_item               |
|             14 | order_payment        | sales/order_payment            |
|             15 | order_status_history | sales/order_status_history     |
|             16 | invoice              | sales/order_invoice            |
|             17 | invoice_item         | sales/order_invoice_item       |
|             18 | invoice_comment      | sales/order_invoice_comment    |
|             19 | shipment             | sales/order_shipment           |
|             20 | shipment_item        | sales/order_shipment_item      |
|             21 | shipment_comment     | sales/order_shipment_comment   |
|             22 | shipment_track       | sales/order_shipment_track     |
|             23 | creditmemo           | sales/order_creditmemo         |
|             24 | creditmemo_item      | sales/order_creditmemo_item    |
|             25 | creditmemo_comment   | sales/order_creditmemo_comment |
+----------------+----------------------+--------------------------------+
25 rows in set (0.00 sec)

Please do the same selects on your databases and let's compare the results. I'd reinstall the magento anyway, but first you should find and fix the bug that caused the data corruption (if there is any).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文