Skip to content

Commit 76475f2

Browse files
committed
Merge branch 'MAGETWO-29307' of https://github.corp.ebay.com/magento-firedrakes/magento2ce into MAGETWO-14674
2 parents fbc8be6 + 32d6138 commit 76475f2

File tree

25 files changed

+1377
-222
lines changed

25 files changed

+1377
-222
lines changed

app/code/Magento/Checkout/Controller/Cart/Index.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,15 @@ public function execute()
8989
}
9090

9191
// Compose array of messages to add
92-
$messages = [];
93-
/** @var \Magento\Framework\Message\MessageInterface $message */
9492
foreach ($this->cart->getQuote()->getMessages() as $message) {
95-
if ($message) {
96-
// Escape HTML entities in quote message to prevent XSS
97-
$message->setText($this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($message->getText()));
98-
$messages[] = $message;
93+
if (!$message) {
94+
continue;
9995
}
96+
if ($message instanceof \Magento\Framework\Phrase) {
97+
$message = $message->__toString();
98+
}
99+
$this->messageManager->addError($message);
100100
}
101-
$this->messageManager->addUniqueMessages($messages);
102101

103102
/**
104103
* if customer enteres shopping cart we should mark quote

app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfo.php

Lines changed: 175 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,76 @@
77

88
use Magento\Customer\Api\AccountManagementInterface;
99
use Magento\Customer\Controller\RegistryConstants;
10-
use Magento\Customer\Model\AccountManagement;
1110
use Magento\Customer\Model\Address\Mapper;
1211
use Magento\Framework\Exception\NoSuchEntityException;
1312
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1413

1514
/**
16-
* Adminhtml customer view personal information sales block
15+
* Adminhtml customer view personal information sales block.
16+
*
1717
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1818
*/
1919
class PersonalInfo extends \Magento\Backend\Block\Template
2020
{
2121
/**
22+
* Interval in minutes that shows how long customer will be marked 'Online'
23+
* since his last activity. Used only if it's impossible to get such setting
24+
* from configuration.
25+
*/
26+
const DEFAULT_ONLINE_MINUTES_INTERVAL = 15;
27+
28+
/**
29+
* Customer
30+
*
2231
* @var \Magento\Customer\Api\Data\CustomerInterface
2332
*/
2433
protected $customer;
2534

2635
/**
36+
* Customer log
37+
*
38+
* @var \Magento\Customer\Model\Log
39+
*/
40+
protected $customerLog;
41+
42+
/**
43+
* Customer logger
44+
*
45+
* @var \Magento\Customer\Model\Logger
46+
*/
47+
protected $customerLogger;
48+
49+
/**
50+
* Account management
51+
*
2752
* @var AccountManagementInterface
2853
*/
2954
protected $accountManagement;
3055

3156
/**
57+
* Customer group repository
58+
*
3259
* @var \Magento\Customer\Api\GroupRepositoryInterface
3360
*/
3461
protected $groupRepository;
3562

3663
/**
64+
* Customer data factory
65+
*
3766
* @var \Magento\Customer\Api\Data\CustomerInterfaceFactory
3867
*/
3968
protected $customerDataFactory;
4069

4170
/**
71+
* Address helper
72+
*
4273
* @var \Magento\Customer\Helper\Address
4374
*/
4475
protected $addressHelper;
4576

4677
/**
78+
* Date time
79+
*
4780
* @var \Magento\Framework\Stdlib\DateTime
4881
*/
4982
protected $dateTime;
@@ -56,11 +89,15 @@ class PersonalInfo extends \Magento\Backend\Block\Template
5689
protected $coreRegistry;
5790

5891
/**
92+
* Address mapper
93+
*
5994
* @var Mapper
6095
*/
6196
protected $addressMapper;
6297

6398
/**
99+
* Data object helper
100+
*
64101
* @var \Magento\Framework\Api\DataObjectHelper
65102
*/
66103
protected $dataObjectHelper;
@@ -75,6 +112,7 @@ class PersonalInfo extends \Magento\Backend\Block\Template
75112
* @param \Magento\Framework\Registry $registry
76113
* @param Mapper $addressMapper
77114
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
115+
* @param \Magento\Customer\Model\Logger $customerLogger
78116
* @param array $data
79117
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
80118
*/
@@ -88,6 +126,7 @@ public function __construct(
88126
\Magento\Framework\Registry $registry,
89127
Mapper $addressMapper,
90128
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
129+
\Magento\Customer\Model\Logger $customerLogger,
91130
array $data = []
92131
) {
93132
$this->coreRegistry = $registry;
@@ -98,10 +137,14 @@ public function __construct(
98137
$this->dateTime = $dateTime;
99138
$this->addressMapper = $addressMapper;
100139
$this->dataObjectHelper = $dataObjectHelper;
140+
$this->customerLogger = $customerLogger;
141+
101142
parent::__construct($context, $data);
102143
}
103144

104145
/**
146+
* Retrieve customer object
147+
*
105148
* @return \Magento\Customer\Api\Data\CustomerInterface
106149
*/
107150
public function getCustomer()
@@ -117,13 +160,31 @@ public function getCustomer()
117160
}
118161

119162
/**
163+
* Retrieve customer id
164+
*
120165
* @return string|null
121166
*/
122167
public function getCustomerId()
123168
{
124169
return $this->coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
125170
}
126171

172+
/**
173+
* Retrieves customer log model
174+
*
175+
* @return \Magento\Customer\Model\Log
176+
*/
177+
protected function getCustomerLog()
178+
{
179+
if (!$this->customerLog) {
180+
$this->customerLog = $this->customerLogger->get(
181+
$this->getCustomer()->getId()
182+
);
183+
}
184+
185+
return $this->customerLog;
186+
}
187+
127188
/**
128189
* Returns customer's created date in the assigned store
129190
*
@@ -146,6 +207,8 @@ public function getStoreCreateDate()
146207
}
147208

148209
/**
210+
* Retrieve store default timezone from configuration
211+
*
149212
* @return string
150213
*/
151214
public function getStoreCreateDateTimezone()
@@ -172,6 +235,8 @@ public function getCreateDate()
172235
}
173236

174237
/**
238+
* Check if account is confirmed
239+
*
175240
* @return \Magento\Framework\Phrase
176241
*/
177242
public function getIsConfirmedStatus()
@@ -189,6 +254,8 @@ public function getIsConfirmedStatus()
189254
}
190255

191256
/**
257+
* Retrieve store
258+
*
192259
* @return null|string
193260
*/
194261
public function getCreatedInStore()
@@ -199,6 +266,8 @@ public function getCreatedInStore()
199266
}
200267

201268
/**
269+
* Retrieve billing address html
270+
*
202271
* @return \Magento\Framework\Phrase|string
203272
*/
204273
public function getBillingAddressHtml()
@@ -221,6 +290,8 @@ public function getBillingAddressHtml()
221290
}
222291

223292
/**
293+
* Retrieve group name
294+
*
224295
* @return string|null
225296
*/
226297
public function getGroupName()
@@ -236,6 +307,8 @@ public function getGroupName()
236307
}
237308

238309
/**
310+
* Retrieve customer group by id
311+
*
239312
* @param int $groupId
240313
* @return \Magento\Customer\Api\Data\GroupInterface|null
241314
*/
@@ -248,4 +321,104 @@ private function getGroup($groupId)
248321
}
249322
return $group;
250323
}
324+
325+
/**
326+
* Returns timezone of the store to which customer assigned.
327+
*
328+
* @return string
329+
*/
330+
public function getStoreLastLoginDateTimezone()
331+
{
332+
return $this->_scopeConfig->getValue(
333+
$this->_localeDate->getDefaultTimezonePath(),
334+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
335+
$this->getCustomer()->getStoreId()
336+
);
337+
}
338+
339+
/**
340+
* Get customer's current status.
341+
*
342+
* Customer considered 'Offline' in the next cases:
343+
*
344+
* - customer has never been logged in;
345+
* - customer clicked 'Log Out' link\button;
346+
* - predefined interval has passed since customer's last activity.
347+
*
348+
* In all other cases customer considered 'Online'.
349+
*
350+
* @return \Magento\Framework\Phrase
351+
*/
352+
public function getCurrentStatus()
353+
{
354+
// Customer has never been logged in.
355+
if (!$this->getCustomerLog()->getLastLoginAt()) {
356+
return __('Offline');
357+
}
358+
359+
// Customer clicked 'Log Out' link\button.
360+
if ($this->getCustomerLog()->getLastLogoutAt() &&
361+
strtotime($this->getCustomerLog()->getLastLogoutAt()) > strtotime($this->getCustomerLog()->getLastLoginAt())
362+
) {
363+
return __('Offline');
364+
}
365+
366+
// Predefined interval has passed since customer's last activity.
367+
$interval = $this->getOnlineMinutesInterval();
368+
369+
if ($this->getCustomerLog()->getLastVisitAt() &&
370+
strtotime($this->dateTime->now()) - strtotime($this->getCustomerLog()->getLastVisitAt()) > $interval * 60
371+
) {
372+
return __('Offline');
373+
}
374+
375+
return __('Online');
376+
}
377+
378+
/**
379+
* Get customer last login date.
380+
*
381+
* @return \Magento\Framework\Phrase|string
382+
*/
383+
public function getLastLoginDate()
384+
{
385+
$date = $this->getCustomerLog()->getLastLoginAt();
386+
387+
if ($date) {
388+
return $this->formatDate($date, TimezoneInterface::FORMAT_TYPE_MEDIUM, true);
389+
}
390+
391+
return __('Never');
392+
}
393+
394+
/**
395+
* Returns customer last login date in store's timezone.
396+
*
397+
* @return \Magento\Framework\Phrase|string
398+
*/
399+
public function getStoreLastLoginDate()
400+
{
401+
$date = strtotime($this->getCustomerLog()->getLastLoginAt());
402+
403+
if ($date) {
404+
$date = $this->_localeDate->scopeDate($this->getCustomer()->getStoreId(), $date, true);
405+
return $this->formatDate($date, TimezoneInterface::FORMAT_TYPE_MEDIUM, true);
406+
}
407+
408+
return __('Never');
409+
}
410+
411+
/**
412+
* Returns interval that shows how long customer will be considered 'Online'.
413+
*
414+
* @return int Interval in minutes
415+
*/
416+
protected function getOnlineMinutesInterval()
417+
{
418+
$configValue = $this->_scopeConfig->getValue(
419+
'customer/online_customers/online_minutes_interval',
420+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
421+
);
422+
return intval($configValue) > 0 ? intval($configValue) : self::DEFAULT_ONLINE_MINUTES_INTERVAL;
423+
}
251424
}

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use Magento\Framework\Exception\State\ExpiredException;
3131
use Magento\Framework\Exception\State\InputMismatchException;
3232
use Magento\Framework\Exception\State\InvalidTransitionException;
33-
use Psr\Log\LoggerInterface as Logger;
33+
use Psr\Log\LoggerInterface as PsrLogger;
3434
use Magento\Framework\Mail\Exception as MailException;
3535
use Magento\Framework\Mail\Template\TransportBuilder;
3636
use Magento\Framework\Math\Random;
@@ -132,7 +132,7 @@ class AccountManagement implements AccountManagementInterface
132132
private $url;
133133

134134
/**
135-
* @var Logger
135+
* @var PsrLogger
136136
*/
137137
protected $logger;
138138

@@ -215,7 +215,7 @@ class AccountManagement implements AccountManagementInterface
215215
* @param CustomerMetadataInterface $customerMetadataService
216216
* @param CustomerRegistry $customerRegistry
217217
* @param \Magento\Framework\Url $url
218-
* @param Logger $logger
218+
* @param PsrLogger $logger
219219
* @param Encryptor $encryptor
220220
* @param ConfigShare $configShare
221221
* @param StringHelper $stringHelper
@@ -243,7 +243,7 @@ public function __construct(
243243
CustomerMetadataInterface $customerMetadataService,
244244
CustomerRegistry $customerRegistry,
245245
\Magento\Framework\Url $url,
246-
Logger $logger,
246+
PsrLogger $logger,
247247
Encryptor $encryptor,
248248
ConfigShare $configShare,
249249
StringHelper $stringHelper,

0 commit comments

Comments
 (0)