Passed
Push — master ( 838667...7834b3 )
by Aimeos
06:31 queued 03:26
created

Standard::view()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 1
nop 2
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
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'] );
0 ignored issues
show
Bug introduced by
It seems like $subscription->getOrderBaseId() can also be of type null; however, parameter $id of Aimeos\MShop\Common\Manager\Iface::get() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
		$base = $manager->get( /** @scrutinizer ignore-type */ $subscription->getOrderBaseId(), ['order/base/address', 'order/base/product'] );
Loading history...
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 );
0 ignored issues
show
Bug introduced by
The method call() does not exist on Aimeos\Controller\Common...rocessor\Email\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
		/** @scrutinizer ignore-call */ 
93
  $msg = $this->call( 'mailTo', $address );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
93
		$view->logo = $msg->embed( $this->call( 'mailLogo', $logoPath ), basename( $logoPath ) );
0 ignored issues
show
Bug introduced by
It seems like $logoPath can also be of type null; however, parameter $path of basename() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
		$view->logo = $msg->embed( $this->call( 'mailLogo', $logoPath ), basename( /** @scrutinizer ignore-type */ $logoPath ) );
Loading history...
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