|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2022 |
|
6
|
|
|
* @package Controller |
|
7
|
|
|
* @subpackage Jobs |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Jobs; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Mail trait for job controllers |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Jobs |
|
19
|
|
|
*/ |
|
20
|
|
|
trait Mail |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Returns the context object |
|
24
|
|
|
* |
|
25
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context object |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract protected function context() : \Aimeos\MShop\Context\Item\Iface; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Returns the CSS rules for the given theme |
|
32
|
|
|
* |
|
33
|
|
|
* @param string|null $theme Theme name |
|
34
|
|
|
* @return string|null CSS rules |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function mailCss( ?string $theme ) : ?string |
|
37
|
|
|
{ |
|
38
|
|
|
$theme = $theme ?: 'default'; |
|
39
|
|
|
$fs = $this->context()->fs( 'fs-theme' ); |
|
40
|
|
|
|
|
41
|
|
|
return $fs->has( $theme . '/email.css' ) ? $fs->read( $theme . '/email.css' ) : null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Returns the e-mail intro message |
|
47
|
|
|
* |
|
48
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface $addr Address item object |
|
49
|
|
|
* @return string Intro message with salutation |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function mailIntro( \Aimeos\MShop\Common\Item\Address\Iface $addr ) : string |
|
52
|
|
|
{ |
|
53
|
|
|
switch( $addr->getSalutation() ) |
|
54
|
|
|
{ |
|
55
|
|
|
case \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_UNKNOWN: |
|
56
|
|
|
/// E-mail intro with first name (%1$s) and last name (%2$s) |
|
57
|
|
|
return $this->context()->translate( 'client', 'Dear %1$s %2$s' ); |
|
58
|
|
|
case \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR: |
|
59
|
|
|
/// E-mail intro with first name (%1$s) and last name (%2$s) |
|
60
|
|
|
return $this->context()->translate( 'client', 'Dear Mr %1$s %2$s' ); |
|
61
|
|
|
case \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MS: |
|
62
|
|
|
/// E-mail intro with first name (%1$s) and last name (%2$s) |
|
63
|
|
|
return $this->context()->translate( 'client', 'Dear Ms %1$s %2$s' ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $this->context()->translate( 'client', 'Dear customer' ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the logo for the given path |
|
72
|
|
|
* |
|
73
|
|
|
* @param string|null $path Logo path relative to fs-media file system |
|
74
|
|
|
* @return string Binary logo data |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function mailLogo( ?string $path ) : string |
|
77
|
|
|
{ |
|
78
|
|
|
$fs = $this->context()->fs( 'fs-media' ); |
|
79
|
|
|
return $path && $fs->has( $path ) ? $fs->read( $path ) : ''; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Prepares and returns a new mail message |
|
85
|
|
|
* |
|
86
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface $addr Address item object |
|
87
|
|
|
* @return \Aimeos\Base\Mail\Message\Iface Prepared mail message |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function mailTo( \Aimeos\MShop\Common\Item\Address\Iface $addr ) : \Aimeos\Base\Mail\Message\Iface |
|
90
|
|
|
{ |
|
91
|
|
|
$context = $this->context(); |
|
92
|
|
|
$config = $context->config(); |
|
93
|
|
|
|
|
94
|
|
|
return $context->mail()->create() |
|
95
|
|
|
->header( 'X-MailGenerator', 'Aimeos' ) |
|
96
|
|
|
->from( $config->get( 'resource/email/from-email' ), $config->get( 'resource/email/from-name' ) ) |
|
97
|
|
|
->to( $addr->getEMail(), $addr->getFirstName() . ' ' . $addr->getLastName() ) |
|
98
|
|
|
->bcc( $config->get( 'resource/email/bcc-email' ) ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns the view for generating the mail message content |
|
104
|
|
|
* |
|
105
|
|
|
* @param string|null $langId Language ID the content should be generated for |
|
106
|
|
|
* @return \Aimeos\MW\View\Iface View object |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function mailView( string $langId = null ) : \Aimeos\MW\View\Iface |
|
109
|
|
|
{ |
|
110
|
|
|
$view = $this->context()->view(); |
|
111
|
|
|
|
|
112
|
|
|
$helper = new \Aimeos\MW\View\Helper\Number\Locale( $view, $langId ); |
|
113
|
|
|
$view->addHelper( 'number', $helper ); |
|
114
|
|
|
|
|
115
|
|
|
$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $this->context()->i18n( $langId ?: 'en' ) ); |
|
116
|
|
|
$view->addHelper( 'translate', $helper ); |
|
117
|
|
|
|
|
118
|
|
|
return $view; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|