Skip to content

Commit c743dec

Browse files
Slabko,Michael(mslabko)Slabko,Michael(mslabko)
Slabko,Michael(mslabko)
authored and
Slabko,Michael(mslabko)
committed
Merge pull request #98 from magento-goinc/prepared-pull-request
[GoInc] bugsfixing
2 parents abb8d3b + 92513dc commit c743dec

File tree

6 files changed

+171
-133
lines changed

6 files changed

+171
-133
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,21 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
119119
$optionId = $connection->fetchOne($statement);
120120

121121
if ($optionId) {
122-
if ($object->getStoreId() == '0') {
123-
$data = $this->_prepareDataForTable(
124-
new \Magento\Framework\DataObject(
125-
['price' => $object->getPrice(), 'price_type' => $object->getPriceType()]
126-
),
127-
$priceTable
128-
);
122+
$data = $this->_prepareDataForTable(
123+
new \Magento\Framework\DataObject(
124+
['price' => $object->getPrice(), 'price_type' => $object->getPriceType()]
125+
),
126+
$priceTable
127+
);
129128

130-
$connection->update(
131-
$priceTable,
132-
$data,
133-
[
134-
'option_id = ?' => $object->getId(),
135-
'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
136-
]
137-
);
138-
}
129+
$connection->update(
130+
$priceTable,
131+
$data,
132+
[
133+
'option_id = ?' => $object->getId(),
134+
'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
135+
]
136+
);
139137
} else {
140138
$data = $this->_prepareDataForTable(
141139
new \Magento\Framework\DataObject(

app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/Bulk.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ class Bulk extends \Magento\Ui\Block\Component\StepsWizard\StepAbstract
1212
/** @var \Magento\Catalog\Helper\Image */
1313
protected $image;
1414

15+
/**
16+
* @var \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes
17+
*/
18+
protected $variationMediaAttributes;
19+
1520
/**
1621
* @param \Magento\Framework\View\Element\Template\Context $context
1722
* @param \Magento\Catalog\Helper\Image $image
23+
* @param \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes $variationMediaAttributes
1824
*/
1925
public function __construct(
2026
\Magento\Framework\View\Element\Template\Context $context,
21-
\Magento\Catalog\Helper\Image $image
27+
\Magento\Catalog\Helper\Image $image,
28+
\Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes $variationMediaAttributes
2229
) {
2330
parent::__construct($context);
2431
$this->image = $image;
32+
$this->variationMediaAttributes = $variationMediaAttributes;
2533
}
2634

2735
/**
@@ -39,4 +47,31 @@ public function getNoImageUrl()
3947
{
4048
return $this->image->getDefaultPlaceholderUrl('thumbnail');
4149
}
50+
51+
/**
52+
* Get image types data
53+
*
54+
* @return array
55+
*/
56+
public function getImageTypes()
57+
{
58+
$imageTypes = [];
59+
foreach ($this->variationMediaAttributes->getMediaAttributes() as $attribute) {
60+
/* @var $attribute \Magento\Eav\Model\Entity\Attribute */
61+
$imageTypes[$attribute->getAttributeCode()] = [
62+
'code' => $attribute->getAttributeCode(),
63+
'value' => '',
64+
'name' => '',
65+
];
66+
}
67+
return $imageTypes;
68+
}
69+
70+
/**
71+
* @return array
72+
*/
73+
public function getMediaAttributes()
74+
{
75+
return $this->variationMediaAttributes->getMediaAttributes();
76+
}
4277
}

app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,36 @@ class VariationHandler
3232
/** @var \Magento\CatalogInventory\Api\StockConfigurationInterface */
3333
protected $stockConfiguration;
3434

35+
/**
36+
* @var \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes
37+
*/
38+
protected $variationMediaAttributes;
39+
3540
/**
3641
* @param Type\Configurable $configurableProduct
3742
* @param \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory
3843
* @param \Magento\Eav\Model\EntityFactory $entityFactory
3944
* @param \Magento\Catalog\Model\ProductFactory $productFactory
4045
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
4146
* @param \Magento\Catalog\Model\Product\Attribute\Backend\Media $media
47+
* @param VariationMediaAttributes $variationMediaAttributes
4248
*/
4349
public function __construct(
4450
Type\Configurable $configurableProduct,
4551
\Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory,
4652
\Magento\Eav\Model\EntityFactory $entityFactory,
4753
\Magento\Catalog\Model\ProductFactory $productFactory,
4854
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
49-
\Magento\Catalog\Model\Product\Attribute\Backend\Media $media
55+
\Magento\Catalog\Model\Product\Attribute\Backend\Media $media,
56+
\Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes $variationMediaAttributes
5057
) {
5158
$this->configurableProduct = $configurableProduct;
5259
$this->attributeSetFactory = $attributeSetFactory;
5360
$this->entityFactory = $entityFactory;
5461
$this->productFactory = $productFactory;
5562
$this->stockConfiguration = $stockConfiguration;
5663
$this->media = $media;
64+
$this->variationMediaAttributes = $variationMediaAttributes;
5765
}
5866

5967
/**
@@ -209,11 +217,11 @@ public function duplicateImagesForVariations($productsData)
209217
$variationId = $image['variation_id'];
210218
$newFile = $this->media->duplicateImageFromTmp($file);
211219
$productsData[$variationId]['media_gallery']['images'][$imageId]['file'] = $newFile;
212-
foreach (['small_image', 'thumbnail', 'image'] as $imageType) {
213-
if (isset($productsData[$variationId][$imageType])
214-
&& $productsData[$variationId][$imageType] == $file
220+
foreach ($this->variationMediaAttributes->getMediaAttributes() as $attribute) {
221+
if (isset($productsData[$variationId][$attribute->getAttributeCode()])
222+
&& $productsData[$variationId][$attribute->getAttributeCode()] == $file
215223
) {
216-
$productsData[$variationId][$imageType] = $newFile;
224+
$productsData[$variationId][$attribute->getAttributeCode()] = $newFile;
217225
}
218226
}
219227
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Model\Product;
8+
9+
/**
10+
* Class VariationMediaAttributes. Return media attributes allowed for variations
11+
*/
12+
class VariationMediaAttributes
13+
{
14+
/**
15+
* @var \Magento\Catalog\Model\ProductFactory
16+
*/
17+
protected $productFactory;
18+
19+
/**
20+
* @var array
21+
*/
22+
protected $mediaAttributes;
23+
24+
/**
25+
* @param \Magento\Catalog\Model\ProductFactory $productFactory
26+
*/
27+
public function __construct(\Magento\Catalog\Model\ProductFactory $productFactory)
28+
{
29+
$this->productFactory = $productFactory;
30+
}
31+
32+
/**
33+
* Get media attributes for Configurable variation
34+
*
35+
* @return array
36+
*/
37+
public function getMediaAttributes()
38+
{
39+
if (null === $this->mediaAttributes) {
40+
$this->mediaAttributes = $this->getProduct()->getMediaAttributes();
41+
}
42+
return $this->mediaAttributes;
43+
}
44+
45+
/**
46+
* Get product container for Simple product
47+
*
48+
* @return \Magento\Catalog\Model\Product
49+
*/
50+
private function getProduct()
51+
{
52+
return $this->productFactory->create()->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE);
53+
}
54+
}

app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/bulk.phtml

Lines changed: 53 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@
6363
</ul>
6464

6565
<div data-role="step-gallery-single" class="attribute-image-selector" data-bind="visible: type() == 'single'">
66-
<div data-role="gallery" class="gallery" data-images="[]">
66+
<div data-role="gallery"
67+
class="gallery"
68+
data-images="[]"
69+
data-types="<?php /* @noEscape */ echo $block->escapeHtml(
70+
$this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getImageTypes())
71+
) ?>"
72+
>
6773
<div class="image image-placeholder">
6874
<div data-role="uploader" class="uploader">
6975
<div class="image-browse">
@@ -79,19 +85,6 @@
7985
<p class="image-placeholder-text"><?= /* @escapeNotVerified */ __('Browse to find or drag image here') ?></p>
8086
</div>
8187

