Skip to content

Commit 04257ce

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'origin/develop' into PR
2 parents eb49283 + b3f5588 commit 04257ce

File tree

106 files changed

+4555
-918
lines changed

Some content is hidden

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

106 files changed

+4555
-918
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/Bundle/Model/Product/CopyConstructor/Bundle.php

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,30 @@
55
*/
66
namespace Magento\Bundle\Model\Product\CopyConstructor;
77

8+
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\Product\Type;
10+
811
class Bundle implements \Magento\Catalog\Model\Product\CopyConstructorInterface
912
{
1013
/**
1114
* Duplicating bundle options and selections
1215
*
13-
* @param \Magento\Catalog\Model\Product $product
14-
* @param \Magento\Catalog\Model\Product $duplicate
16+
* @param Product $product
17+
* @param Product $duplicate
1518
* @return void
1619
*/
17-
public function build(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $duplicate)
20+
public function build(Product $product, Product $duplicate)
1821
{
19-
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
22+
if ($product->getTypeId() != Type::TYPE_BUNDLE) {
2023
//do nothing if not bundle
2124
return;
2225
}
2326

24-
$product->getTypeInstance()->setStoreFilter($product->getStoreId(), $product);
25-
$optionCollection = $product->getTypeInstance()->getOptionsCollection($product);
26-
$selectionCollection = $product->getTypeInstance()->getSelectionsCollection(
27-
$product->getTypeInstance()->getOptionsIds($product),
28-
$product
29-
);
30-
$optionCollection->appendSelections($selectionCollection);
31-
32-
$optionRawData = [];
33-
$selectionRawData = [];
34-
35-
$i = 0;
36-
foreach ($optionCollection as $option) {
37-
$optionRawData[$i] = [
38-
'required' => $option->getData('required'),
39-
'position' => $option->getData('position'),
40-
'type' => $option->getData('type'),
41-
'title' => $option->getData('title') ? $option->getData('title') : $option->getData('default_title'),
42-
'delete' => '',
43-
];
44-
foreach ($option->getSelections() as $selection) {
45-
$selectionRawData[$i][] = [
46-
'product_id' => $selection->getProductId(),
47-
'position' => $selection->getPosition(),
48-
'is_default' => $selection->getIsDefault(),
49-
'selection_price_type' => $selection->getSelectionPriceType(),
50-
'selection_price_value' => $selection->getSelectionPriceValue(),
51-
'selection_qty' => $selection->getSelectionQty(),
52-
'selection_can_change_qty' => $selection->getSelectionCanChangeQty(),
53-
'delete' => '',
54-
];
55-
}
56-
$i++;
27+
$bundleOptions = $product->getExtensionAttributes()->getBundleProductOptions();
28+
$duplicatedBundleOptions = [];
29+
foreach ($bundleOptions as $key => $bundleOption) {
30+
$duplicatedBundleOptions[$key] = clone $bundleOption;
5731
}
58-
59-
$duplicate->setBundleOptionsData($optionRawData);
60-
$duplicate->setBundleSelectionsData($selectionRawData);
32+
$duplicate->getExtensionAttributes()->setBundleProductOptions($duplicatedBundleOptions);
6133
}
6234
}

0 commit comments

Comments
 (0)