Skip to content

Commit d95ad45

Browse files
author
Olga Nakonechna
committed
MAGETWO-52974: CLONE - Configurable product options not saved when editing
- Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-52974
2 parents cd813e4 + 2264ea7 commit d95ad45

File tree

12 files changed

+173
-30
lines changed

12 files changed

+173
-30
lines changed

app/code/Magento/Backend/Block/Store/Switcher.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
/**
1010
* Store switcher block
11-
*
12-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1311
*/
1412
class Switcher extends \Magento\Backend\Block\Template
1513
{
@@ -152,11 +150,7 @@ public function getWebsites()
152150
{
153151
$websites = $this->_storeManager->getWebsites();
154152
if ($websiteIds = $this->getWebsiteIds()) {
155-
foreach (array_keys($websites) as $websiteId) {
156-
if (!in_array($websiteId, $websiteIds)) {
157-
unset($websites[$websiteId]);
158-
}
159-
}
153+
$websites = array_intersect_key($websites, array_flip($websiteIds));
160154
}
161155
return $websites;
162156
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Block\Store;
8+
9+
class SwitcherTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\Backend\Block\Store\Switcher
13+
*/
14+
private $switcherBlock;
15+
16+
private $storeManagerMock;
17+
18+
protected function setUp()
19+
{
20+
$this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
21+
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
22+
$context = $objectHelper->getObject(
23+
\Magento\Backend\Block\Template\Context::class,
24+
[
25+
'storeManager' => $this->storeManagerMock,
26+
]
27+
);
28+
29+
$this->switcherBlock = $objectHelper->getObject(
30+
\Magento\Backend\Block\Store\Switcher::class,
31+
['context' => $context]
32+
);
33+
}
34+
35+
public function testGetWebsites()
36+
{
37+
$websiteMock = $this->getMock(\Magento\Store\Model\Website::class, [], [], '', false);
38+
$websites = [0 => $websiteMock, 1 => $websiteMock];
39+
$this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
40+
$this->assertEquals($websites, $this->switcherBlock->getWebsites());
41+
}
42+
43+
public function testGetWebsitesIfSetWebsiteIds()
44+
{
45+
$websiteMock = $this->getMock(\Magento\Store\Model\Website::class, [], [], '', false);
46+
$websites = [0 => $websiteMock, 1 => $websiteMock];
47+
$this->storeManagerMock->expects($this->once())->method('getWebsites')->will($this->returnValue($websites));
48+
49+
$this->switcherBlock->setWebsiteIds([1]);
50+
$expected = [1 => $websiteMock];
51+
$this->assertEquals($expected, $this->switcherBlock->getWebsites());
52+
}
53+
}

app/code/Magento/Catalog/view/frontend/templates/product/view/form.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
'jquery',
4343
'priceBox'
4444
], function($){
45-
var priceBoxes = $('[data-role=priceBox]');
45+
var dataPriceBoxSelector = '[data-role=priceBox]',
46+
dataProductIdSelector = '[data-product-id=<?php echo $block->escapeHtml($_product->getId())?>]',
47+
priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector);
4648

