-
13-12-2019 - |
题
我经营一家商店(Magento CE 1.6.2),有 4 个不同的商店视图,(由于历史原因)ID 为 1、3、4 和 7。订单号看起来像这样 10000001、30000001、40000001、70000001。
我已经使用 Magento CE 1.9.1 设置了全新安装,但现在商店 ID 是 1、2、3、4...
在旧的情况下我该如何改变呢?
我看到了这篇文章 --> http://www.thevortexcode.com/how-to-change-order-prefix-and-default-value-of-ordershipmentinvoice-numbercredit-memo-in-magento/ 解释如何设置/更改 eav_entity_store.increment_prefix
但这似乎在1.9中不起作用......
解决方案
只需编辑商店的ID即可 store_id
栏目中的 core_store
数据库表。由于外键的存在,几乎所有其他表都会更新。
此外,您应该更新:
default_store_id
列于core_store_group
桌子
正如所评论的,更改实际的数据库 ID 有点激进。此外,您仍然需要更新 eav_entity_store
桌子。
因此,您还可以简单地为您的增量 ID 设置每个商店的配置。您可以在 eav_entity_store
桌子:
- 对于商店 ID 1,设置
increment_prefix
至 1 - 对于商店 ID 2,设置
increment_prefix
至 3 - 对于商店 ID 3,设置
increment_prefix
至 4 - 对于商店 ID 4,设置
increment_prefix
至 7
其他提示
更好地使用模型包装器而不是原始的SQL语句。
示例:
$productEntityType = Mage::getModel('eav/entity_type')
->loadByCode(Mage_Catalog_Model_Product::ENTITY);
$entityStoreConfig = Mage::getModel('eav/entity_store')
->loadByEntityStore($productEntityType->getId(), 0);
$entityStoreConfig->setEntityTypeId($productEntityType->getId())
->setStoreId(0)
->setIncrementPrefix($prefix)
->setIncrementLastId($lastId)
->save();
.
请参阅:
我必须多次做出不同的原因,这就是我所做的:
此查询将仅显示Entity_type_code= Order
的增量IDSELECT * FROM eav_entity_store join eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
WHERE eav_entity_type.entity_type_code='order';
.
一旦找到您想要更新的行,您可以如下更改:
UPDATE eav_entity_store
INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
SET eav_entity_store.increment_prefix='X'
WHERE eav_entity_type.entity_type_code='order' and eav_entity_store.eav_entity_store_id = {row_id_here};
.
请注意,increntment_last_id的值已包含increntment_prefix,因此我通常从increment_last_id中删除旧的increntment_prefix,因此新的订单增量ID看起来很好。
如果您有引号,具有保留的increment_order_id,则可能仍然可以使用旧的increntment_id 查看订单。在更新后开始生成新报价后,所有应该是正常的。
通常在我的开发环境中,我刚刚将所有引号设置为 is_active= 0 在更新increment_id之后只需一个新的开始。
有关详细信息,请查看以下内容: http://www.warpconduit.net/2012/04/18/how-to-change-the-order-increment-id-and-prefix-in-magento/
我真的尝试避免将查询直接入到Magento DB中。如果可能,请创建一个具有安装或升级脚本的简单模块,该脚本将为您执行此操作。例如,您可以使用以下脚本更改递增ID和递增前缀:
<?php
$this->startSetup();
/*
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/*
* Retrieve the write connection
*/
$writeConnection = $resource->getConnection('core_write');
/*
* Retrieve our table name
*/
$table = $resource->getTableName('eav/entity_store');
$table2=$resource->getTableName('eav/entity_type');
$query = "UPDATE {$table}
INNER JOIN {$table2} ON {$table2}.entity_type_id ={$table}.entity_type_id
SET {$table}.increment_last_id='XXXXXXXXX'
WHERE {$table2}.entity_type_code='order' AND eav_entity_store.store_id = 'Y'";
/*
* Execute the query
*/
$writeConnection->query($query);
$this->endSetup();
.
其中xxxxxxxxx是您想要启动的增量ID,y是您要为此执行此操作的商店ID。
要更改实际前缀,请使用以下查询: $query = "UPDATE {$table}
INNER JOIN {$table2} ON {$table2}.entity_type_id ={$table}.entity_type_id
SET {$table}.increment_prefix='X'
WHERE {$table2}.entity_type_code='order' AND eav_entity_store.store_id = 'Y'";
.
其中x是您要使用的前缀,y是您要执行此操作的鞋类ID。