Integrate second address table
-
12-12-2019 - |
Question
I'm making an extension, which lets me add Company. Each Company can have many addresses (same as customer->customer_address). The target is, to let a customer use the address of his company (relation is made by a customer attribute).
What I'd like to achieve: Every time magento accesses the customer_address table, I want my module to add it's addresses too, so the customer has its "own" addresses and his companys addresses.
What is the best way to achieve this without breaking modularity?
Any ideas and or tips are appreciated.
Solution
You should be able to accomplish this using an observer.
In config.xml
<eav_collection_abstract_load_after>
<observers>
<layout_before>
<class>module/observer</class>
<method>handleCustomerCollectionBefore</method>
</layout_before>
</observers>
</eav_collection_abstract_load_after>
In observer.php
Company_Module_Model_Observer{
public function handleCustomerCollectionBefore(){
$collection = $observer->getCollection();
if (strpos(get_class($collection),'Address_Collection')){
//load company address
$companyAddress = Mage::getModel('customer/address')->load(xyz);
if($customAddress->getId()){
$collection->addItem($companyAddress);
}
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange