Skip to content

Commit e7934e0

Browse files
author
Oleksandr Iegorov
committed
Merge branch 'develop' of https://github.com/magento/magento2ce into MAGETWO-62468-1
2 parents f0246f6 + 02e1c6b commit e7934e0

File tree

135 files changed

+8451
-306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+8451
-306
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Analytics\Block\Adminhtml\System\Config;
7+
8+
use Magento\Analytics\Model\SubscriptionStatusProvider;
9+
use Magento\Backend\Block\Template\Context;
10+
use Magento\Framework\Data\Form\Element\AbstractElement;
11+
12+
/**
13+
* Class SubscriptionStatusLabel.
14+
*
15+
* Provides labels for subscription status
16+
* Status can be reviewed in System Configuration
17+
*/
18+
class SubscriptionStatusLabel extends \Magento\Config\Block\System\Config\Form\Field
19+
{
20+
/**
21+
* @var SubscriptionStatusProvider
22+
*/
23+
private $subscriptionStatusProvider;
24+
25+
/**
26+
* SubscriptionStatusLabel constructor.
27+
*
28+
* @param Context $context
29+
* @param SubscriptionStatusProvider $labelStatusProvider
30+
* @param array $data
31+
*/
32+
public function __construct(
33+
Context $context,
34+
SubscriptionStatusProvider $labelStatusProvider,
35+
array $data = []
36+
) {
37+
parent::__construct($context, $data);
38+
$this->subscriptionStatusProvider = $labelStatusProvider;
39+
}
40+
41+
/**
42+
* Unset some non-related element parameters
43+
*
44+
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
45+
* @return string
46+
*/
47+
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
48+
{
49+
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
50+
$element->setData(
51+
'value',
52+
$this->prepareLabelValue()
53+
);
54+
return parent::render($element);
55+
}
56+
57+
/**
58+
* Prepare label for subscription status
59+
*
60+
* @return string
61+
*/
62+
private function prepareLabelValue()
63+
{
64+
return __('Subscription status') . ': ' . __($this->subscriptionStatusProvider->getStatus());
65+
}
66+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Analytics\Controller\Adminhtml\Subscription;
8+
9+
use Magento\Analytics\Model\NotificationTime;
10+
use Magento\Analytics\Model\Subscription;
11+
use Magento\Backend\App\Action;
12+
use Magento\Backend\App\Action\Context;
13+
use Magento\Framework\Controller\Result\Json;
14+
use Magento\Framework\Controller\ResultFactory;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Psr\Log\LoggerInterface;
17+
18+
/**
19+
* Class Activate
20+
*
21+
* Activates subscription with Free Tier program
22+
*/
23+
class Activate extends Action
24+
{
25+
/**
26+
* Resource for managing subscription to Magento Analytics.
27+
*
28+
* @var Subscription
29+
*/
30+
private $subscription;
31+
32+
/**
33+
* @var LoggerInterface
34+
*/
35+
private $logger;
36+
37+
/**
38+
* Resource for managing last notification time about subscription to Magento Analytics.
39+
*
40+
* @var NotificationTime
41+
*/
42+
private $notificationTime;
43+
44+
/**
45+
* Agreement on subscription value into request.
46+
*
47+
* @var string
48+
*/
49+
private $subscriptionApprovedField = 'analytics_subscription_checkbox';
50+
51+
/**
52+
* Activate constructor.
53+
*
54+
* @param Context $context
55+
* @param Subscription $subscription
56+
* @param LoggerInterface $logger
57+
* @param NotificationTime $notificationTime
58+
*/
59+
public function __construct(
60+
Context $context,
61+
Subscription $subscription,
62+
LoggerInterface $logger,
63+
NotificationTime $notificationTime
64+
) {
65+
$this->subscription = $subscription;
66+
$this->logger = $logger;
67+
$this->notificationTime = $notificationTime;
68+
parent::__construct($context);
69+
}
70+
71+
/**
72+
* Check admin permissions for this controller
73+
*
74+
* @return boolean
75+
*/
76+
protected function _isAllowed()
77+
{
78+
return $this->_authorization->isAllowed('Magento_Analytics::analytics_settings');
79+
}
80+
81+
/**
82+
* Activate subscription to Magento Analytics via AJAX.
83+
*
84+
* @return Json
85+
*/
86+
public function execute()
87+
{
88+
try {
89+
if ($this->getRequest()->getParam($this->subscriptionApprovedField)) {
90+
$this->subscription->enable();
91+
} else {
92+
$this->notificationTime->unsetLastTimeNotificationValue();
93+
}
94+
$responseContent = [
95+
'success' => true,
96+
'error_message' => '',
97+
];
98+
} catch (LocalizedException $e) {
99+
$responseContent = [
100+
'success' => false,
101+
'error_message' => $e->getMessage(),
102+
];
103+
$this->logger->error($e->getMessage());
104+
} catch (\Exception $e) {
105+
$responseContent = [
106+
'success' => false,
107+
'error_message' => __(
108+
'Sorry, there was an error processing your registration request to Magento Analytics. '
109+
. 'Please try again later.'
110+
),
111+
];
112+
$this->logger->error($e->getMessage());
113+
}
114+
/** @var Json $resultJson */
115+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
116+
return $resultJson->setData($responseContent);
117+
}
118+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Analytics\Controller\Adminhtml\Subscription;
8+
9+
use Magento\Analytics\Model\NotificationTime;
10+
use Magento\Backend\App\Action;
11+
use Magento\Backend\App\Action\Context;
12+
use Magento\Framework\Intl\DateTimeFactory;
13+
use Magento\Framework\Controller\Result\Json;
14+
use Magento\Framework\Controller\ResultFactory;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Psr\Log\LoggerInterface;
17+
18+
/**
19+
* Class Postpone
20+
*
21+
* Postpones notification about Free Tier program
22+
*/
23+
class Postpone extends Action
24+
{
25+
/**
26+
* @var DateTimeFactory
27+
*/
28+
private $dateTimeFactory;
29+
30+
/**
31+
* @var NotificationTime
32+
*/
33+
private $notificationTime;
34+
35+
/**
36+
* @var LoggerInterface
37+
*/
38+
private $logger;
39+
40+
/**
41+
* Postpone constructor.
42+
*
43+
* @param Context $context
44+
* @param DateTimeFactory $dateTimeFactory
45+
* @param NotificationTime $notificationTime
46+
* @param LoggerInterface $logger
47+
*/
48+
public function __construct(
49+
Context $context,
50+
DateTimeFactory $dateTimeFactory,
51+
NotificationTime $notificationTime,
52+
LoggerInterface $logger
53+
) {
54+
$this->dateTimeFactory = $dateTimeFactory;
55+
$this->notificationTime = $notificationTime;
56+
$this->logger = $logger;
57+
parent::__construct($context);
58+
59+
}
60+
61+
/**
62+
* Check admin permissions for this controller
63+
*
64+
* @return boolean
65+
*/
66+
protected function _isAllowed()
67+
{
68+
return $this->_authorization->isAllowed('Magento_Analytics::analytics_settings');
69+
}
70+
71+
/**
72+
* Postpones notification about subscription
73+
*
74+
* @return Json
75+
*/
76+
public function execute()
77+
{
78+
try {
79+
$dateTime = $this->dateTimeFactory->create();
80+
$responseContent = [
81+
'success' => $this->notificationTime->storeLastTimeNotification($dateTime->getTimestamp()),
82+
'error_message' => ''
83+
];
84+
} catch (LocalizedException $e) {
85+
$this->logger->error($e->getMessage());
86+
$responseContent = [
87+
'success' => false,
88+
'error_message' => $e->getMessage()
89+
];
90+
} catch (\Exception $e) {
91+
$this->logger->error($e->getMessage());
92+
$responseContent = [
93+
'success' => false,
94+
'error_message' => __('Error occurred during postponement notification')
95+
];
96+
}
97+
/** @var Json $resultJson */
98+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
99+
return $resultJson->setData($responseContent);
100+
}
101+
}

0 commit comments

Comments
 (0)