必须比较地址-其中一个是刚刚创建的(未保存)。也许它可以帮助某人:
基于@Alphawolf的答案:
public function isDifferentAddresses(Mage_Customer_Model_Address $adr1, Mage_Customer_Model_Address $adr2, array $excludeKeys = array())
{
if (!count($excludeKeys)) {
$excludeKeys = array(
'entity_id',
'entity_type_id',
'attribute_set_id',
'is_active',
'increment_id',
'parent_id',
'created_at',
'updated_at',
'customer_id',
'customer_address_id',
'quote_address_id',
'region_id',
'address_type',
'is_default_billing',
'is_default_shipping',
'save_in_address_book'
);
}
$excludeKeys = array_flip($excludeKeys);
$adr1Filtered = array_diff_key($adr1->getData(), $excludeKeys);
$adr2Filtered = array_diff_key($adr2->getData(), $excludeKeys);
$diff = array_diff_assoc($adr1Filtered, $adr2Filtered);
return !empty($diff);
}
编辑20 01 2016
自从我发布上面的版本以来,我使用以下方法,它对我有用-以为它可能对某人有帮助:
/**
* returns if address 1 is different to address 2
*
* @param Mage_Customer_Model_Address $adr1
* @param Mage_Customer_Model_Address $adr2
* @param array $excludeKeys
*
* @return bool
*/
public function isDifferentAddresses(Mage_Customer_Model_Address $adr1,
Mage_Customer_Model_Address $adr2, array $excludeKeys = array()
) {
if (!count($excludeKeys)) {
$excludeKeys = array(
'prefix',
'suffix',
//'region',
//'region_id',
'entity_id',
'vat_id',
'entity_type_id',
'attribute_set_id',
'is_active',
'increment_id',
'parent_id',
'created_at',
'updated_at',
'customer_id',
'customer_address_id',
'quote_address_id',
'address_type',
'is_default_billing',
'is_default_shipping',
'save_in_address_book'
);
}
$excludeKeys = array_flip($excludeKeys);
$adr1Filtered = array_diff_key($adr1->getData(), $excludeKeys);
$adr2Filtered = array_diff_key($adr2->getData(), $excludeKeys);
$diff = array_diff_assoc($adr1Filtered, $adr2Filtered);
return !empty($diff);
}
array_diff_assoc
因为array_diff仅比较值,因此,例如,如果您切换名字和姓氏,则地址仍将被视为相等