82-
<input name="product[image]"
83-
class="image-image"
84-
type="hidden"
85-
value="" />
86-
<input name="product[small_image]"
87-
class="image-small_image"
88-
type="hidden"
89-
value="" />
90-
<input name="product[thumbnail]"
91-
class="image-thumbnail"
92-
type="hidden"
93-
value="" />
94-
9588
<script data-template="uploader" type="text/x-magento-template">
9689
<div id="<%- data.id %>" class="file-row">
9790
<span class="file-info"><%- data.name %> (<%- data.size %>)</span>
@@ -185,30 +178,25 @@
185178
</label>
186179
<div class="control">
187180
<ul class="multiselect-alt">
188-
<li class="item">
189-
<label>
190-
<input class="image-type"
191-
data-role="type-selector"
192-
type="checkbox"
193-
value="image"
194-
/><?= /* @escapeNotVerified */ __('Base Image') ?></label>
195-
</li>
196-
<li class="item">
197-
<label>
198-
<input class="image-type"
199-
data-role="type-selector"
200-
type="checkbox"
201-
value="small_image"
202-
/><?= /* @escapeNotVerified */ __('Small Image') ?></label>
203-
</li>
204-
<li class="item">
205-
<label>
206-
<input class="image-type"
207-
data-role="type-selector"
208-
type="checkbox"
209-
value="thumbnail"
210-
/><?= /* @escapeNotVerified */ __('Thumbnail') ?></label>
211-
</li>
181+
<?php
182+
foreach ($block->getMediaAttributes() as $attribute) : ?>
183+
<li class="item">
184+
<label>
185+
<input class="image-type"
186+
data-role="type-selector"
187+
type="checkbox"
188+
value="<?php /* @noEscape */ echo $block->escapeHtml(
189+
$attribute->getAttributeCode()
190+
) ?>"
191+
/>
192+
<?php /* @noEscape */ echo $block->escapeHtml(
193+
$attribute->getFrontendLabel()
194+
) ?>
195+
</label>
196+
</li>
197+
<?php
198+
endforeach;
199+
?>
212200
</ul>
213201
</div>
214202
</div>
@@ -258,7 +246,13 @@
258246
<span data-bind="text:label"></span>
259247
</label>
260248

