|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018-2022 |
|
6
|
|
|
* @package Controller |
|
7
|
|
|
* @subpackage Common |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Common\Subscription\Process\Processor\Email; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Customer group processor for subscriptions |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Common |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\Controller\Common\Subscription\Process\Processor\Base |
|
22
|
|
|
implements \Aimeos\Controller\Common\Subscription\Process\Processor\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
use \Aimeos\Controller\Jobs\Mail; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Executed after the subscription renewal |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item |
|
31
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $order Order invoice item |
|
32
|
|
|
*/ |
|
33
|
|
|
public function renewAfter( \Aimeos\MShop\Subscription\Item\Iface $subscription, \Aimeos\MShop\Order\Item\Iface $order ) |
|
34
|
|
|
{ |
|
35
|
|
|
if( $subscription->getReason() === \Aimeos\MShop\Subscription\Item\Iface::REASON_PAYMENT ) { |
|
36
|
|
|
$this->notify( $subscription ); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Processes the end of the subscription |
|
43
|
|
|
* |
|
44
|
|
|
* @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item |
|
45
|
|
|
*/ |
|
46
|
|
|
public function end( \Aimeos\MShop\Subscription\Item\Iface $subscription ) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->notify( $subscription ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Sends e-mails for the given subscription |
|
54
|
|
|
* |
|
55
|
|
|
* @param \Aimeos\MShop\Subscription\Item\Iface $subscription Subscription item object |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function notify( \Aimeos\MShop\Subscription\Item\Iface $subscription ) |
|
58
|
|
|
{ |
|
59
|
|
|
$context = $this->context(); |
|
60
|
|
|
$manager = \Aimeos\MShop::create( $context, 'order/base' ); |
|
61
|
|
|
$base = $manager->get( $subscription->getOrderBaseId(), ['order/base/address', 'order/base/product'] ); |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
$address = current( $base->getAddress( 'payment' ) ); |
|
64
|
|
|
$siteIds = explode( '.', trim( $base->getSiteId(), '.' ) ); |
|
65
|
|
|
$sites = \Aimeos\MShop::create( $context, 'locale/site' )->getPath( end( $siteIds ) ); |
|
66
|
|
|
|
|
67
|
|
|
$view = $this->view( $base, $sites->getTheme()->filter()->last() ); |
|
68
|
|
|
$view->subscriptionItem = $subscription; |
|
69
|
|
|
$view->addressItem = $address; |
|
70
|
|
|
|
|
71
|
|
|
foreach( $base->getProducts() as $orderProduct ) |
|
72
|
|
|
{ |
|
73
|
|
|
if( $orderProduct->getId() == $subscription->getOrderProductId() ) { |
|
74
|
|
|
$this->send( $view->set( 'orderProductItem', $orderProduct ), $address, $sites->getLogo()->filter()->last() ); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Sends the subscription e-mail to the customer |
|
82
|
|
|
* |
|
83
|
|
|
* @param \Aimeos\MW\View\Iface $view View object |
|
84
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Address\Iface $address Address item |
|
85
|
|
|
* @param string|null $logoPath Path to the logo |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function send( \Aimeos\MW\View\Iface $view, \Aimeos\MShop\Order\Item\Base\Address\Iface $address, string $logoPath = null ) |
|
88
|
|
|
{ |
|
89
|
|
|
$context = $this->context(); |
|
90
|
|
|
$config = $context->config(); |
|
91
|
|
|
|
|
92
|
|
|
$msg = $this->call( 'mailTo', $address ); |
|
|
|
|
|
|
93
|
|
|
$view->logo = $msg->embed( $this->call( 'mailLogo', $logoPath ), basename( $logoPath ) ); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$msg->subject( $context->translate( 'client', 'Your subscription' ) ) |
|
96
|
|
|
->html( $view->render( $config->get( 'controller/jobs/order/email/subscription/template-html', 'order/email/subscription/html' ) ) ) |
|
97
|
|
|
->text( $view->render( $config->get( 'controller/jobs/order/email/subscription/template-text', 'order/email/subscription/text' ) ) ) |
|
98
|
|
|
->send(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns the view populated with common data |
|
104
|
|
|
* |
|
105
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $base Basket including addresses |
|
106
|
|
|
* @param string|null $theme Theme name |
|
107
|
|
|
* @return \Aimeos\MW\View\Iface View object |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function view( \Aimeos\MShop\Order\Item\Base\Iface $base, string $theme = null ) : \Aimeos\MW\View\Iface |
|
110
|
|
|
{ |
|
111
|
|
|
$address = current( $base->getAddress( 'payment' ) ); |
|
112
|
|
|
$langId = $address->getLanguageId() ?: $base->locale()->getLanguageId(); |
|
113
|
|
|
|
|
114
|
|
|
$view = $this->call( 'mailView', $langId ); |
|
115
|
|
|
$view->intro = $this->call( 'mailIntro', $address ); |
|
116
|
|
|
$view->css = $this->call( 'mailCss', $theme ); |
|
117
|
|
|
$view->urlparams = [ |
|
118
|
|
|
'currency' => $base->getPrice()->getCurrencyId(), |
|
119
|
|
|
'site' => $base->getSiteCode(), |
|
120
|
|
|
'locale' => $langId, |
|
121
|
|
|
]; |
|
122
|
|
|
|
|
123
|
|
|
return $view; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|