Related
I'm trying to add a new field to Admin Preferences - a textarea field with tinymce. I've added code to AdminPreferencesController.php:
$this->fields_options['contact'] = array(
'title' => $this->l('Contact'),
'icon' => 'icon-cogs',
'submit' => array('title' => $this->l('Save')),
);
$this->fields_options['contact']['fields']['PS_CONTACT_ADDITIONAL_INFO'] = array(
'type' => 'textarea',
'label' => $this->l('Short description'),
'name' => 'short_description',
'lang' => true,
'cols' => 60,
'rows' => 10,
'autoload_rte' => 'rte',
'col' => 6,
);
But tinymce doesnt' appear and when I'm using HTML tags after saving they disappear. Presta strips all HTML tags.
How to allow HTML tags on this field and enable tinymce?
It seems that you can't just add it in a regular way. But you can implement it in a next way.
First of all, use field type textareaLang instead of textarea and add a parameter 'validation' => 'isCleanHtml' to this field
$this->fields_options['contact']['fields']['PS_CONTACT_ADDITIONAL_INFO'] = array(
'type' => 'textareaLang',
'label' => $this->l('Short description'),
'name' => 'short_description',
'lang' => true,
'cols' => 60,
'rows' => 10,
'col' => 6,
'validation' => 'isCleanHtml'
);
Create your own script to initialize your editor. I created a script tinymce.init.js and put it to js/admin/ folder
$(document).ready(function(){
ad = ''; // this is defenition of the external plugin path. I didn't fint how it can impact on script if it's empty but by default it it the path to your admin folder
iso = iso_user;
var config = {
selector: '.textarea-autosize'
};
tinySetup(config);
});
Then include tinymce script and your own to this controller AdminPreferencesController.php
public function setMedia()
{
$this->context->controller->addJquery();
$this->context->controller->addJS(
array(
_PS_JS_DIR_.'admin/tinymce.init.js',
_PS_JS_DIR_.'tiny_mce/tiny_mce.js',
_PS_JS_DIR_.'admin/tinymce.inc.js'
)
);
parent::setMedia();
}
It should implement your requirements. But don't forget that now you should call your configuration field in multilingual scope. So, add a language id to Configuration::get() like
Configuration::get('PS_CONTACT_ADDITIONAL_INFO, $id_lang)
whenever you use it.
P.S. Bear in mind that the best solution for your goal is to create a simple module which will handle this. And far more, it is recommended way.
I want to filter list that does not have an invalid email and opt-out email in Leads and Contact module using SugarCRM 7 API.
I have added below email filter in arguments but does not work. How to email filter via SugarCRM 7.x rest API.
$filter_arguments = array(
"filter" => array(
array(
"assigned_user_id" => 1,
),
array(
"email1" => array(
array(
'opt_out' => array(
'$equals' => ''
)
)
)
),
),
);
$url = $base_url . "/Contacts/filter";
Thanks.
This much code will not help you please check this :
Reference Link 1
Reference Link 2
The following example will demonstrate how to add a predefined filter on the Accounts module to return all records with an account type of "Customer" and industry of "Other".
To create a predefined filter, create a display label extension in ./custom/Extension/modules/<module>/Ext/Language/. For this example, we will create:
./custom/Extension/modules/Accounts/Ext/Language/en_us.filterAccountByTypeAndIndustry.php
<?php
$mod_strings['LBL_FILTER_ACCOUNT_BY_TYPE_AND_INDUSTRY'] = 'Customer/Other Accounts';
Next, create a custom filter extension in ./custom/Extension/modules/<module>/Ext/clients/base/filters/basic/.
For this example, we will create:
./custom/Extension/modules/Accounts/Ext/clients/base/filters/basic/filterAccountByTypeAndIndustry.php
<?php
$viewdefs['Accounts']['base']['filter']['basic']['filters'][] = array(
'id' => 'filterAccountByTypeAndIndustry',
'name' => 'LBL_FILTER_ACCOUNT_BY_TYPE_AND_INDUSTRY',
'filter_definition' => array(
array(
'account_type' => array(
'$in' => array(
'Customer',
),
),
),
array(
'industry' => array(
'$in' => array(
'Other',
),
),
),
),
'editable' => false,
'is_template' => false,
);
You should notice that the editable and is_template options have been set to "false". If editable is not set to "false", the filter will not be displayed in the list view filter's list.
Finally, navigate to Admin > Repair and click "Quick Repair and Rebuild" to rebuild the extensions and make the predefined filter available for users.
Adding Initial Filters to Lookup Searches
To add initial filters to record lookups and type-ahead searches, define a filter template. This will allow you to filter results for users when looking up a parent related record. The following example will demonstrate how to add an initial filter for the Account lookup on the Contacts module. This initial filter will limit records to having an account type of "Customer" and a dynamically assigned user value determined by the contact's assigned user.
To add an initial filter to the Contacts record view, create a display label for the filter in ./custom/Extension/modules/<module>/Ext/Language/. For this example , we will create:
./custom/Extension/modules/Accounts/Ext/Language/en_us.filterAccountTemplate.php
<?php
$mod_strings['LBL_FILTER_ACCOUNT_TEMPLATE'] = 'Customer Accounts By A Dynamic User';
Next, create a custom template filter extension in ./custom/Extension/modules/<module>/Ext/clients/base/filters/basic/.
For this example, create:
./custom/Extension/modules/Accounts/Ext/clients/base/filters/basic/filterAccountTemplate.php
<?php
$viewdefs['Accounts']['base']['filter']['basic']['filters'][] = array(
'id' => 'filterAccountTemplate',
'name' => 'LBL_FILTER_ACCOUNT_TEMPLATE',
'filter_definition' => array(
array(
'account_type' => array(
'$in' => array(),
),
),
array(
'assigned_user_id' => ''
)
),
'editable' => true,
'is_template' => true,
);
As you can see, the filter_definition contains arrays for account_type and assigned_user_id. These filter definitions will receive their values from the contact record view's metadata. You should also note that this filter has is_template and editable set to "true". This is required for initial filters.
Once the filter template is in place, modify the contact record view's metadata. To accomplish this, edit ./custom/modules/Contacts/clients/base/views/record/record.php to adjust the account_name field. If this file does not exist in your local Sugar installation, navigate to Admin > Studio > Contacts > Layouts > Record View and click "Save & Deploy" to generate it. In this file, identify the panel_body array as shown below:
1 =>
array (
'name' => 'panel_body',
'label' => 'LBL_RECORD_BODY',
'columns' => 2,
'labelsOnTop' => true,
'placeholders' => true,
'newTab' => false,
'panelDefault' => 'expanded',
'fields' =>
array (
0 => 'title',
1 => 'phone_mobile',
2 => 'department',
3 => 'do_not_call',
4 => 'account_name',
5 => 'email',
),
),
Next, modify the account_name field to contain the initial filter parameters.
1 =>
array (
'name' => 'panel_body',
'label' => 'LBL_RECORD_BODY',
'columns' => 2,
'labelsOnTop' => true,
'placeholders' => true,
'newTab' => false,
'panelDefault' => 'expanded',
'fields' =>
array (
0 => 'title',
1 => 'phone_mobile',
2 => 'department',
3 => 'do_not_call',
4 => array (
//field name
'name' => 'account_name',
//the name of the filter template
'initial_filter' => 'filterAccountTemplate',
//the display label for users
'initial_filter_label' => 'LBL_FILTER_ACCOUNT_TEMPLATE',
//the hardcoded filters to pass to the templates filter definition
'filter_populate' => array(
'account_type' => array('Customer')
),
//the dynamic filters to pass to the templates filter definition
//please note the index of the array will be for the field the data is being pulled from
'filter_relate' => array(
//'field_to_pull_data_from' => 'field_to_populate_data_to'
'assigned_user_id' => 'assigned_user_id',
)
),
5 => 'email',
),
),
Finally, navigate to Admin > Repair and click "Quick Repair and Rebuild". This will rebuild the extensions and make the initial filter available for users when selecting a parent account for a contact.
Adding Initial Filters to Drawers from a Controller
When creating your own views, you may need to filter a drawer called from within your custom controller. Using an initial filter, as described in the Adding Initial Filters to Lookup Searches section, we can filter a drawer with predefined values by creating a filter object and populating the config.filter_populate property as shown below:
//create filter
var filterOptions = new app.utils.FilterOptions()
.config({
'initial_filter': 'filterAccountTemplate',
'initial_filter_label': 'LBL_FILTER_ACCOUNT_TEMPLATE',
'filter_populate': {
'account_type': ['Customer'],
'assigned_user_id': 'seed_sally_id'
}
})
.format();
//open drawer
app.drawer.open({
layout: 'selection-list',
context: {
module: 'Accounts',
filterOptions: filterOptions,
parent: this.context
}
});
To create a filtered drawer with dynamic values, create a filter object and populate the config.filter_relate property using the populateRelate method as shown below:
//record to filter related fields by
var contact = app.data.createBean('Contacts', {
'first_name': 'John',
'last_name': 'Smith',
'assigned_user_id': 'seed_sally_id'
});
//create filter
var filterOptions = new app.utils.FilterOptions()
.config({
'initial_filter': 'filterAccountTemplate',
'initial_filter_label': 'LBL_FILTER_ACCOUNT_TEMPLATE',
'filter_populate': {
'account_type': ['Customer'],
},
'filter_relate': {
'assigned_user_id': 'assigned_user_id'
}
})
.populateRelate(contact)
.format();
//open drawer
app.drawer.open({
layout: 'selection-list',
context: {
module: 'Accounts',
filterOptions: filterOptions,
parent: this.context
}
});
I recently built a website for work because our techs need an easy way to find out what keys go to which properties we provide service to. I've gotten the site working with live search (Ajaxlivesearch.com) and it's linked to my MySQL database. Everything works great except it only searches one column currently, the Address column. I'd like to be able to search two columns, Address and Property_Name at the same time.
Here's the current code, or at least the part that deals with searching the db.
<?php
namespace AjaxLiveSearch\core;
if (count(get_included_files()) === 1) {
exit('Direct access not permitted.');
}
/**
* Class Config
*/
class Config
{
/**
* #var array
*/
private static $configs = array(
// ***** Database ***** //
'dataSources' => array(
'ls_query' => array(
'host' => '',
'database' => '',
'username' => '',
'pass' => '',
'table' => '',
// specify the name of search columns
'searchColumns' => array('Address'),
// specify order by column. This is optional
'orderBy' => '',
// specify order direction e.g. ASC or DESC. This is optional
'orderDirection' => '',
// filter the result by entering table column names
// to get all the columns, remove filterResult or make it an empty array
'filterResult' => array(),
// specify search query comparison operator. possible values for comparison operators are: 'LIKE' and '='. this is required.
'comparisonOperator' => 'LIKE',
// searchPattern is used to specify how the query is searched. possible values are: 'q', '*q', 'q*', '*q*'. this is required.
'searchPattern' => 'q*',
// specify search query case sensitivity
'caseSensitive' => false,
// to limit the maximum number of result uncomment this:
'maxResult' => 10,
// to display column header, change 'active' value to true
'displayHeader' => array(
'active' => true,
'mapper' => array(
'Property_Name' => 'Property Name',
'Address' => 'Address',
'Key' => 'Key',
'Property_Manager' => 'Property Manager',
'Door_Code' => 'Door Code'
)
),
// add custom class to <td> and <th>
// To hide a column use class 'ls_hide'
'columnClass' => array(
'Count' => 'ls_hide',
'Reserve' => 'ls_hide'
),
'type' => 'mysql',
),
I've taken the connection info out for obvious reasons.
I tried 'searchColumns' => array('Address' AND 'Property_Name'), thinking that would search both columns but that didn't work at all.
I'm not familiar with Ajaxlivesearch, but it looks like searchColumns takes an array, so:
'searchColumns' => array('Address', 'Property_Name'),
will probably work.
(array('Address' AND 'Property_Name') is a syntax error.)
And of course as soon as I post the question I figure it out, maybe it will help someone else though. To look at multiple columns in one array you need to separate them with a comma (,) the working code is:
<?php
namespace AjaxLiveSearch\core;
if (count(get_included_files()) === 1) {
exit('Direct access not permitted.');
}
/**
* Class Config
*/
class Config
{
/**
* #var array
*/
private static $configs = array(
// ***** Database ***** //
'dataSources' => array(
'ls_query' => array(
'host' => '',
'database' => '',
'username' => '',
'pass' => '',
'table' => '',
// specify the name of search columns
'searchColumns' => array('Address', 'Property_Name'),
// specify order by column. This is optional
'orderBy' => '',
// specify order direction e.g. ASC or DESC. This is optional
'orderDirection' => '',
// filter the result by entering table column names
// to get all the columns, remove filterResult or make it an empty array
'filterResult' => array(),
// specify search query comparison operator. possible values for comparison operators are: 'LIKE' and '='. this is required.
'comparisonOperator' => 'LIKE',
// searchPattern is used to specify how the query is searched. possible values are: 'q', '*q', 'q*', '*q*'. this is required.
'searchPattern' => 'q*',
// specify search query case sensitivity
'caseSensitive' => false,
// to limit the maximum number of result uncomment this:
'maxResult' => 10,
// to display column header, change 'active' value to true
'displayHeader' => array(
'active' => true,
'mapper' => array(
'Property_Name' => 'Property Name',
'Address' => 'Address',
'Key' => 'Key',
'Property_Manager' => 'Property Manager',
'Door_Code' => 'Door Code'
)
),
// add custom class to <td> and <th>
// To hide a column use class 'ls_hide'
'columnClass' => array(
'Count' => 'ls_hide',
'Reserve' => 'ls_hide'
),
'type' => 'mysql',
),
Run code snippetCopy snippet to answer
I have a Attribute called "Color" and it has two attributes "Red" and "Green".
When i run this using WC REST API
Everything is working from the below code, i am stuck with the attributes.
print_r( $client->products->create( array(
'title' => 'Nile - Over Counter Basin',
'sku' => '91081_Nile',
'type' => 'simple',
'regular_price' => '7260',
'sale_price' => '5445',
'description' => 'Nile - Over Counter BasinOver Counter BasinHindware Italian CollectionContemporary design with smooth flowing line Space for toiletries',
'dimensions'=>array( 'length' =>'67.5' ,'width' =>'39.5','height'=>'12.5'),
'categories'=>array( ' SANITARYWARE' =>'592',' WASHBASIN' =>'650',' Table Top Wash Basin' =>'508'),
'images' =>Array ('91081_Nile'=>Array('src'=>'http://www.somethingsomething.com/images/products/91081/2.jpg','title'=>'91081_Nile','position'=>'0') ),
'short_description'=>'Contemporary design with smooth flowing line Space for toiletries <table id="ProductDescriptiontable"><tr><td>Brand</td><td>:</td><td class="thirdcolumn">Hindware</td></tr><tr><td>Product Name</td><td>:</td><td class="thirdcolumn">Nile - Over Counter Basin</td></tr><tr><td>Product Description</td><td>:</td><td class="thirdcolumn">Table Top Wash Basin</td></tr></tr><tr><td>Product Color</td><td>:</td><td class="thirdcolumn">StarwhiteIvory</td></tr></table>',
'attributes' => Array ('name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red'),
'enable_html_short_description' => true, // This is the line you need to add
) ) ) ;
Anand: After adding the attributes in multiple array, the attributes are displayed in correct section, but they are not considered as attributes, .. please see the image, they are seen as a plain text and not as an attributes.
My Code is:
'attributes'=>array(array('name'=>'Color','Slug'=>'color','position'=>'0','visible'=>true,'options'=>'Starwhite'),array('name'=>'Model',
'Slug'=>'model','position'=>'0','visible'=>true,'options'=>'Pedestal Wash Basin'),array('name'=>'Brands','Slug'=>'brands','position'=>'0','visible'=>true,'options'=>'Hindware'),array('name'=>'Washbasin Size','Slug'=>'washbasin-size','position'=>'0','visible'=>true,'options'=>'56 x 46 x 38.5 cm'),array('name'=>'Washbasin Type','Slug'=>'washbasin-type','position'=>'0','visible'=>true,'options'=>'Washbasin With Pedestal'))
You need to pass attributes as an array of arrays, change
'attributes' => Array ('name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red'),
to
'attributes' => array( array( 'name'=>'Color','slug'=>'color','position'=>'0','visible'=>'true','options'=>'Red' ) ),
P.S: I am presuming there that the taxonomy and term already exist, and that the taxonomy's type is set to text.
EDIT
When the taxonomy's type is set to "text" pass options as plain text
'options' => 'term'
When the taxonomy's type is set to "select" pass options as an array
'options' => array( 'red', 'white' )
To pass multiple attributes, send them as an array of arrays, for eg:
'attributes'=>array(
array( 'name'=>'Color', 'slug'=>'color', 'position'=>'0', 'visible'=>true, 'options'=> array('Starwhite') ),
array( 'name'=>'Washbasin Type', 'slug'=>'washbasin-type', 'position'=>'0', 'visible'=>true, 'options'=> array('Washbasin With Pedestal') ),
);
I had asked a question here a while back about setting up database populated dropdowns for SugarCRM. I received a really good answer and, after more php studies and a dev instance running, I decided to give it a shot. The instructions I followed can be found here. After I run the repair and rebuild, I would expect to see the custom field in my Fields list under the module in studio, but have not been able to find it. The module is named Makers (a1_makers as a database table). For good orders sake, there were no errors when I repaired/rebuilt after saving the files. Per the instructions, I first created a php file with a custom function to query the database (custom/Extension/application/Ext/Utils/getMakers.php):
<?php
function getMakers() {
static $makers = null;
if (!$makers){
global $db;
$query = "SELECT id, name FROM a1_maker";
$result = $db->query($query, false);
$accounts = array();
$accounts[''] = '';
while (($row = $db->fetchByAssoc($result)) !=null) {
$accounts[$row['id']] = $row['name'];
}
}
return $makers;
}
?>
Then, I set 'function' field in Vardefs to point to the function (custom/Extension/modules/Maker/Ext/Vardefs/makers_template.php):
<?php
$dictionary['Maker']['fields']['list_of_makers'] = array (
'name' => 'list_of_makers',
'vname' => 'LBL_MKRLST'
'function' => 'getMakers',
'type' => 'enum',
'len' => '100',
'comment' => 'List of makers populated from the database',
);
?>
Unfortunately, there are no errors and the repair/rebuild runs fine. I am just unable to see the custom field when I go into studio. Can anyone please help point out what I may be doing wrong?
I would recommend checking existence of newly created field 'list_of_makers' in cache/modules/Maker/Makervardefs.php file. If new field definition exists in that file, try add 'studio' => 'visible' to custom/Extension/modules/Maker/Ext/Vardefs/makers_template.php to get something like this:
<?php
$dictionary['Maker']['fields']['list_of_makers'] = array (
'name' => 'list_of_makers',
'vname' => 'LBL_MKRLST'
'function' => 'getMakers',
'type' => 'enum',
'studio' => 'visible'
'len' => '100',
'comment' => 'List of makers populated from the database',
);
Try to edit your custom/modules/Maker/metadata/editviewdefs.php manually and insert field definition by hand in proper place if everything above won't work.
$dictionary['Maker']['fields']['list_of_makers'] = array (
'name' => 'list_of_makers',
'vname' => 'LBL_MKRLST'
'function' => 'getMakers',
'type' => 'enum',
'studio' => 'visible'
'len' => '100',
'comment' => 'List of makers populated from the database',
'studio' => array(
'listview' => true,
'detailview' => true,
'editview' => true
),
);