Adding a custom/relate field in Email template in Sugarcrm - sugarcrm

I have created a custom module named surveys which will be in many to many relationship with targets. I need to insert survey name while sending campaign mails to targets.
Currently I managed to populate survey module entities in insert variable by following the guide from adding a custom module in insert variable dropdownlist in email template but the issue is it will never parse the survey name and displays $survey_name in emails that are delivered.
Any help/guidance to sort this out.

I just added the answer to that forum. The sugarCrm EmailTemplate modules basically is a lot of code to get just few beans working (Accounts, Contacts, Leads, Users, Prospects), I get some templates working with other beans with this steps, this code is based on SugarCrm 6.0.2, class modules/Email.php details on the forum:
1) Let the Email.php create the own bean. Example: LOC510
if (... $_REQUEST['parent_type'] == 'Prospects' || TRUE)
2) Create an array of replace fields. Example: LOC521
foreach($bean->field_defs as $key => $field_def) {
$replace_fields ['$'.strtolower(get_class($bean).'_'.$field_def['name'])]
= $bean->$field_def['name'];
//example of fieldnames: $bug_name, $bug_type, $case_date_created, $case_name, etc...
}
3) Replace the fields on html template. Example: LOC545
$this->description_html = str_replace(array_keys($replace_fields), $replace_fields, $this->description_html);
3) Replace the fields on txt template. Example: LOC549
$this->description = str_replace(array_keys($replace_fields), $replace_fields, $this->description);

Related

Shopware 6 Plugin - Load and display ProductStream via id

I want to load ProductStream data via a given id and display it in the frontend, for example below the product cart.
The ProductStream is not linked to a ProductCrossSelling and therefore not linked to a product.
I loaded a ProductStream Collection via the repository.
$criteria = new Criteria($producStreamIds);
$productStreamResult = $this->productStreamRepository->search($criteria, $context);
$productStreams = $productStreamResult->getEntities();
Now I need the associated list of products, to include them via cms-element-product-slider.html.twig.
I found a post with a similar question:
How to get products from the product stream ID in Shopware 6?
The answer was, to use the function loadByStream of Core\Content\Product\SalesChannel\CrossSelling\ProductCrossSellingRoute.php, but this function is private.
The only public function is load and it needs a $productId as a parameter, which I do not have, because my ProductStream is not linked to a product.
Is there a clean way to load products of a ProductStream that is not linked to a ProductCrossSelling?
I have currently copied the code of the loadByStream function to load the products for the stream.
Or is there an other function in the shopware core that I can use for this case. I haven't found anything else.
It feels as if the current assumption is that ProductStreams are not used without connection to a ProductCrossSelling and thus to a product.
A product stream is really just a collection of criterium filters. You inject ProductStreamBuilder and call buildFilters with the id of your product stream to retrieve the filters. Then you use the filters as normal with your criteria, add a limit, sorting etc and fetch your product entities.
// <argument type="service" id="Shopware\Core\Content\ProductStream\Service\ProductStreamBuilder"/>
private ProductStreamBuilderInterface $productStreamBuilder;
// <argument type="service" id="sales_channel.product.repository"/>
private SalesChannelRepositoryInterface $productRepository;
// ..
$filters = $this->productStreamBuilder->buildFilters(
$productStreamId,
$salesChannelContext->getContext()
);
$criteria = new Criteria();
$criteria->addFilter(...$filters);
$products = $this->productRepository
->search($criteria, $salesChannelContext)
->getEntities();

Access related model fields from ModelAdmin actions for exporting to excel

