Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 140 #143

Merged
merged 6 commits into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ content:
third_party_settings: { }
type: email_default
region: content
field_attendee_email_sent:
weight: 5
settings: { }
third_party_settings: { }
type: datetime_timestamp
region: content
field_attendee_firstname:
weight: 1
settings:
Expand Down Expand Up @@ -64,5 +58,6 @@ content:
hidden:
created: true
field_attended: true
field_attendee_email_sent: true
status: true
uid: true
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ content:
region: content
hidden:
field_attended: true
field_attendee_email_sent: true
field_attendee_status: true
65 changes: 65 additions & 0 deletions config/sync/views.view.my_camp_tickets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
- commerce_order.commerce_order_type.drupal_camp_ticket
- field.storage.commerce_order_item.field_attendee
- field.storage.commerce_order_item.field_t_shirt_size
- field.storage.commerce_order_item.field_t_shirt_type
module:
- commerce
- commerce_order
Expand Down Expand Up @@ -213,6 +214,68 @@ display:
separator: ', '
field_api_classes: false
plugin_id: field
field_t_shirt_type:
id: field_t_shirt_type
table: commerce_order_item__field_t_shirt_type
field: field_t_shirt_type
relationship: order_items
group_type: group
admin_label: ''
label: 'Тип футболки'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: true
trim: false
preserve_tags: ''
html: false
element_type: span
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: list_default
settings: { }
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
quantity:
id: quantity
table: commerce_order_item
Expand Down Expand Up @@ -487,6 +550,7 @@ display:
tags:
- 'config:field.storage.commerce_order_item.field_attendee'
- 'config:field.storage.commerce_order_item.field_t_shirt_size'
- 'config:field.storage.commerce_order_item.field_t_shirt_type'
mail_block:
display_plugin: block
id: mail_block
Expand Down Expand Up @@ -872,3 +936,4 @@ display:
tags:
- 'config:field.storage.commerce_order_item.field_attendee'
- 'config:field.storage.commerce_order_item.field_t_shirt_size'
- 'config:field.storage.commerce_order_item.field_t_shirt_type'
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
use Drupal\Core\Mail\MailManagerInterface;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Render\Renderer;
use Drupal\Core\Url;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\user\UserInterface;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

/**
Expand Down Expand Up @@ -207,46 +209,48 @@ public function attendeesReport() {
* @param OrderItemInterface $commerce_order_item
* @param ParagraphInterface $attendee_paragraph
*
* @return array
* @return array|RedirectResponse
*/
public function sendTicket(UserInterface $user, OrderItemInterface $commerce_order_item, ParagraphInterface $attendee_paragraph) {
$to = $attendee_paragraph->get('field_attendee_email')->value;
if (empty($to)) {
// @TODO show order info
$message = $this->t('Mail was not sent to attendee. Empty recipient address');
$message = $this->t('Mail was not sent to attendee from order :order_id. Empty recipient address.', [
':order_id' => $commerce_order_item->getOrderId(),
]);
$this->getLogger('dckyiv_commerce')->warning($message);
$this->messenger()->addWarning($message);
return [
'#markup' => $message,
];
}
$order = $commerce_order_item->getOrder();
$params = [
'headers' => [
'Content-Type' => 'text/html; charset=UTF-8;',
'Content-Transfer-Encoding' => '8Bit',
],
'from' => $order->getStore()->getEmail(),
'subject' => 'Ticket info',
'attendee_paragraph' => $attendee_paragraph,
];
else {
$order = $commerce_order_item->getOrder();
$params = [
'headers' => [
'Content-Type' => 'text/html; charset=UTF-8;',
'Content-Transfer-Encoding' => '8Bit',
],
'from' => $order->getStore()->getEmail(),
'subject' => 'Ticket info',
'attendee_paragraph' => $attendee_paragraph,
];

$viewBuilder = $this->entityTypeManager()->getViewBuilder('paragraph');
$build = $viewBuilder->view($attendee_paragraph, 'mail');
$params['body'] =$this->renderer->executeInRenderContext(new RenderContext(), function () use ($build) {
return $this->renderer->render($build);
});
$langcode = $this->languageManager()->getDefaultLanguage()->getId();

$result = $this->mailManager->mail('commerce_order', 'receipt', $to, $langcode, $params);
if ($result['send']) {
$attendee_paragraph->set('field_attendee_email_sent', time());
$attendee_paragraph->save();
$viewBuilder = $this->entityTypeManager()->getViewBuilder('paragraph');
$build = $viewBuilder->view($attendee_paragraph, 'mail');
$params['body'] = $this->renderer->executeInRenderContext(new RenderContext(), function () use ($build) {
return $this->renderer->render($build);
});
$langcode = $this->languageManager()->getDefaultLanguage()->getId();

$result = $this->mailManager->mail('commerce_order', 'receipt', $to, $langcode, $params);
if ($result['send']) {
$attendee_paragraph->set('field_attendee_email_sent', time());
$attendee_paragraph->save();
}
$this->messenger()->addStatus($this->t('Ticket has been sent to @mail', [
'@mail' => $to,
]));
}
// @TODO redirect with message.
return [
'#markup' => $this->t('Ticket has been sent'),
];
return new RedirectResponse(Url::fromRoute('view.my_camp_tickets.my_tickets_page', [
'user' => $user->id(),
])->toString());
}

}
Loading