261-
<div data-role="gallery" class="gallery" data-images="[]">
249+
<div data-role="gallery"
250+
class="gallery"
251+
data-images="[]"
252+
data-types="<?php /* @noEscape */ echo $block->escapeHtml(
253+
$this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getImageTypes())
254+
) ?>"
255+
>
262256
<div class="image image-placeholder">
263257
<div data-role="uploader" class="uploader">
264258
<div class="image-browse">
@@ -273,19 +267,6 @@
273267
<span></span><span></span><span></span><span></span>
274268
</div>
275269
</div>
276-
<input name="product[image]"
277-
class="image-image"
278-
type="hidden"
279-
value=""/>
280-
<input name="product[small_image]"
281-
class="image-small_image"
282-
type="hidden"
283-
value=""/>
284-
<input name="product[thumbnail]"
285-
class="image-thumbnail"
286-
type="hidden"
287-
value=""/>
288-
289270
<script data-template="uploader" type="text/x-magento-template">
290271
<div id="<%- data.id %>" class="file-row">
291272
<span class="file-info"><%- data.name %> (<%- data.size %>)</span>
@@ -321,11 +302,6 @@
321302
name="product[media_gallery][images][<%- data.file_id %>][removed]"
322303
value=""
323304
class="is-removed"/>
324-
<ul class="type-labels" style="display: none">
325-
<li class="type-image"><?= /* @escapeNotVerified */ __('Base Image') ?></li>
326-
<li class="type-small_image"><?= /* @escapeNotVerified */ __('Small Image') ?></li>
327-
<li class="type-thumbnail"><?= /* @escapeNotVerified */ __('Thumbnail') ?></li>
328-
</ul>
329305
<img class="product-image" src="<%- data.url %>" alt="<%- data.label %>"/>
330306

331307
<button type="button"
@@ -387,36 +363,26 @@
387363
</label>
388364
<div class="control">
389365
<ul class="multiselect-alt">
390-
<li class="item">
391-
<label>
392-
<input class="image-type"
393-
data-role="type-selector"
394-
type="checkbox"
395-
value="image"
396-
/>
397-
<?= /* @escapeNotVerified */ __('Base Image') ?>
398-
</label>
399-
</li>
400-
<li class="item">
401-
<label>
402-
<input class="image-type"
403-
data-role="type-selector"
404-
type="checkbox"
405-
value="small_image"
406-
/>
407-
<?= /* @escapeNotVerified */ __('Small Image') ?>
408-
</label>
409-
</li>
410-
<li class="item">
411-
<label>
412-
<input class="image-type"
413-
data-role="type-selector"
414-
type="checkbox"
415-
value="thumbnail"
416-
/>
417-
<?= /* @escapeNotVerified */ __('Thumbnail') ?>
418-
</label>
419-
</li>
366+
<?php
367+
foreach ($block->getMediaAttributes() as $attribute) :
368+
?>
369+
<li class="item">
370+
<label>
371+
<input class="image-type"
372+
data-role="type-selector"
373+
type="checkbox"
374+
value="<?php /* @noEscape */ echo $block->escapeHtml(
375+
$attribute->getAttributeCode()
376+
) ?>"
377+
/>
378+
<?php /* @noEscape */ echo $block->escapeHtml(
379+
$attribute->getFrontendLabel()
380+
) ?>
381+
</label>
382+
</li>
383+
<?php
384+
endforeach;
385+
?>
420386
</ul>
421387
</div>
422388
</div>

0 commit comments

Comments
 (0)