-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStartController.php
More file actions
63 lines (53 loc) · 2.03 KB
/
StartController.php
File metadata and controls
63 lines (53 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Copyright © . All rights reserved.
* See LICENSE file for license details.
*/
declare(strict_types=1);
namespace OxidEsales\ExamplesModule\Extension\Controller;
use OxidEsales\Eshop\Application\Model\User as EshopModelUser;
use OxidEsales\ExamplesModule\Greeting\Service\GreetingMessageServiceInterface;
use OxidEsales\ExamplesModule\Greeting\Settings\GreetingSettingsInterface;
/**
* @eshopExtension
*
* This is an example for a module extension (chain extend) of
* the shop start controller.
* NOTE: class must not be final.
*
* @mixin \OxidEsales\Eshop\Application\Controller\StartController
*
* @todo: extract methods to domain
*/
class StartController extends StartController_parent
{
/**
* All we need here is to fetch the information we need from a service.
* As in our example we extend a block of a template belonging ONLY
* to the shop's StartController, we extend that Controller with a new method.
* NOTE: only leaf classes can be extended this way. The FrontendController class which
* many Controllers inherit from cannot be extended this way.
*/
public function getOeemGeneralGreeting(): string
{
$service = $this->getService(GreetingMessageServiceInterface::class);
return $service->getGeneralGreeting();
}
public function showOeemGeneralGreeting(): bool
{
return strtolower((string)getenv('SHOW_GENERAL_GREETING')) !== 'false';
}
public function getOeemGreeting(): string
{
$service = $this->getService(GreetingMessageServiceInterface::class);
/** @phpstan-ignore-next-line */
$user = is_a($this->getUser(), EshopModelUser::class) ? $this->getUser() : null;
return $service->getGreeting($user);
}
public function canUpdateOeemGreeting(): bool
{
$greetingSettings = $this->getService(GreetingSettingsInterface::class);
/** @phpstan-ignore-next-line */
return is_a($this->getUser(), EshopModelUser::class) && $greetingSettings->isPersonalGreetingMode();
}
}