Hi,
I’m trying to customize Edit view of Quotes to auto fill billing address with the contact’s primary address when selecting a contact from popup or quick search (instead od Account’s billing address).
I have copyed controller.php in \custom\modules\AOS_Quotes\controller.php with these changes:
require_once('modules/AOS_Quotes/controller.php');
class CustomAOS_QuotesController extends AOS_QuotesController {
...
if (isset($_REQUEST['contact_id'])) {
$query = "SELECT * FROM contacts WHERE id = '{$_REQUEST['contact_id']}'";
$result = $this->bean->db->query($query, true);
$row = $this->bean->db->fetchByAssoc($result);
$this->bean->billing_contact_id = $row['id'];
$this->bean->billing_contact = $row['first_name'].' '.$row['last_name'];
$this->bean->billing_address_street = $row['primary_address_street'];
$this->bean->billing_address_city = $row['primary_address_city'];
$this->bean->billing_address_state = $row['primary_address_state'];
$this->bean->billing_address_postalcode = $row['primary_address_postalcode'];
$this->bean->billing_address_country = $row['primary_address_country'];
}
It keeps on behaving like the new controller does not exist. Am I missing something in the process?
Thanks in advance for your help
I’m not sure of this solution, but while writing custom controllers you need to extend the sugar controller instead of the module controller. Please try with
class AOS_QuotesController extends SugarController {
and check if it works. Do a Quick Repair and Rebuild.
Yes you may be correct that creating a custom controller might not be the answer.
I don’t think there is any logic look which executes on a relate field or else that could have solved your querry.
Another option is using javascript, you can fetch the id of the value in the contact’s relate field and then fetch its address using AJAX and prefill the address field. A bit of a complex process though.
I have another problem related to this one. When I start creating a new quote straight from Contacts module, it doesnt populate address fields. So I have to select Contact again (or open pop-up and make selection there) and after that fields are getting filled.