4749
priceBoxes = priceBoxes.filter(function(index, elem){
4850
return !$(elem).find('.price-from').length;

app/code/Magento/Catalog/view/frontend/templates/product/view/options.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
?>
1111

1212
<?php $_options = $block->decorateArray($block->getOptions()) ?>
13+
<?php $_productId = $block->getProduct()->getId() ?>
1314
<?php if (count($_options)):?>
1415
<script type="text/x-magento-init">
1516
{
1617
"#product_addtocart_form": {
1718
"priceOptions": {
1819
"optionConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig()?>,
1920
"controlContainer": ".field",
20-
"priceHolderSelector": "[data-role=priceBox]"
21+
"priceHolderSelector": "[data-product-id='<?php echo $block->escapeHtml($_productId)?>'][data-role=priceBox]"
2122
}
2223
}
2324
}

app/code/Magento/Sales/view/frontend/templates/order/history.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
<span><?php /* @escapeNotVerified */ echo __('View Order') ?></span>
4343
</a>
4444
<?php if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?>
45-
<a href="<?php /* @escapeNotVerified */ echo $block->getReorderUrl($_order) ?>" class="action order">
45+
<a href="#" data-post='<?php /* @escapeNotVerified */ echo
46+
$this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
47+
->getPostData($block->getReorderUrl($_order))
48+
?>' class="action order">
4649
<span><?php /* @escapeNotVerified */ echo __('Reorder') ?></span>
4750
</a>
4851
<?php endif ?>

app/code/Magento/Sales/view/frontend/templates/order/info/buttons.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
<div class="actions">
1111
<?php $_order = $block->getOrder() ?>
1212
<?php if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?>
13-
<a class="action reorder" href="<?php /* @escapeNotVerified */ echo $block->getReorderUrl($_order) ?>">
13+
<a href="#" data-post='<?php /* @escapeNotVerified */ echo
14+
$this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
15+
->getPostData($block->getReorderUrl($_order))
16+
?>' class="action order">
1417
<span><?php /* @escapeNotVerified */ echo __('Reorder') ?></span>
1518
</a>
1619
<?php endif ?>

app/code/Magento/Sales/view/frontend/templates/order/recent.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
<span><?php /* @escapeNotVerified */ echo __('View Order') ?></span>
4747
</a>
4848
<?php if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?>
49-
<a href="<?php /* @escapeNotVerified */ echo $block->getReorderUrl($_order) ?>" class="action order">
49+
<a href="#" data-post='<?php /* @escapeNotVerified */ echo
50+
$this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
51+
->getPostData($block->getReorderUrl($_order))
52+
?>' class="action order">
5053
<span><?php /* @escapeNotVerified */ echo __('Reorder') ?></span>
5154
</a>
5255
<?php endif ?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<head>
10+
<css src="Magento_Swatches::css/swatches.css"/>
11+
</head>
12+
<body>
13+
<referenceBlock name="category.product.type.details.renderers">
14+
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" />
15+
</referenceBlock>
16+
</body>
17+
</page>

lib/internal/Magento/Framework/Module/Dir/Reader.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class Reader
4646
*/
4747
protected $readFactory;
4848

49+
/**
50+
* Found configuration files grouped by configuration types (filename).
51+
*
52+
* @var array
53+
*/
54+
private $fileIterators = [];
55+
4956
/**
5057
* @param Dir $moduleDirs
5158
* @param ModuleListInterface $moduleList
@@ -65,24 +72,42 @@ public function __construct(
6572
}
6673

6774
/**
68-
* Go through all modules and find configuration files of active modules
75+
* Go through all modules and find configuration files of active modules.
6976
*
7077
* @param string $filename
7178
* @return FileIterator
7279
*/
7380
public function getConfigurationFiles($filename)
7481
{
75-
return $this->fileIteratorFactory->create($this->getFiles($filename, Dir::MODULE_ETC_DIR));
82+
return $this->getFilesIterator($filename, Dir::MODULE_ETC_DIR);
7683
}
7784

7885
/**
79-
* Go through all modules and find composer.json files of active modules
86+
* Go through all modules and find composer.json files of active modules.
8087
*
8188
* @return FileIterator
8289
*/
8390
public function getComposerJsonFiles()
8491
{
85-
return $this->fileIteratorFactory->create($this->getFiles('composer.json'));
92+
return $this->getFilesIterator('composer.json');
93+
}
94+
95+
/**
96+
* Retrieve iterator for files with $filename from components located in component $subDir.
97+
*
98+
* @param string $filename
99+
* @param string $subDir
100+
*
101+
* @return FileIterator
102+
*/
103+
private function getFilesIterator($filename, $subDir = '')
104+
{
105+
if (!isset($this->fileIterators[$subDir][$filename])) {
106+
$this->fileIterators[$subDir][$filename] = $this->fileIteratorFactory->create(
107+
$this->getFiles($filename, $subDir)
108+
);
109+
}
110+
return $this->fileIterators[$subDir][$filename];
86111
}
87112

88113
/**
@@ -96,9 +121,9 @@ private function getFiles($filename, $subDir = '')
96121
{
97122
$result = [];
98123
foreach ($this->modulesList->getNames() as $moduleName) {
99-
$moduleEtcDir = $this->getModuleDir($subDir, $moduleName);
100-
$file = $moduleEtcDir . '/' . $filename;
101-
$directoryRead = $this->readFactory->create($moduleEtcDir);
124+
$moduleSubDir = $this->getModuleDir($subDir, $moduleName);
125+
$file = $moduleSubDir . '/' . $filename;
126+
$directoryRead = $this->readFactory->create($moduleSubDir);
102127
$path = $directoryRead->getRelativePath($file);
103128
if ($directoryRead->isExist($path)) {
104129
$result[] = $file;
@@ -159,5 +184,6 @@ public function getModuleDir($type, $moduleName)
159184
public function setModuleDir($moduleName, $type, $path)
160185
{
161186
$this->customModuleDirs[$moduleName][$type] = $path;
187+
$this->fileIterators = [];
162188
}
163189
}

lib/web/tiny_mce/plugins/advimage/js/image.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ var ImageDialog = {
184184
tinyMCEPopup.editor.execCommand('mceRepaint');
185185
tinyMCEPopup.editor.focus();
186186
tinyMCEPopup.close();
187+
ed.onChange.dispatch(ed);
187188
},
188189

189190
getAttrib : function(e, at) {

0 commit comments

Comments
 (0)