I am desperately waiting for someone attention to get my question answered.... please help..
ModelAdmin model has to export to Excel action method.
I need to access related model fields in action method. That means I can not pass any arguments therefore I tried relatedmodel_set but ModelAdmin action method shows memory location and fails when I try to access values through attributes:
<django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager..RelatedManager object at 0x7f8eea904ac0>
model.py
class EnrolStudent(models.Model):
def get_trn_activity(self):
return self.studenttraininactivities_set
class StudentTraininActivities(models.Model):
trainin_activities = models.ForeignKey(EnrolStudent,
on_delete=CASCADE, null=True )
<other fields...>
admin.py
#admin.register(EnrolStudent)
class EnrolAdmin(admin.ModelAdmin):
form = CityInlineForm
inlines = [CohortTraininActivitiesInline]
...
actions = [export_as_txt_action_0120("File NAT00120 data Export"
, fields=['information_no', 'get_trn_activity',
'student_enrol__student_code'])]
I need to access related model fields to export to excel.
I can not pass parameter to get_trn_activity as you have noticed.
Therefore selected rows only data from Django admin change_list page will only need bit of work using its queryset in actions method used in separate actions.py file that I can do!
Please help me with this issue. I am new to Python / Django.
I also tried property decorator in related model then access in a method in main model then call it inside action but same problem with memory address not the direct value and then how to get data of memory location here .... I don't know.
If I can access the related fields then I can do it no issue.
Another question:
I had same situation with model/related model before, but they were connected through OneToOneField relationship and I was able to use dundor to access related model fields but in this case of ForiegnKey relationship I can not see related model in queryset.
In other case this is what I can do easily; here cohortdetails is related model and when I debug I saw it was listed in queryset that was great.
actions = [export_as_txt_action_0080("File NAT00080 txt Export",
fields=['rto_student_code', 'first_name', 'family_name'
,'cohortdetails__highest_school__highestschool_levelcode',
'cohortdetails__cohort_gender'
, 'cohortdetails__student_dob' ])]

How to customize register and contact forms in PrestaShop?

