Skip to content

Commit d1847bd

Browse files
committed
Merge pull request #343 from magento-ogre/PR_Branch
[Ogre's] Synonym Management, Public PRs and Bugs
2 parents 01141f4 + 08b9b15 commit d1847bd

File tree

67 files changed

+3308
-161
lines changed

Some content is hidden

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

67 files changed

+3308
-161
lines changed

app/code/Magento/Backend/Model/Locale/Manager.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,30 @@ class Manager
2626
* @var \Magento\Framework\TranslateInterface
2727
*/
2828
protected $_translator;
29+
30+
/**
31+
* @var \Magento\Backend\App\ConfigInterface
32+
*/
33+
protected $_backendConfig;
2934

3035
/**
3136
* Constructor
3237
*
3338
* @param \Magento\Backend\Model\Session $session
3439
* @param \Magento\Backend\Model\Auth\Session $authSession
3540
* @param \Magento\Framework\TranslateInterface $translator
41+
* @param \Magento\Backend\App\ConfigInterface $backendConfig
3642
*/
3743
public function __construct(
3844
\Magento\Backend\Model\Session $session,
3945
\Magento\Backend\Model\Auth\Session $authSession,
40-
\Magento\Framework\TranslateInterface $translator
46+
\Magento\Framework\TranslateInterface $translator,
47+
\Magento\Backend\App\ConfigInterface $backendConfig
4148
) {
4249
$this->_session = $session;
4350
$this->_authSession = $authSession;
4451
$this->_translator = $translator;
52+
$this->_backendConfig = $backendConfig;
4553
}
4654

4755
/**
@@ -53,28 +61,40 @@ public function __construct(
5361
public function switchBackendInterfaceLocale($localeCode)
5462
{
5563
$this->_session->setSessionLocale(null);
56-
64+
5765
$this->_authSession->getUser()->setInterfaceLocale($localeCode);
58-
66+
5967
$this->_translator->setLocale($localeCode)->loadData(null, true);
60-
68+
6169
return $this;
6270
}
6371

72+
/**
73+
* Get general interface locale
74+
*
75+
* @return string
76+
*/
77+
public function getGeneralLocale()
78+
{
79+
return $this->_backendConfig->getValue('general/locale/code');
80+
}
81+
6482
/**
6583
* Get user interface locale stored in session data
6684
*
6785
* @return string
6886
*/
6987
public function getUserInterfaceLocale()
7088
{
71-
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;
72-
7389
$userData = $this->_authSession->getUser();
90+
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;
91+
7492
if ($userData && $userData->getInterfaceLocale()) {
7593
$interfaceLocale = $userData->getInterfaceLocale();
94+
} elseif ($this->getGeneralLocale()) {
95+
$interfaceLocale = $this->getGeneralLocale();
7696
}
77-
97+
7898
return $interfaceLocale;
7999
}
80100
}

app/code/Magento/Backend/Test/Unit/Model/Locale/ManagerTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
1515
protected $_model;
1616

1717
/**
18-
* @var \Magento\Framework\TranslateInterface
18+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\TranslateInterface
1919
*/
2020
protected $_translator;
2121

@@ -25,9 +25,14 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
2525
protected $_session;
2626

2727
/**
28-
* @var \Magento\Backend\Model\Auth\Session
28+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Auth\Session
2929
*/
3030
protected $_authSession;
31+
32+
/**
33+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\App\ConfigInterface
34+
*/
35+
protected $_backendConfig;
3136

3237
protected function setUp()
3338
{
@@ -40,7 +45,9 @@ protected function setUp()
4045
'',
4146
false
4247
);
43-
48+
49+
$this->_backendConfig = $this->getMockForAbstractClass('Magento\Backend\App\ConfigInterface', [], '', false);
50+
4451
$userMock = new \Magento\Framework\DataObject();
4552

4653
$this->_authSession->expects($this->any())->method('getUser')->will($this->returnValue($userMock));
@@ -54,7 +61,8 @@ protected function setUp()
5461
$this->_model = new \Magento\Backend\Model\Locale\Manager(
5562
$this->_session,
5663
$this->_authSession,
57-
$this->_translator
64+
$this->_translator,
65+
$this->_backendConfig
5866
);
5967
}
6068

@@ -102,4 +110,17 @@ public function testGetUserInterfaceLocale()
102110

103111
$this->assertEquals($locale, 'de_DE');
104112
}
113+
114+
/**
115+
* @covers \Magento\Backend\Model\Locale\Manager::getUserInterfaceLocale
116+
*/
117+
public function testGetUserInterfaceGeneralLocale()
118+
{
119+
$this->_backendConfig->expects($this->any())
120+
->method('getValue')
121+
->with('general/locale/code')
122+
->willReturn('test_locale');
123+
$locale = $this->_model->getUserInterfaceLocale();
124+
$this->assertEquals($locale, 'test_locale');
125+
}
105126
}

