Show related module fields in other module

Hola @digitecmedia,

After creating the relationship as many contacts to one product, you can go into studio and add the products field to year Contacts Editview, Detailview etc.

When you also want to show the field Código Farmacia of the products in your contacts detailview, you will need to create this field by vardefs as describe in:

Specifically for your case (please first do this on a test environment):

Create the file:

custom/Extension/modules/AOS_Products/Ext/Vardefs/pharmacy_code.php

with contents

<?php

$dictionary['AOS_Products']['fields']['pharmacy_code'] = array (
    'name' => 'pharmacy_code',
    'vname' => 'LBL_PHARMACY_CODE',
    'type' => 'varchar',
    'len' => 60,
    'audited' => true,
    'unified_search' => true,
    'merge_filter' => 'enabled',
    'reportable' => '1',
    'importable' => 'true',
  );

Create the file

custom/Extension/modules/AOS_Products/Ext/Language/en_us.pharmacy_code.php

With contents:

<?php
$mod_strings['LBL_PHARMACY_CODE'] = 'Pharmacy Code';

For the spanish translation, also create the file:

custom/Extension/modules/AOS_Products/Ext/Language/es_es.pharmacy_code.php

with contents:

<?php
$mod_strings['LBL_PHARMACY_CODE'] = 'Código farmacia';

Create the file:

custom/Extension/modules/Contacts/Ext/Vardefs/product_pharmacy_code.php

with contents:

<?php
$dictionary['Contact']['fields']['aos_products_contacts_1']['join_link_name'] = 'contacts_aos_products_link';
$dictionary['Contact']['fields']['aos_products_contacts_1']['join_name'] = 'aos_products_link';

$dictionary['Contact']['fields']['products_pharmacy_code'] = array (
		'name' => 'products_pharmacy_code',
		'rname' => 'pharmacy_code',
		'id_name' => 'aos_products_contacts_1aos_products_ida',
		'vname' => 'LBL_PRODUCTS_PHARMACY_CODE',
		'join_name'=>'aos_products_link',
		'join_link_name'=>'contacts_aos_products_link',
		'type' => 'relate',
		'link' => 'aos_products_contacts_1',
		'table' => 'aos_products',
		'isnull' => 'true',
		'module' => 'AOS_Products',
		'dbType' => 'varchar',
		'source' => 'non-db',
		'unified_search' => true,
		'massupdate' => false,
		'studio' => array('detailview' => 'true'),
		'inline_edit' => false,
	);

The values for:

  • field name: aos_products_contacts_1
  • id_name: aos_products_contacts_1aos_products_ida
  • link: aos_products_contacts_1

need to correspond to the ones described in the existing file:

custom/Extension/modules/Contacts/Ext/Vardefs/aos_products_contacts_1_Contacts.php

Create the file:

custom/Extension/modules/Contacts/Ext/Language/en_us.products_pharmacy_code.php 

with contents:

<?php
$mod_strings['LBL_PRODUCTS_PHARMACY_CODE'] = 'Pharmacy Code';

For the spanish translation, also create

custom/Extension/modules/Contacts/Ext/Language/es_es.products_pharmacy_code.php 

with contents:

<?php
$mod_strings['LBL_PRODUCTS_PHARMACY_CODE'] = 'Código farmacia';

Do a Admin - Repair - Quick Repair and Rebuild, scroll down and make sure to click on execute to execute the query.

Afterwards the new field Código farmacia is available in the edit, detail and listviews of the products module, as well as in the detail, and listviews of the contacts module.

To migrate the field values of the previously created código farmacia field in studio, execute a query like this:

update aos_products as p, aos_products_cstm as pc set p.pharmacy_code = pc.codigo_farmacia_c where p.id = pc.id_c;

After successful migration you can then remove the código farmacia field previously created in studio.