Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 0f1c2f1

Browse files
author
Oleksii Korshenko
authored
2 parents cb93fe5 + ebb15eb commit 0f1c2f1

File tree

10 files changed

+281
-49
lines changed

10 files changed

+281
-49
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier;
8+
9+
use Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Alerts\Price;
10+
use Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Alerts\Stock;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\View\LayoutFactory;
13+
use Magento\Store\Model\ScopeInterface;
14+
use Magento\Ui\Component\Form\Fieldset;
15+
16+
class Alerts extends AbstractModifier
17+
{
18+
const DATA_SCOPE = 'data';
19+
const DATA_SCOPE_STOCK = 'stock';
20+
const DATA_SCOPE_PRICE = 'price';
21+
22+
/**
23+
* @var string
24+
*/
25+
private static $previousGroup = 'related';
26+
27+
/**
28+
* @var int
29+
*/
30+
private static $sortOrder = 110;
31+
32+
/**
33+
* @var ScopeConfigInterface
34+
*/
35+
private $scopeConfig;
36+
37+
/**
38+
* @var LayoutFactory
39+
*/
40+
private $layoutFactory;
41+
42+
/**
43+
* Alerts constructor.
44+
* @param ScopeConfigInterface $scopeConfig
45+
* @param LayoutFactory $layoutFactory
46+
*/
47+
public function __construct(
48+
ScopeConfigInterface $scopeConfig,
49+
LayoutFactory $layoutFactory
50+
) {
51+
$this->scopeConfig = $scopeConfig;
52+
$this->layoutFactory = $layoutFactory;
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
* @since 101.0.0
58+
*/
59+
public function modifyData(array $data)
60+
{
61+
return $data;
62+
}
63+
64+
/**
65+
* {@inheritdoc}
66+
* @since 101.0.0
67+
*/
68+
public function modifyMeta(array $meta)
69+
{
70+
if (!$this->canShowTab()) {
71+
return $meta;
72+
}
73+
74+
$meta = array_replace_recursive(
75+
$meta,
76+
[
77+
'alerts' => [
78+
'arguments' => [
79+
'data' => [
80+
'config' => [
81+
'additionalClasses' => 'admin__fieldset-section',
82+
'label' => __('Product Alerts'),
83+
'collapsible' => true,
84+
'componentType' => Fieldset::NAME,
85+
'dataScope' => static::DATA_SCOPE,
86+
'sortOrder' =>
87+
$this->getNextGroupSortOrder(
88+
$meta,
89+
self::$previousGroup,
90+
self::$sortOrder
91+
),
92+
],
93+
],
94+
],
95+
'children' => [
96+
static::DATA_SCOPE_STOCK => $this->getAlertStockFieldset(),
97+
static::DATA_SCOPE_PRICE => $this->getAlertPriceFieldset()
98+
],
99+
],
100+
]
101+
);
102+
103+
return $meta;
104+
}
105+
106+
/**
107+
* @return bool
108+
*/
109+
private function canShowTab()
110+
{
111+
$alertPriceAllow = $this->scopeConfig->getValue(
112+
'catalog/productalert/allow_price',
113+
ScopeInterface::SCOPE_STORE
114+
);
115+
$alertStockAllow = $this->scopeConfig->getValue(
116+
'catalog/productalert/allow_stock',
117+
ScopeInterface::SCOPE_STORE
118+
);
119+
120+
return ($alertPriceAllow || $alertStockAllow);
121+
}
122+
123+
/**
124+
* Prepares config for the alert stock products fieldset
125+
* @return array
126+
*/
127+
private function getAlertStockFieldset()
128+
{
129+
return [
130+
'arguments' => [
131+
'data' => [
132+
'config' => [
133+
'label' => __('Alert stock'),
134+
'componentType' => 'container',
135+
'component' => 'Magento_Ui/js/form/components/html',
136+
'additionalClasses' => 'admin__fieldset-note',
137+
'content' =>
138+
'<h4>' . __('Alert Stock') . '</h4>' .
139+
$this->layoutFactory->create()->createBlock(
140+
Stock::class
141+
)->toHtml(),
142+
]
143+
]
144+
]
145+
];
146+
}
147+
148+
/**
149+
* Prepares config for the alert price products fieldset
150+
* @return array
151+
*/
152+
private function getAlertPriceFieldset()
153+
{
154+
return [
155+
'arguments' => [
156+
'data' => [
157+
'config' => [
158+
'label' => __('Alert price'),
159+
'componentType' => 'container',
160+
'component' => 'Magento_Ui/js/form/components/html',
161+
'additionalClasses' => 'admin__fieldset-note',
162+
'content' =>
163+
'<h4>' . __('Alert Price') . '</h4>' .
164+
$this->layoutFactory->create()->createBlock(
165+
Price::class
166+
)->toHtml(),
167+
]
168+
]
169+
]
170+
];
171+
}
172+
}

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@
143143
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Attributes</item>
144144
<item name="sortOrder" xsi:type="number">120</item>
145145
</item>
146+
<item name="alerts" xsi:type="array">
147+
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Alerts</item>
148+
<item name="sortOrder" xsi:type="number">130</item>
149+
</item>
146150
<item name="advanced-pricing-tier-price-type" xsi:type="array">
147151
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\TierPrice</item>
148152
<item name="sortOrder" xsi:type="number">150</item>

app/code/Magento/Checkout/view/frontend/web/template/billing-address/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77
<div class="field field-select-billing">
8-
<label class="label"><span data-bind="i18n: 'My billing and shipping address are the same'"></span></label>
8+
<label class="label"><span data-bind="i18n: 'Billing Address'"></span></label>
99
<div class="control" data-bind="if: (addressOptions.length > 1)">
1010
<select class="select" name="billing_address_id" data-bind="
1111
options: addressOptions,

app/code/Magento/Cron/etc/cron_groups.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<schedule_ahead_for>20</schedule_ahead_for>
1212
<schedule_lifetime>15</schedule_lifetime>
1313
<history_cleanup_every>10</history_cleanup_every>
14-
<history_success_lifetime>60</history_success_lifetime>
15-
<history_failure_lifetime>600</history_failure_lifetime>
14+
<history_success_lifetime>10080</history_success_lifetime>
15+
<history_failure_lifetime>10080</history_failure_lifetime>
1616
<use_separate_process>0</use_separate_process>
1717
</group>
1818
</config>

app/code/Magento/Indexer/etc/cron_groups.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<schedule_ahead_for>4</schedule_ahead_for>
1212
<schedule_lifetime>2</schedule_lifetime>
1313
<history_cleanup_every>10</history_cleanup_every>
14-
<history_success_lifetime>60</history_success_lifetime>
15-
<history_failure_lifetime>600</history_failure_lifetime>
14+
<history_success_lifetime>10080</history_success_lifetime>
15+
<history_failure_lifetime>10080</history_failure_lifetime>
1616
<use_separate_process>1</use_separate_process>
1717
</group>
1818
</config>

lib/internal/Magento/Framework/Crontab/CrontabManager.php

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66
namespace Magento\Framework\Crontab;
77

8-
use Magento\Framework\ShellInterface;
9-
use Magento\Framework\Phrase;
8+
use Magento\Framework\App\Filesystem\DirectoryList;
109
use Magento\Framework\Exception\LocalizedException;
1110
use Magento\Framework\Filesystem;
12-
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Phrase;
12+
use Magento\Framework\ShellInterface;
1313

1414
/**
1515
* Manager works with cron tasks
@@ -38,14 +38,38 @@ public function __construct(
3838
$this->filesystem = $filesystem;
3939
}
4040

41+
/**
42+
* @return string
43+
*/
44+
private function getTasksBlockStart()
45+
{
46+
$tasksBlockStart = self::TASKS_BLOCK_START;
47+
if (defined('BP')) {
48+
$tasksBlockStart .= ' ' . md5(BP);
49+
}
50+
return $tasksBlockStart;
51+
}
52+
53+
/**
54+
* @return string
55+
*/
56+
private function getTasksBlockEnd()
57+
{
58+
$tasksBlockEnd = self::TASKS_BLOCK_END;
59+
if (defined('BP')) {
60+
$tasksBlockEnd .= ' ' . md5(BP);
61+
}
62+
return $tasksBlockEnd;
63+
}
64+
4165
/**
4266
* {@inheritdoc}
4367
*/
4468
public function getTasks()
4569
{
4670
$this->checkSupportedOs();
4771
$content = $this->getCrontabContent();
48-
$pattern = '!(' . self::TASKS_BLOCK_START . ')(.*?)(' . self::TASKS_BLOCK_END . ')!s';
72+
$pattern = '!(' . $this->getTasksBlockStart() . ')(.*?)(' . $this->getTasksBlockEnd() . ')!s';
4973

5074
if (preg_match($pattern, $content, $matches)) {
5175
$tasks = trim($matches[2], PHP_EOL);
@@ -61,14 +85,14 @@ public function getTasks()
6185
*/
6286
public function saveTasks(array $tasks)
6387
{
64-
$this->checkSupportedOs();
65-
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
66-
$logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath();
67-
6888
if (!$tasks) {
6989
throw new LocalizedException(new Phrase('List of tasks is empty'));
7090
}
7191

92+
$this->checkSupportedOs();
93+
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
94+
$logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath();
95+
7296
foreach ($tasks as $key => $task) {
7397
if (empty($task['expression'])) {
7498
$tasks[$key]['expression'] = '* * * * *';
@@ -114,11 +138,11 @@ public function removeTasks()
114138
private function generateSection($content, $tasks = [])
115139
{
116140
if ($tasks) {
117-
$content .= self::TASKS_BLOCK_START . PHP_EOL;
141+
$content .= $this->getTasksBlockStart() . PHP_EOL;
118142
foreach ($tasks as $task) {
119-
$content .= $task['expression'] . ' ' . PHP_BINARY . ' '. $task['command'] . PHP_EOL;
143+
$content .= $task['expression'] . ' ' . PHP_BINARY . ' ' . $task['command'] . PHP_EOL;
120144
}
121-
$content .= self::TASKS_BLOCK_END . PHP_EOL;
145+
$content .= $this->getTasksBlockEnd() . PHP_EOL;
122146
}
123147

124148
return $content;
@@ -133,7 +157,8 @@ private function generateSection($content, $tasks = [])
133157
private function cleanMagentoSection($content)
134158
{
135159
$content = preg_replace(
136-
'!' . preg_quote(self::TASKS_BLOCK_START) . '.*?' . preg_quote(self::TASKS_BLOCK_END . PHP_EOL) . '!s',
160+
'!' . preg_quote($this->getTasksBlockStart()) . '.*?'
161+
. preg_quote($this->getTasksBlockEnd() . PHP_EOL) . '!s',
137162
'',
138163
$content
139164
);
@@ -192,7 +217,7 @@ private function checkSupportedOs()
192217
{
193218
if (stripos(PHP_OS, 'WIN') === 0) {
194219
throw new LocalizedException(
195-
new Phrase('Your operation system is not supported to work with this command')
220+
new Phrase('Your operating system is not supported to work with this command')
196221
);
197222
}
198223
}

0 commit comments

Comments
 (0)