I need to know how to customize my contact and register forms. How to add new fileds ( and ) and make the information from these fields required or not required.
I need to know which files I must edit for these forms...
I use prestashop 1.4.7.0
This is really two separate questions as there are major differences in how you would handle each case.
Answer 1
For the registration form you can write a module which contains two hook handler functions. These will be:
public function hookCreateAccountForm() {}
public function hookCreateAccount($params) {}
The first function allows you to add additional fields to the registration form (by default these are inserted at the end of the form authentication.tpl, although you could move them all as a single group elsewhere). It should simply return the additional form html you require.
The second function provides you with two parameters to handle the account creation process. This is executed after the standard fields have been validated and the new customer has been created. Unfortunately you cannot do validation on your additional fields using this (you would need to either use javascript or override AuthController to perform your own authentication in the preProcess() member function). In one of my own custom modules for a site I have the following, for example:
public function hookCreateAccount($params)
{
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$customer = $params['newCustomer'];
$address = new Address(Address::getFirstCustomerAddressId((int)$customer->id));
$membership_number = $params['_POST']['membership_number'];
....
....
}
$params['newCustomer'] is a standard Prestashop element in the array and contains the newly created customer object. Your fields will be in the $params['_POST'] array - in my case it was an input field called membership_number.
Answer 2
For the contact form it's a whole lot more complicated I'm afraid. The simplest method for the html is to just hard-code your additional fields in the template file contact-form.tpl.
To actually process the form you will need to create an override for the controller by ceating a file called ContactController.php in /<web-root>/<your-optional-ps-folder>/override/controller containing something like:
<?php
class ContactController extends ContactControllerCore {
function preProcess()
{
if (Tools::isSubmit('submitMessage'))
{
// The form has been submitted so your field validation code goes in here.
// Get the entered values for your fields using Tools::getValue('<field-name>')
// Flag errors by adding a message to $this->errors e.g.
$this->errors[] = Tools::displayError('I haven't even bothered to check!');
}
parent::preProcess();
if (Tools::isSubmit('submitMessage') && is_empty($this->errors))
{
// Success so now perform any addition required actions
// Note that the only indication of success is that $this->errors is empty
}
}
}
Another method would be to just copy the entire preProcess function from controllers\ContactController and just hack away at it until it does what you want....

Programmatically adding an article to Joomla

I am very new to Joomla (frankly just started exploring the possibility of using Joomla) and need help with programmatically adding articles to Joomla backend tables (please see details below). Also along the same lines, I would like to understand how should values for the columns:
parent_id
lft
rgt
level
be generated for the table jos_assets (#__assets) and what is their functional role (eg are they “pointers/indexes” analogous to, say, an os inode to uniquely indentify a file or are they more functional attributes such as identifying the category, subcategory etc)
It might help to use the following SIMPLIFIED example to illustrate what I am trying to do. Say we have a program that collects various key information such as names of the authors of web articles, the subject type of the articles, the date of articles as well as a link to the article. I want to be able to extend this program to programmatically store this information in Joomla. Currently this information is stored in a custom table and the user, through a custom php web page, can use search criteria say by author name, over a certain range of dates to find the article(s) of interest. The result of this search is then displayed along with a hyperlink to the actual article. The articles are stored locally on the web server and are not external links. The portion of the hyperlink stored in the custom table includes the relative path of the physical document (relative to the web root), so for example:
Author date type html_file
Tom 08-14-2011 WEB /tech/11200/ar_324.html
Jim 05-20-2010 IND /tech/42350/ar_985.html
etc.
With all the advantages that Joomla offers over writing custom php search and presentation pages as well as trending etc, we would really like to switch to it. It seems that among other tables for example that #__assets and #__content can be populated programmatically to populate Joomla from our existing php program (which is used to compile the data) and then use Joomla.
Any examples, suggestions and help is greatly appreciated
Kindest regards
Gar
Just an initial note: Joomla 1.6/1.7 are pretty similar. 1.5 not so much. I'll assume 1.6/1.7, as that's what I'd recommend as a base for a new project.
First up, you'll need to be running with access to the Joomla framework. You could do this through a Component, or a module, or a cron that bootstraps it or whatever. I won't go though how to do that.
But once you do that, creating an article is reasonably simple.
<?php
require_once JPATH_ADMINISTRATOR . '/components/com_content/models/article.php';
$new_article = new ContentModelArticle();
$data = array(
'catid' => CATEGORY_ID,
'title' => 'SOME TITLE',
'introtext' => 'SOME TEXT',
'fulltext' => 'SOME TEXT',
'state' => 1,
);
$new_article->save($data);
The actual list of fields will be a bit longer than that (required fields etc), but you should get sane error messages etc from the Joomla framework which illuminate that.
So in summary:
Load up the Joomla framework so you have access to the DB, components, models, etc
Include the com_content article class, which will handle validation, saving to the database etc for you
Create an article instance with the required fields filled in as appropriate
Call save()
Now that I think about it, that'll probably work in 1.5...
Found a better way to do this without any errors Create a Joomla! Article Programatically
$table = JTable::getInstance('Content', 'JTable', array());
$data = array(
'catid' => 1,
'title' => 'SOME TITLE',
'introtext' => 'SOME TEXT',
'fulltext' => 'SOME TEXT',
'state' => 1,
);
// Bind data
if (!$table->bind($data))
{
$this->setError($table->getError());
return false;
}
// Check the data.
if (!$table->check())
{
$this->setError($table->getError());
return false;
}
// Store the data.
if (!$table->store())
{
$this->setError($table->getError());
return false;
}

Is there a way to programmatically grab a list of meeting attendees from Outlook?

I am trying to grab a list of meeting attendees from Outlook 2003. I am open to using any language that would be appropriate. Scripting languages are preferable. Any suggestions?
The information is exposed through the outlook COM interface so any language that can talk COM would work fine.
I once wrote a piece of code that did just this (and some more), and you can see the source yourself.
If you can't be bothered to look through that code, in a nutshell you do:
// Also, don't forget to add a project reference to the outlook COM object
using Microsoft.Office.Interop.Outlook;
...
var outlookNS = OutlookApp.GetNamespace("MAPI");
var calendar = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
foreach (AppointmentItem item in calendar.Items)
{
// Mandatory attendees (in the "To:" field)
foreach (var attendee in item.Recipents)
Console.WriteLine("Attendee {0}", attendee);
// Optional Attendees (in the "CC:" field)
foreach (var attendee in item.OptionalAttendees)
Console.WriteLine("Attendee {0}", attendee);
}
In perl you would use Win32::OLE.
See for examle this link and of course the documentation that comes with that module.
You should also be able to simply rewrite the VB code given above to perl using Win32::OLE.
And also see this other question.