Skip to content

Commit 723e114

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-61960' into 2.0-develop-pr6
2 parents bc28861 + 53216d5 commit 723e114

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<div data-role="tabs" id="product-edit-form-tabs"></div> <?php /* @TODO: remove id after elimination of setDestElementId('product-edit-form-tabs') */?>
5454
<?php echo $block->getChildHtml('product-type-tabs') ?>
5555
<input type="hidden" id="product_type_id" value="<?php /* @escapeNotVerified */ echo $block->getProduct()->getTypeId()?>"/>
56-
<input type="hidden" id="attribute_set_id" value="<?php /* @escapeNotVerified */ echo $block->getProduct()->getAttributeSetId()?>"/>
56+
<input type="hidden" id="attribute_set_id" name="set" value="<?php /* @escapeNotVerified */ echo $block->getProduct()->getAttributeSetId()?>"/>
5757
<button type="submit" class="hidden"></button>
5858
<?php if ($block->getUseContainer()): ?>
5959
</form>

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Configurable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ public function afterInitialize(
5151
$attributes = $this->request->getParam('attributes');
5252
if ($product->getTypeId() == ConfigurableProduct::TYPE_CODE && !empty($attributes)) {
5353
$setId = $this->request->getPost('new-variations-attribute-set-id');
54+
55+
if (!$setId) {
56+
$setId = $this->request->getPost('set');
57+
}
5458
$product->setAttributeSetId($setId);
59+
$product->getResource()->getSortedAttributes($setId);
5560
$this->productType->setUsedProductAttributeIds($attributes, $product);
5661

5762
$product->setNewVariationsAttributeSetId($setId);

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Initialization/Helper/Plugin/UpdateConfigurations.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,19 @@ public function afterInitialize(
5151
$configurations = json_decode($this->request->getParam('configurations_serialized'), true);
5252
}
5353
$configurations = $this->variationHandler->duplicateImagesForVariations($configurations);
54+
$productsAttributeSets = [];
55+
5456
foreach ($configurations as $productId => $productData) {
5557
/** @var \Magento\Catalog\Model\Product $product */
5658
$product = $this->productRepository->getById($productId, false, $this->request->getParam('store', 0));
5759
$productData = $this->variationHandler->processMediaGallery($product, $productData);
60+
$productAttributeSetId = $product->getAttributeSetId();
61+
62+
if (!array_key_exists($productAttributeSetId, $productsAttributeSets)) {
63+
$product->getResource()->getSortedAttributes($productAttributeSetId);
64+
$productsAttributeSets[$productAttributeSetId] = 1;
65+
}
66+
5867
$product->addData($productData);
5968
if ($product->hasDataChanges()) {
6069
$product->save();

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/Plugin/ConfigurableTest.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\ConfigurableProduct\Test\Unit\Controller\Adminhtml\Product\Initialization\Helper\Plugin;
77

8+
use Magento\Catalog\Model\ResourceModel\Product;
89
use \Magento\ConfigurableProduct\Controller\Adminhtml\Product\Initialization\Helper\Plugin\Configurable;
910
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProduct;
1011

@@ -43,30 +44,31 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
4344
protected function setUp()
4445
{
4546
$this->productTypeMock = $this->getMock(
46-
'Magento\ConfigurableProduct\Model\Product\Type\Configurable',
47+
\Magento\ConfigurableProduct\Model\Product\Type\Configurable::class,
4748
[],
4849
[],
4950
'',
5051
false
5152
);
5253
$this->variationHandler = $this->getMock(
53-
'Magento\ConfigurableProduct\Model\Product\VariationHandler',
54+
\Magento\ConfigurableProduct\Model\Product\VariationHandler::class,
5455
[],
5556
[],
5657
'',
5758
false
5859
);
59-
$this->requestMock = $this->getMock('\Magento\Framework\App\Request\Http', [], [], '', false);
60+
$this->requestMock = $this->getMock(\Magento\Framework\App\Request\Http::class, [], [], '', false);
6061
$methods = [
6162
'setNewVariationsAttributeSetId',
6263
'setAssociatedProductIds',
6364
'setCanSaveConfigurableAttributes',
6465
'getTypeId',
66+
'getResource',
6567
'__wakeup',
6668
];
67-
$this->productMock = $this->getMock('Magento\Catalog\Model\Product', $methods, [], '', false);
69+
$this->productMock = $this->getMock(\Magento\Catalog\Model\Product::class, $methods, [], '', false);
6870
$this->subjectMock = $this->getMock(
69-
'Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper',
71+
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper::class,
7072
[],
7173
[],
7274
'',
@@ -77,13 +79,16 @@ protected function setUp()
7779

7880
public function testAfterInitializeIfAttributesNotEmptyAndActionNameNotGenerateVariations()
7981
{
82+
$postValue = 'postValue';
83+
$productResourceMock = $this->getProductResource($postValue);
84+
8085
$this->productMock->expects($this->once())->method('getTypeId')->willReturn(ConfigurableProduct::TYPE_CODE);
86+
$this->productMock->expects($this->once())->method('getResource')->willReturn($productResourceMock);
8187
$associatedProductIds = ['key' => 'value'];
8288
$associatedProductIdsSerialized = json_encode($associatedProductIds);
8389
$generatedProductIds = ['key_one' => 'value_one'];
8490
$expectedArray = ['key' => 'value', 'key_one' => 'value_one'];
8591
$attributes = ['key' => 'value'];
86-
$postValue = 'postValue';
8792
$variationsMatrix = ['variationKey' => 'variationValue'];
8893
$variationsMatrixSerialized = json_encode($variationsMatrix);
8994

@@ -125,11 +130,13 @@ public function testAfterInitializeIfAttributesNotEmptyAndActionNameNotGenerateV
125130

126131
public function testAfterInitializeIfAttributesNotEmptyAndActionNameGenerateVariations()
127132
{
133+
$postValue = 'postValue';
134+
$productResourceMock = $this->getProductResource($postValue);
128135
$this->productMock->expects($this->once())->method('getTypeId')->willReturn(ConfigurableProduct::TYPE_CODE);
136+
$this->productMock->expects($this->once())->method('getResource')->willReturn($productResourceMock);
129137
$associatedProductIds = ['key' => 'value'];
130138
$associatedProductIdsSerialized = json_encode($associatedProductIds);
131139
$attributes = ['key' => 'value'];
132-
$postValue = 'postValue';
133140
$valueMap = [
134141
['new-variations-attribute-set-id', null, $postValue],
135142
['associated_product_ids_serialized', '[]', $associatedProductIdsSerialized],
@@ -182,4 +189,21 @@ public function testAfterInitializeForNotConfigurableProduct()
182189
$this->productTypeMock->expects($this->never())->method('generateSimpleProducts');
183190
$this->plugin->afterInitialize($this->subjectMock, $this->productMock);
184191
}
192+
193+
/**
194+
* generate product resource model mock
195+
* @param $postValue
196+
* @return \PHPUnit_Framework_MockObject_MockObject
197+
*/
198+
private function getProductResource($postValue)
199+
{
200+
$productResourceMock = $this->getMockBuilder(Product::class)
201+
->disableOriginalConstructor()
202+
->getMock();
203+
$productResourceMock->expects(self::once())
204+
->method('getSortedAttributes')
205+
->with($postValue);
206+
207+
return $productResourceMock;
208+
}
185209
}

app/code/Magento/ConfigurableProduct/view/adminhtml/templates/product/configurable/affected-attribute-set-selector/js.phtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@
164164
$('[data-role=new-variations-attribute-set-id]').val($('#attribute_set_id').val());
165165
return; // all selected configurable attributes belong to current attribute set
166166
}
167-
if (!$('[data-role=product-variations-matrix] [data-column=entity_id]')
168-
.closest('tr').has('input[name$="[name]"]').length
169-
) {
170-
return; // no new simple products to save from matrix: uniting attribute set is not needed
167+
168+
var regex = /id\/(\d+)(?:\/)?/g;
169+
var existingProductPage = regex.exec(BASE_URL);
170+
if (existingProductPage != null) {
171+
return; // it is not new product page
171172
}
172173

173174
event.stopImmediatePropagation();

0 commit comments

Comments
 (0)