app/code/Magento/Cms/etc/webapi.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<route url="/V1/cmsPage/:pageId" method="GET">
1212
<service class="Magento\Cms\Api\PageRepositoryInterface" method="getById"/>
1313
<resources>
14-
<resource ref="Magento_Cms::page"/>
14+
<resource ref="anonymous"/>
1515
</resources>
1616
</route>
1717
<route url="/V1/cmsPage/search" method="GET">
@@ -42,7 +42,7 @@
4242
<route url="/V1/cmsBlock/:blockId" method="GET">
4343
<service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/>
4444
<resources>
45-
<resource ref="Magento_Cms::block"/>
45+
<resource ref="anonymous"/>
4646
</resources>
4747
</route>
4848
<route url="/V1/cmsBlock/search" method="GET">
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Api\Data;
7+
8+
/**
9+
* @api
10+
*/
11+
interface SynonymGroupInterface
12+
{
13+
/**
14+
* Gets group id
15+
*
16+
* @return int
17+
*/
18+
public function getGroupId();
19+
20+
/**
21+
* Sets group id
22+
*
23+
* @param int $groupId
24+
* @return $this
25+
*/
26+
public function setGroupId($groupId);
27+
28+
/**
29+
* Gets synonym group
30+
*
31+
* @return string
32+
*/
33+
public function getSynonymGroup();
34+
35+
/**
36+
* Sets synonym group
37+
*
38+
* @param string $synonymGroup
39+
* @return $this
40+
*/
41+
public function setSynonymGroup($synonymGroup);
42+
43+
/**
44+
* Gets store id
45+
*
46+
* @return int
47+
*/
48+
public function getStoreId();
49+
50+
/**
51+
* Sets store id
52+
*
53+
* @param int $id
54+
* @return $this
55+
*/
56+
public function setStoreId($id);
57+
58+
/**
59+
* Gets website id
60+
*
61+
* @return int
62+
*/
63+
public function getWebsiteId();
64+
65+
/**
66+
* Sets website id
67+
*
68+
* @param int $id
69+
* @return $this
70+
*/
71+
public function setWebsiteId($id);
72+
}

app/code/Magento/Search/Api/SynonymAnalyzerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface SynonymAnalyzerInterface
1414
/**
1515
* Get synonyms for specified phrase
1616
*
17-
* For phrase: "Elizabeth is the English queen" correct output is an array of arrays containing synonyms for each
17+
* For phrase: "Elizabeth is the English queen" example output is an array of arrays containing synonyms for each
1818
* word in the phrase:
1919
*
2020
* [
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Api;
7+
8+
/**
9+
* @api
10+
*/
11+
interface SynonymGroupRepositoryInterface
12+
{
13+
/**
14+
* Save synonym group data
15+
*
16+
* @param \Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup
17+
* @return \Magento\Search\Api\Data\SynonymGroupInterface saved attribute set
18+
*/
19+
public function save(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup);
20+
21+
/**
22+
* Remove given synonym group data
23+
*
24+
* @param \Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup
25+
* @return bool
26+
*/
27+
public function delete(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup);
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Block\Adminhtml;
7+
8+
9+
/**
10+
* Adminhtml synonym group content block
11+
*/
12+
class Synonyms extends \Magento\Backend\Block\Widget\Grid\Container
13+
{
14+
/**
15+
* @return void
16+
*/
17+
protected function _construct()
18+
{
19+
$this->_blockGroup = 'Magento_Search';
20+
$this->_controller = 'adminhtml_synonyms';
21+
$this->_headerText = __('Search Synonyms');
22+
$this->_addButtonLabel = __('New Synonym Group');
23+
parent::_construct();
24+
}
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Block\Adminhtml\Synonyms\Edit;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
10+
/**
11+
* Class BackButton
12+
*/
13+
class BackButton extends GenericButton implements ButtonProviderInterface
14+
{
15+
/**
16+
* @return array
17+
*/
18+
public function getButtonData()
19+
{
20+
return [
21+
'label' => __('Back'),
22+
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
23+
'class' => 'back',
24+
'sort_order' => 10
25+
];
26+
}
27+
28+
/**
29+
* Get URL for back (reset) button
30+
*
31+
* @return string
32+
*/
33+
public function getBackUrl()
34+
{
35+
return $this->getUrl('*/*/');
36+
}
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Block\Adminhtml\Synonyms\Edit;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
10+
/**
11+
* Class DeleteButton
12+
*/
13+
class DeleteButton extends GenericButton implements ButtonProviderInterface
14+
{
15+
/**
16+
* @return array
17+
*/
18+
public function getButtonData()
19+
{
20+
$data = [];
21+
if ($this->getGroupId()) {
22+
$data = [
23+
'label' => __('Delete Synonym Group'),
24+
'class' => 'delete',
25+
'on_click' => 'deleteConfirm(\''
26+
. __('Are you sure you want to delete this synonym group?')
27+
. '\', \'' . $this->getDeleteUrl() . '\')',
28+
'sort_order' => 20,
29+
];
30+
}
31+
return $data;
32+
}
33+
34+
/**
35+
* @return string
36+
*/
37+
public function getDeleteUrl()
38+
{
39+
return $this->getUrl('*/*/delete', ['group_id' => $this->getGroupId()]);
40+
}
41+
}

0 commit comments

Comments
 (0)