通过SQL查询修正Magento中的截断邮政编码

时间:2014-06-02 19:18:13

标签: sql magento

从X-Cart迁移到Magento后,带有前导零的邮政编码被截断,没有零。我试图运行SQL查询以添加零但不知道在数据库中运行它的哪个表/列。我们使用邮政编码确定在结账时客户可以使用哪些送货服务。有谁知道发货地址(默认和附加)邮政编码在数据库中的位置?

2 个答案:

答案 0 :(得分:2)

magento中的zip / postal代码是customer_address实体的一个属性。

查看表mage_eav_attribute以查找属性id及其存储位置,例如执行此查询以找出magento存储属性的位置:

select attribute_id
, backend_type
, attribute_code
from mage_eav_attribute 
where attribute_code like '%post%' or attribute_code like '%zip%'

对于我的实施,attribute_id = 29attribute_code = 'postcode'backend_type =' varchar'。列backend_type将告诉您后端的属性类型。

varchar告诉我,magento将此属性存储在名为mage_customer_address_entity_varchar的表中。 对于您而言,这可能会有所不同,因为它似乎将其视为整数并截断前导零。

然后我可以执行以下sql来获取邮政编码。 当然,您必须将属性表mage_customer_address_entity_varchar修改为您的magento实施存储此属性的位置。

select e.entity_id, a.value atype.attribute_code
from mage_customer_address_entity e
join mage_customer_address_entity_varchar a ON a.entity_id = e.entity_id
join mage_eav_attribute atype ON atype.attribute_id = a.attribute_id
where atype.attribute_code = 'postcode'

最后,您需要这个用于送货地址(而不是帐单地址?)。默认送货地址是客户的属性,因此您必须修改上述方法以查找哪个客户属性表包含该信息。

我希望这有助于您找到解决方案

干杯

答案 1 :(得分:0)

你可以忽略这些领先0吗?因为对于系统的逻辑而言它并不重要,如果你必须打印它,只需获取字符串的长度,并在需要时将前导0添加为字符串。

如果这对您不起作用,您将不得不查看您正在使用的模块的源代码,以查看该模块使用的表格。

相关问题