musste Adressen vergleichen - eine von ihnen wurde gerade erstellt (nicht gespeichert). Vielleicht hilft es jemandem:
basierend auf @Alphawolf Antwort:
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);
}
EDIT 20 01 2016
Ich benutze die folgende Methode, da ich die obige Version gepostet habe und sie für mich funktioniert - dachte, es könnte jemandem helfen:
/**
* 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
dass array_diff nur die Werte vergleicht. Wenn Sie also beispielsweise Vor- und Nachnamen wechseln, werden die Adressen weiterhin als gleich behandelt