Skip to content

Commit

Permalink
Merge pull request #98 from magento-goinc/prepared-pull-request
Browse files Browse the repository at this point in the history
[GoInc] bugsfixing
  • Loading branch information
Slabko,Michael(mslabko) authored and Slabko,Michael(mslabko) committed Nov 2, 2015
2 parents abb8d3b + 92513dc commit c743dec
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 133 deletions.
30 changes: 14 additions & 16 deletions app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,21 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
$optionId = $connection->fetchOne($statement);

if ($optionId) {
if ($object->getStoreId() == '0') {
$data = $this->_prepareDataForTable(
new \Magento\Framework\DataObject(
['price' => $object->getPrice(), 'price_type' => $object->getPriceType()]
),
$priceTable
);
$data = $this->_prepareDataForTable(
new \Magento\Framework\DataObject(
['price' => $object->getPrice(), 'price_type' => $object->getPriceType()]
),
$priceTable
);

$connection->update(
$priceTable,
$data,
[
'option_id = ?' => $object->getId(),
'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
]
);
}
$connection->update(
$priceTable,
$data,
[
'option_id = ?' => $object->getId(),
'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID
]
);
} else {
$data = $this->_prepareDataForTable(
new \Magento\Framework\DataObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ class Bulk extends \Magento\Ui\Block\Component\StepsWizard\StepAbstract
/** @var \Magento\Catalog\Helper\Image */
protected $image;

/**
* @var \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes
*/
protected $variationMediaAttributes;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Catalog\Helper\Image $image
* @param \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes $variationMediaAttributes
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Catalog\Helper\Image $image
\Magento\Catalog\Helper\Image $image,
\Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes $variationMediaAttributes
) {
parent::__construct($context);
$this->image = $image;
$this->variationMediaAttributes = $variationMediaAttributes;
}

/**
Expand All @@ -39,4 +47,31 @@ public function getNoImageUrl()
{
return $this->image->getDefaultPlaceholderUrl('thumbnail');
}

/**
* Get image types data
*
* @return array
*/
public function getImageTypes()
{
$imageTypes = [];
foreach ($this->variationMediaAttributes->getMediaAttributes() as $attribute) {
/* @var $attribute \Magento\Eav\Model\Entity\Attribute */
$imageTypes[$attribute->getAttributeCode()] = [
'code' => $attribute->getAttributeCode(),
'value' => '',
'name' => '',
];
}
return $imageTypes;
}

/**
* @return array
*/
public function getMediaAttributes()
{
return $this->variationMediaAttributes->getMediaAttributes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,36 @@ class VariationHandler
/** @var \Magento\CatalogInventory\Api\StockConfigurationInterface */
protected $stockConfiguration;

/**
* @var \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes
*/
protected $variationMediaAttributes;

/**
* @param Type\Configurable $configurableProduct
* @param \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory
* @param \Magento\Eav\Model\EntityFactory $entityFactory
* @param \Magento\Catalog\Model\ProductFactory $productFactory
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
* @param \Magento\Catalog\Model\Product\Attribute\Backend\Media $media
* @param VariationMediaAttributes $variationMediaAttributes
*/
public function __construct(
Type\Configurable $configurableProduct,
\Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory,
\Magento\Eav\Model\EntityFactory $entityFactory,
\Magento\Catalog\Model\ProductFactory $productFactory,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
\Magento\Catalog\Model\Product\Attribute\Backend\Media $media
\Magento\Catalog\Model\Product\Attribute\Backend\Media $media,
\Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes $variationMediaAttributes
) {
$this->configurableProduct = $configurableProduct;
$this->attributeSetFactory = $attributeSetFactory;
$this->entityFactory = $entityFactory;
$this->productFactory = $productFactory;
$this->stockConfiguration = $stockConfiguration;
$this->media = $media;
$this->variationMediaAttributes = $variationMediaAttributes;
}

/**
Expand Down Expand Up @@ -209,11 +217,11 @@ public function duplicateImagesForVariations($productsData)
$variationId = $image['variation_id'];
$newFile = $this->media->duplicateImageFromTmp($file);
$productsData[$variationId]['media_gallery']['images'][$imageId]['file'] = $newFile;
foreach (['small_image', 'thumbnail', 'image'] as $imageType) {
if (isset($productsData[$variationId][$imageType])
&& $productsData[$variationId][$imageType] == $file
foreach ($this->variationMediaAttributes->getMediaAttributes() as $attribute) {
if (isset($productsData[$variationId][$attribute->getAttributeCode()])
&& $productsData[$variationId][$attribute->getAttributeCode()] == $file
) {
$productsData[$variationId][$imageType] = $newFile;
$productsData[$variationId][$attribute->getAttributeCode()] = $newFile;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\ConfigurableProduct\Model\Product;

/**
* Class VariationMediaAttributes. Return media attributes allowed for variations
*/
class VariationMediaAttributes
{
/**
* @var \Magento\Catalog\Model\ProductFactory
*/
protected $productFactory;

/**
* @var array
*/
protected $mediaAttributes;

/**
* @param \Magento\Catalog\Model\ProductFactory $productFactory
*/
public function __construct(\Magento\Catalog\Model\ProductFactory $productFactory)
{
$this->productFactory = $productFactory;
}

/**
* Get media attributes for Configurable variation
*
* @return array
*/
public function getMediaAttributes()
{
if (null === $this->mediaAttributes) {
$this->mediaAttributes = $this->getProduct()->getMediaAttributes();
}
return $this->mediaAttributes;
}

/**
* Get product container for Simple product
*
* @return \Magento\Catalog\Model\Product
*/
private function getProduct()
{
return $this->productFactory->create()->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@
</ul>

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

<input name="product[image]"
class="image-image"
type="hidden"
value="" />
<input name="product[small_image]"
class="image-small_image"
type="hidden"
value="" />
<input name="product[thumbnail]"
class="image-thumbnail"
type="hidden"
value="" />

<script data-template="uploader" type="text/x-magento-template">
<div id="<%- data.id %>" class="file-row">
<span class="file-info"><%- data.name %> (<%- data.size %>)</span>
Expand Down Expand Up @@ -185,30 +178,25 @@
</label>
<div class="control">
<ul class="multiselect-alt">
<li class="item">
<label>
<input class="image-type"
data-role="type-selector"
type="checkbox"
value="image"
/><?= /* @escapeNotVerified */ __('Base Image') ?></label>
</li>
<li class="item">
<label>
<input class="image-type"
data-role="type-selector"
type="checkbox"
value="small_image"
/><?= /* @escapeNotVerified */ __('Small Image') ?></label>
</li>
<li class="item">
<label>
<input class="image-type"
data-role="type-selector"
type="checkbox"
value="thumbnail"
/><?= /* @escapeNotVerified */ __('Thumbnail') ?></label>
</li>
<?php
foreach ($block->getMediaAttributes() as $attribute) : ?>
<li class="item">
<label>
<input class="image-type"
data-role="type-selector"
type="checkbox"
value="<?php /* @noEscape */ echo $block->escapeHtml(
$attribute->getAttributeCode()
) ?>"
/>
<?php /* @noEscape */ echo $block->escapeHtml(
$attribute->getFrontendLabel()
) ?>
</label>
</li>
<?php
endforeach;
?>
</ul>
</div>
</div>
Expand Down Expand Up @@ -258,7 +246,13 @@
<span data-bind="text:label"></span>
</label>

<div data-role="gallery" class="gallery" data-images="[]">
<div data-role="gallery"
class="gallery"
data-images="[]"
data-types="<?php /* @noEscape */ echo $block->escapeHtml(
$this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getImageTypes())
) ?>"
>
<div class="image image-placeholder">
<div data-role="uploader" class="uploader">
<div class="image-browse">
Expand All @@ -273,19 +267,6 @@
<span></span><span></span><span></span><span></span>
</div>
</div>
<input name="product[image]"
class="image-image"
type="hidden"
value=""/>
<input name="product[small_image]"
class="image-small_image"
type="hidden"
value=""/>
<input name="product[thumbnail]"
class="image-thumbnail"
type="hidden"
value=""/>

<script data-template="uploader" type="text/x-magento-template">
<div id="<%- data.id %>" class="file-row">
<span class="file-info"><%- data.name %> (<%- data.size %>)</span>
Expand Down Expand Up @@ -321,11 +302,6 @@
name="product[media_gallery][images][<%- data.file_id %>][removed]"
value=""
class="is-removed"/>
<ul class="type-labels" style="display: none">
<li class="type-image"><?= /* @escapeNotVerified */ __('Base Image') ?></li>
<li class="type-small_image"><?= /* @escapeNotVerified */ __('Small Image') ?></li>
<li class="type-thumbnail"><?= /* @escapeNotVerified */ __('Thumbnail') ?></li>
</ul>
<img class="product-image" src="<%- data.url %>" alt="<%- data.label %>"/>

<button type="button"
Expand Down Expand Up @@ -387,36 +363,26 @@
</label>
<div class="control">
<ul class="multiselect-alt">
<li class="item">
<label>
<input class="image-type"
data-role="type-selector"
type="checkbox"
value="image"
/>
<?= /* @escapeNotVerified */ __('Base Image') ?>
</label>
</li>
<li class="item">
<label>
<input class="image-type"
data-role="type-selector"
type="checkbox"
value="small_image"
/>
<?= /* @escapeNotVerified */ __('Small Image') ?>
</label>
</li>
<li class="item">
<label>
<input class="image-type"
data-role="type-selector"
type="checkbox"
value="thumbnail"
/>
<?= /* @escapeNotVerified */ __('Thumbnail') ?>
</label>
</li>
<?php
foreach ($block->getMediaAttributes() as $attribute) :
?>
<li class="item">
<label>
<input class="image-type"
data-role="type-selector"
type="checkbox"
value="<?php /* @noEscape */ echo $block->escapeHtml(
$attribute->getAttributeCode()
) ?>"
/>
<?php /* @noEscape */ echo $block->escapeHtml(
$attribute->getFrontendLabel()
) ?>
</label>
</li>
<?php
endforeach;
?>
</ul>
</div>
</div>
Expand Down
Loading

0 comments on commit c743dec

Please sign in to comment.