Is there any way to include the parameter i html portion of mandrill ?
I am not using template.
here is my code.
$mandrill = new Mandrill('YOUR_API_KEY');
$message = array(
'html' => '<p>here is my email</p>',
'text' => 'Example text content',
'subject' => 'example subject',
'from_email' => 'message.from_email#example.com',
'from_name' => 'Example Name',
'to' => array(
array(
'email' => 'recipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'to'
),
array(
'email' => 'recipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'to'
)
),
What i want to do is to add a parameter to the html content.
'html' => '<p>here is my email{ param}</p>', // this line
How can i do this ?
Thanks
Sounds like you're looking to use Mandrill merge tags.
You can insert merge tags into your HTML content and have it inject personalized information for each recipient. They can be used in your content with the format *|MERGETAG|* and by defining "merge_vars" in your message array.
Here's an example from their docs:
"message": {
"global_merge_vars": [
{
"name": "var1",
"content": "Global Value 1"
}
],
"merge_vars": [
{
"rcpt": "emailadress#domain.com",
"vars": [
{
"name": "fname",
"content": "John"
},
{
"name": "lname",
"content": "Smith"
}
]
}
],
source:
http://help.mandrill.com/entries/21678522-How-do-I-use-merge-tags-to-add-dynamic-content-
In testing a bit, Mandrill actually supports a few merge tags "out of the box", so you should just be able to add *|EMAIL|* into your HTML content and it'll pull that email address in from your TO array.
Related
We created custom fields within our plugin for orders and for products.
Shopware creates text snippets for the custom fields labels.
These should be removed when uninstalling the plugin.
It works for the products custom field.
...
'customFields' => [
[
'name' => 'product_custom_field_name_dummy',
'type' => CustomFieldTypes::BOOL,
'config' => [
'type' => 'checkbox',
'componentName' => 'sw-field',
'customFieldType' => 'checkbox',
'label' => [
self::GER_ISO => 'Label GER',
self::EN_ISO => 'Label EN',
Defaults::LANGUAGE_SYSTEM => 'Label EN',
]
],
]
],
'relations' => [
[
'entityName' => ProductDefinition::ENTITY_NAME,
],
],
...
But not for the orders custom fields.
...
'customFields' => [
[
'name' => 'order_custom_field_name_dummy_one',
'type' => CustomFieldTypes::TEXT,
'config' => [
'customFieldType' => CustomFieldTypes::TEXT,
'label' => [
self::GER_ISO => 'Order Label GER',
self::EN_ISO => 'Order Label EN',
Defaults::LANGUAGE_SYSTEM => 'Order Label EN',
]
],
],
[
'name' => 'order_custom_field_name_dummy_two',
'type' => CustomFieldTypes::SELECT,
'config' => [
'customFieldType' => CustomFieldTypes::SELECT,
'componentName' => 'sw-single-select',
'label' => [
self::GER_ISO => 'Order Label GER 2',
self::EN_ISO => 'Order Label EN 2',
Defaults::LANGUAGE_SYSTEM => 'Order Label EN 2',
],
'options' => [
...
]
]
],
[
'name' => 'order_custom_field_name_dummy_three',
'type' => CustomFieldTypes::DATETIME,
'config' => [
'customFieldType' => CustomFieldTypes::DATETIME,
'label' => [
self::GER_ISO => 'Order Label GER 3',
self::EN_ISO => 'Order Label EN 3',
Defaults::LANGUAGE_SYSTEM => 'Order Label EN 3',
]
],
],
[
'name' => 'order_custom_field_name_dummy_four',
'type' => CustomFieldTypes::SELECT,
'config' => [
'customFieldType' => CustomFieldTypes::SELECT,
'componentName' => 'sw-single-select',
'label' => [
self::GER_ISO => 'Order Label GER 4',
self::EN_ISO => 'Order Label EN 4',
Defaults::LANGUAGE_SYSTEM => 'Order Label EN 4',
],
'options' => [
...
]
],
],
],
'relations' => [
[
'entityName' => OrderDefinition::ENTITY_NAME,
],
],
...
Is this a problem Shopware has with order custom fields or did we possibly make a mistake when creating the order custom fields?
Edit:
The custom fields are created on install method und removed on uninstall method inside the plugin via the CustomFieldSetRepository.
Edit:
This is how we delete the custom fields on uninstall:
public function uninstallCustomFieldSet() {
$customFieldSet = $this->getCustomFieldSet(self::CUSTOM_FIELD_SET_NAME);
if ($customFieldSet instanceof CustomFieldSetEntity) {
$this->customFieldSetRepository->delete([['id' => $customFieldSet->getId()]], $this->context);
}
}
protected function getCustomFieldSet(string $customFieldSetName): ?CustomFieldSetEntity {
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', $customFieldSetName));
$criteria->addAssociation('customFields');
$criteria->addAssociation('relations');
$customFieldSet = $this->customFieldSetRepository->search($criteria, $this->context)->first();
if ($customFieldSet instanceof CustomFieldSetEntity) {
return $customFieldSet;
} else {
return null;
}
}
The author mentions that Shopware 6 confirms that it's a bug.
I am creating an answer to this question even though it was already answered in the comments so that it can be accepted & this question resolved.
I am building an Rails 5 app.
In this app I create a user with customfields. The output I get from the client (Javascript) is a bit wrong (and I have no idea how to change that). How can I "transform" the output I get into the output I must have?
The below is what I get
"user_customfields_attributes" => {
"1533038627616" => {
"customfield_id" => "1", "value" => "test 1"
}, "1533038627617" => {
"customfield_id" => "2", "value" => "test 2"
}
}
The below is what I need
"user_customfields_attributes" => [{
"customfield_id" => 1,
"value" => "test 1"
}, {
"customfield_id" => 2,
"value" => "test 2"
}]
Thankful for all help!
In a Fieldset I have an Element\Radio foo and Element\Text bar.
public function init()
{
$this->add(
[
'type' => 'radio',
'name' => 'foo',
'options' => [
'label' => _('foo'),
'value_options' => [
[
'value' => 'a',
'label' => 'a',
'selected' => true
],
[
'value' => 'b',
'label' => 'b'
]
]
]
...
]);
$this->add(
[
'name' => 'bar',
'type' => 'text',
'options' => [
'label' => 'bar',
...
],
...
]);
}
The validation of the field bar is depending on the selected foo option. It's easy to implement, if I can get the selected value of foo:
public function getInputFilterSpecification()
{
return [
'bar' => [
'required' => $this->get('foo')->getCheckedValue() === 'a',
...
],
];
}
But there is no method Radio#getCheckedValue(). Well, I can iterate over the $this->get('foo')->getOptions()['value_options'], but is it really the only way?
How to get (in the Fieldset#getInputFilterSpecification()) the selected option of a Zend\Form\Element\Radio?
The selected option gets POSTed to the server along with everything else from the HTML form and is all of this is available in validators through the $context array.
You can create a conditionally required field by using a callback validator and the $context array like this:
public function getInputFilterSpecification() {
return [
'bar' => [
'required' => false,
'allow_empty' => true,
'continue_if_empty' => true,
'required' => true,
'validators' => [
[
'name' => 'Callback',
'options' => [
'callback' => function ($value, $context) {
return $context['foo'] === 'a'
},
'messages' => [
\Zend\Validator\Callback::INVALID_VALUE => 'This value is required when selecting "a".'
]
]
]
]
],
];
}
That would check if 'foo' is equal to 'a', i.e. option 'a' is selected and return true when it is, which marks the input as valid, and false when it's not, marking the input invalid.
I want to change url in action view, from view to viewdaily, viewweekly and viewmonthly, what should i do?
[
'class' => 'yii\grid\ActionColumn',
],
The simplest way is not create/use ActionColumn, instead you can use raw-column and show there what you want:
[
'attribute' => 'some_title',
'format' => 'raw',
'value' => function ($model) {
return 'your Text';
},
],
I am attempting to send a small rtf attachment through Mandrill. I have created the following json and tried it using the API test page. The attachment is base 64 encoded. The API reports no error and the email comes through but with no attachment. What am I doing wrong?
{
"attachments": [
{
"type": "application/rtf",
"name": "test.rtf",
"content": "e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZGVmZjBcZGVmbGFuZzIwNTd7XGZvbnR0Ymx7XGYwXGZuaWxcZmNoYXJzZXQwIENhbGlicmk7fX0NCntcKlxnZW5lcmF0b3IgTXNmdGVkaXQgNS40MS4yMS4yNTEwO31cdmlld2tpbmQ0XHVjMVxwYXJkXHNhMjAwXHNsMjc2XHNsbXVsdDFcbGFuZzlcZjBcZnMyMiB0aGlzIGlzIGEgdGVzdCBzZW5kaW5nIGZpbGVccGFyDQp9DQoA"
}
],
"message": {
"html": "<html>\r\n<body>test data</body>\r\n</html>\r\n",
"subject": "Cloud Demo",
"from_email": "jklovanc#hotmail.com",
"preserve_recipients": true,
"text": "",
"to": [
{
"type": "to",
"name": "",
"email": "jklovanc#hotmail.com"
}
],
"from_name": "",
"headers": {
"reply-to": "jklovanc#hotmail.com"
}
},
"key": #mykey#,
"async": false
}
Attachments are part of the message object, so the attachments parameter should be nested under the message instead of at the same level. It should look like this instead:
{
"message": {
"attachments": [
{
"type": "application/rtf",
"name": "test.rtf",
"content": "e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZGVmZjBcZGVmbGFuZzIwNTd7XGZvbnR0Ymx7XGYwXGZuaWxcZmNoYXJzZXQwIENhbGlicmk7fX0NCntcKlxnZW5lcmF0b3IgTXNmdGVkaXQgNS40MS4yMS4yNTEwO31cdmlld2tpbmQ0XHVjMVxwYXJkXHNhMjAwXHNsMjc2XHNsbXVsdDFcbGFuZzlcZjBcZnMyMiB0aGlzIGlzIGEgdGVzdCBzZW5kaW5nIGZpbGVccGFyDQp9DQoA"
}
],
"html": "<html>\r\n<body>test data</body>\r\n</html>\r\n",
....
<?php
//It works for me! good luck
/*LIBS*/
include 'lib/mandrill-api-php/src/Mandrill.php';
$mandrill = new Mandrill('YOUR API KEY HERE');
/*ADMIN AND USER EMAIL*/
$admin_email = 'your_email#your_domain.com';
$client_email = 'the_email_of_the_client#mail.com';
/*attach PDF with base64_encode */
$attachment = file_get_contents('the_route_to_your_pdf'); // https://yourdomain/pdf_folder/mypdf.pdf
$attachment_encoded = base64_encode($attachment);
try{
$user_message = array(
'subject' => 'Your subject',
'from_email' => $admin_email,
'from_name' => 'my_domain_for_example',
'html' => '<p>HTML template</p>',
'to' => array(array('email' => $client_email, 'name' => 'Recipient 1')),
'merge_vars' => array(array(
'rcpt' => 'recipient1#domain.com',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Recipient 1 first name'),
array(
'name' => 'LASTNAME',
'content' => 'Last name')
))),
'attachments' => array(
array(
'content' => $attachment_encoded,
'type' => "application/pdf",
'name' => 'the_name_of_the_attach.pdf',
))
);
$res_user_mandrill = $mandrill->messages->send($user_message, $async=false, $ip_pool=null, $send_at=null);
} catch(Mandrill_Error $e) {
}
?>