Module A -> Orders - runs a logic_hooks
Module B -> Shipments
Module C -> Goods
I’m currently developing a logic_hooks in Module A that at the end should add relationship between B and C.
Description:
1 -> Module A before_save creates a record in module C
2 -> then, with some C references it creates a record in Module B
3 -> then it should creates some relationship between record C and B
All is working well except for relationship.
Doing for example
$accountBean->contacts->add($contactBean);
it relate only the current bean which is running logic_hooks.
This is my code…note that it’s quite long…so i’ve removed many parts just to let you understand the logic behind:
Logic Hooks executed saving MODULE A
class UpdateData {
function DoUpdateData(&$bean, $event, $arguments) {
// Execute the first query from erp to identify goods based on Service Type
$goods_type = $erp->query("SELECT distinct count(B.shipment_code)…bla bla bla
foreach($goods_type as $data){
$GLOBALS['log']->FATAL('Count Goods Type: '.$data['Count'].' - '.$data['Service']);
switch($data['Service']) {
case('AE'):
$GLOBALS['log']->FATAL('DO Query Air shipments');
....
} // EOF foreach($goods_erp as $key=>$goods_data)
break;
case('MA'):
$GLOBALS['log']->FATAL('DO Query Sea shipments');
.....
} // EOF foreach($goods_erp as $key=>$goods_data)
break;
case('ST'):
$GLOBALS['log']->FATAL('DO Query Road shipments');
....
foreach($goods_erp as $key=>$goods_data){
retrievedDataGoods....
if($retrievedDataGoods){
$GLOBALS['log']->FATAL('The Retrieved Goods is present....now we need to compare!!!');
comparing goods records....
if($compareDataGoods == 1){
$GLOBALS['log']->FATAL('Calling update funcion!!!');
}
} // EOF if($retrievedDataGoods)
else {
$GLOBALS['log']->FATAL('Record not Present....must be added!!!');
$GLOBALS['log']->FATAL('Goods PAC NUM:' . $goods_data['CKAQQT']);
MODULE C
$newGoods = new DBGIT_GoodsDetails();
$newGoods->name=$bean->name."-".$goods_data['CKGRNB']."-".$goods_data['shipment_code'];
$newGoods->goods_pacnum=$goods_data['CKAQQT'];
$newGoods->goods_weight=$goods_data['CKBBNB'];
$newGoods->goods_desc=$goods_data['RNXHTX'];
$newGoods->goods_volume=$goods_data['CKARQT'];
$newGoods->save(false);
}
retrievedDataShipments......
if($retrievedDataShipments){
$GLOBALS['log']->FATAL('The Retrieved Shipments is present.......now we need to compare!!!');
comparing shipments record....
if($compareDataShipments == 1){
$GLOBALS['log']->FATAL('Calling update funcion!!!');
}
}
else {
$GLOBALS['log']->FATAL('The Retrieved Shipments is not present....it must be added!!!');
MODULE B
$newShipments = new DBGIT_ManageShipments();
$newShipments->name=$goods_data['shipment_code'];
$newShipments->shipment_oaccountname=$goods_data['B1CJRA'];
$newShipments->billing_address_street=$goods_data['B1ALIN'];
$newShipments->billing_address_city=$goods_data['B1AQLO'];
$newShipments->billing_address_postalcode=$goods_data['B1AICA'];
$newShipments->billing_address_state=$goods_data['B1LXCD'];
$newShipments->billing_address_country=$goods_data['B1AMPR'];
$newShipments->save(false);
NOW I NEED TO RELATE THIS RECORD IN MODULE B WITH TEH PREVIOUS WITH MODULE B
}
} // EOF foreach($goods_erp as $key=>$goods_data)
break;
} // EOF Switch($data['Service'])
} // EOF foreach
} // EOF DoUpdateData Function
} // EOF UpdateData Class
IMPORTANT…
I’ve forgotten to mention that:
-> Module B & C are read only so no logic hooks will be possible.
-> what i need to understand is a way to do something like “relate this ID(Goods) with this one(Shipment) during on save in Order Module.”
$id = $newShipments->save(false);
$newGoods->load_relationship(relationship between BC, look in studio for good name)
$newGoods->relationName->add($id);
Please verify code… and must find the correct name of relationship