Skip to content

Commit

Permalink
Merge pull request #110 from magento-nord/MAGETWO-44145
Browse files Browse the repository at this point in the history
[EPAM][NORD+GOINC+TROLL+DRAGONS] Bugfixes
  • Loading branch information
Miniailo, Igor(iminiailo) committed Nov 4, 2015
2 parents 16dc76d + dddd5b1 commit 0d08a72
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ $isElementReadonly = $block->getElement()
&& !$block->getProduct()->isObjectNew())) { ?>
$('<?= /* @escapeNotVerified */ $switchAttributeCode?>').observe('change', <?= /* @escapeNotVerified */ $switchAttributeCode?>_change);
<?php } ?>
<?= /* @escapeNotVerified */ $switchAttributeCode?>_change();
Event.observe(window, 'load', function(){
<?= /* @escapeNotVerified */ $switchAttributeCode?>_change();
});
});
</script>
<?php } ?>
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ public function saveData()
public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
{
$rowData = array_merge($rowData, $this->transformBundleCustomAttributes($rowData));
if (isset($rowData['bundle_price_type']) && $rowData['bundle_price_type'] == 'dynamic') {
$rowData['price'] = isset($rowData['price']) && $rowData['price'] ? $rowData['price'] : '0.00';
}
return parent::isRowValid($rowData, $rowNum, $isNewProduct);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ public function testIsRowValid()
{
$this->entityModel->expects($this->any())->method('getRowScope')->will($this->returnValue(-1));
$rowData = [
'price_type' => 'fixed',
'price_view' => 'bundle_price_view'
'bundle_price_type' => 'dynamic',
'bundle_price_view' => 'bundle_price_view'
];
$this->assertEquals($this->bundle->isRowValid($rowData, 0), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public function getAfterElementHtml()
$addJsObserver = false;
if ($attribute = $this->getEntityAttribute()) {
$store = $this->getStore($attribute);
$html .= '<strong>' . $this->_localeCurrency->getCurrency(
$store->getBaseCurrencyCode()
)->getSymbol() . '</strong>';
if ($this->getType() !== 'hidden') {
$html .= '<strong>'
. $this->_localeCurrency->getCurrency($store->getBaseCurrencyCode())->getSymbol()
. '</strong>';
}
if ($this->_taxData->priceIncludesTax($store)) {
if ($attribute->getAttributeCode() !== 'cost') {
$addJsObserver = true;
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Helper/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public function init($product, $imageId, $attributes = [])
$this->_reset();

$this->attributes = array_merge(
$attributes,
$this->getConfigView()->getMediaAttributes('Magento_Catalog', self::MEDIA_TYPE_CONFIG_NODE, $imageId)
$this->getConfigView()->getMediaAttributes('Magento_Catalog', self::MEDIA_TYPE_CONFIG_NODE, $imageId),
$attributes
);

$this->setProduct($product);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,9 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
{
$error = false;
$rowScope = $this->_entityModel->getRowScope($rowData);
if ((\Magento\CatalogImportExport\Model\Import\Product::SCOPE_NULL != $rowScope) &&
!empty($rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_SKU])) {


if (\Magento\CatalogImportExport\Model\Import\Product::SCOPE_NULL != $rowScope
&& !empty($rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_SKU])
) {
foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
// check value for non-empty in the case of required attribute?
if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
Expand All @@ -437,9 +436,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
))
) {
$this->_entityModel->addRowError(
// @codingStandardsIgnoreStart
\Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface::ERROR_VALUE_IS_REQUIRED,
// @codingStandardsIgnoreEnd
RowValidatorInterface::ERROR_VALUE_IS_REQUIRED,
$rowNum,
$attrCode
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function isRequiredAttributeValid($attrCode, array $attributeParams, arra
$doCheck = false;
if ($attrCode == Product::COL_SKU) {
$doCheck = true;
} elseif ($attrCode == 'price') {
$doCheck = false;
} elseif ($attributeParams['is_required'] && $this->getRowScope($rowData) == Product::SCOPE_DEFAULT
&& $this->context->getBehavior() != \Magento\ImportExport\Model\Import::BEHAVIOR_DELETE
) {
Expand All @@ -124,7 +126,9 @@ public function isRequiredAttributeValid($attrCode, array $attributeParams, arra
public function isAttributeValid($attrCode, array $attrParams, array $rowData)
{
$this->_rowData = $rowData;
if (!empty($attrParams['apply_to']) && !in_array($rowData['product_type'], $attrParams['apply_to'])) {
if (isset($rowData['product_type']) && !empty($attrParams['apply_to'])
&& !in_array($rowData['product_type'], $attrParams['apply_to'])
) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function testAttributeValidation($behavior, $attrParams, $rowData, $isVal

/**
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function attributeValidationProvider()
{
Expand Down Expand Up @@ -147,6 +148,13 @@ public function attributeValidationProvider()
['product_type' => 'any', 'attribute_code' => '1'],
true
],
[
Import::BEHAVIOR_APPEND,
['is_required' => true, 'type' => 'decimal'],
['product_type' => 'any', 'price' => ''],
true,
'price'
],
[
Import::BEHAVIOR_APPEND,
['is_required' => true, 'type' => 'boolean', 'options' => ['yes' => 0, 'no' => 1]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
$error = false;
$dataWithExtraVirtualRows = $this->_parseVariations($rowData);
$skus = [];
$rowData['price'] = isset($rowData['price']) && $rowData['price'] ? $rowData['price'] : '0.00';
if (!empty($dataWithExtraVirtualRows)) {
array_unshift($dataWithExtraVirtualRows, $rowData);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function aroundValidate(
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\DataObject $response
) {
if ($request->has('attributes')) {
$product->setTypeId(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE);
}
$result = $proceed($product, $request, $response);
$variationProducts = (array)$request->getPost('variations-matrix');
if ($variationProducts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ define([
'use strict';

return {
$initiallyDisabledAttributes: [],
$links: $('[data-ui-id=product-tabs-tab-link-advanced-pricing]'),
$tab: $('[data-tab-panel=advanced-pricing]'),
toggleDisabledAttribute: function (disabled) {
$('input,select', this.$tab).each(function (index, element) {
$(element).attr('disabled', disabled);
if (!$.inArray(element, this.$initiallyDisabledAttributes)) {
$(element).attr('disabled', disabled);
}
});
},
init: function () {
$(document).on('changeTypeProduct', this._initType.bind(this));
this._setInitialState();
this._initType();
},
_setInitialState: function () {
if (this.$initiallyDisabledAttributes.length == 0) {
this.$initiallyDisabledAttributes = $('input:disabled,select:disabled', this.$tab).toArray();
}
},
_initType: function () {
var isConfigurable = productType.type.current === 'configurable';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\ImportExport\Model\Export\Adapter;

use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Abstract adapter model
Expand Down Expand Up @@ -45,7 +45,7 @@ abstract class AbstractAdapter
public function __construct(
\Magento\Framework\Filesystem $filesystem,
$destination = null,
$destinationDirectoryCode = DirectoryList::SYS_TMP
$destinationDirectoryCode = DirectoryList::VAR_DIR
) {
$this->_directoryHandle = $filesystem->getDirectoryWrite($destinationDirectoryCode);
if (!$destination) {
Expand Down
5 changes: 0 additions & 5 deletions app/code/Magento/Msrp/view/base/web/js/msrp.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,6 @@ define([
this.$popup.find(this.options.msrpLabelId).html(this.options.msrpPrice);
this.$popup.find(this.options.priceLabelId).html(this.options.realPrice);
this.$popup.dropdownDialog(this.popUpOptions).dropdownDialog('open');
this.$popup.find('button').on('click', function () {
if (this.options.addToCartButton) {
$(this.options.addToCartButton).click();
}
}.bind(this));
this._toggle(this.$popup);

if (!this.options.isSaleable) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/ProductVideo/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<default>
<catalog>
<product_video>
<play_if_base>1</play_if_base>
<play_if_base>0</play_if_base>
<show_related>0</show_related>
<video_auto_restart>0</video_auto_restart>
</product_video>
Expand Down
36 changes: 21 additions & 15 deletions app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ protected function extractNecessarySwatchData(array $swatchDataArray)

if ($result['type'] == Swatch::SWATCH_TYPE_VISUAL_IMAGE && !empty($swatchDataArray['value'])) {
$result['value'] = $this->swatchMediaHelper->getSwatchAttributeImage(
'swatch_image',
Swatch::SWATCH_IMAGE_NAME,
$swatchDataArray['value']
);
$result['thumb'] = $this->swatchMediaHelper->getSwatchAttributeImage(
'swatch_thumb',
Swatch::SWATCH_THUMBNAIL_NAME,
$swatchDataArray['value']
);
} else {
Expand All @@ -284,8 +284,8 @@ protected function getVariationMedia($attributeCode, $optionId)
$variationMediaArray = [];
if ($variationProduct) {
$variationMediaArray = [
'value' => $this->getSwatchProductImage($variationProduct, 'swatch_image'),
'thumb' => $this->getSwatchProductImage($variationProduct, 'swatch_thumb'),
'value' => $this->getSwatchProductImage($variationProduct, Swatch::SWATCH_IMAGE_NAME),
'thumb' => $this->getSwatchProductImage($variationProduct, Swatch::SWATCH_THUMBNAIL_NAME),
];
}

Expand All @@ -299,22 +299,28 @@ protected function getVariationMedia($attributeCode, $optionId)
*/
protected function getSwatchProductImage(Product $childProduct, $imageType)
{
if (
$childProduct->getData('swatch_image') !== null
&& $childProduct->getData('swatch_image') != self::EMPTY_IMAGE_VALUE
) {
$swatchImageId = $imageType == 'swatch_image' ? 'swatch_image' : 'swatch_thumb';
} elseif (
$childProduct->getData('image') !== null
&& $childProduct->getData('image') != self::EMPTY_IMAGE_VALUE
) {
$swatchImageId = $imageType == 'swatch_image' ? 'swatch_image_base' : 'swatch_thumb_base';
if ($this->isProductHasImage($childProduct, Swatch::SWATCH_IMAGE_NAME)) {
$swatchImageId = $imageType;
$imageAttributes = ['type' => Swatch::SWATCH_IMAGE_NAME];
} elseif ($this->isProductHasImage($childProduct, 'image')) {
$swatchImageId = $imageType == Swatch::SWATCH_IMAGE_NAME ? 'swatch_image_base' : 'swatch_thumb_base';
$imageAttributes = ['type' => 'image'];
}
if (isset($swatchImageId)) {
return $this->_imageHelper->init($childProduct, $swatchImageId)->getUrl();
return $this->_imageHelper->init($childProduct, $swatchImageId, $imageAttributes)->getUrl();
}
}

/**
* @param Product $product
* @param string $imageType
* @return bool
*/
protected function isProductHasImage(Product $product, $imageType)
{
return $product->getData($imageType) !== null && $product->getData($imageType) != self::EMPTY_IMAGE_VALUE;
}

/**
* @param array $attributeData
* @return array
Expand Down
7 changes: 1 addition & 6 deletions app/code/Magento/Swatches/Model/Plugin/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
*/
class Product
{
/**
* Name of swatch image role
*/
const ROLE_SWATCH_IMAGE_NAME = 'swatch_image';

/**
* Unset swatch image role if product is not simple
*
Expand All @@ -28,7 +23,7 @@ public function afterGetMediaAttributes(\Magento\Catalog\Model\Product $product,
&& $product->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL
) {
if (is_array($imageRoles)) {
unset($imageRoles[self::ROLE_SWATCH_IMAGE_NAME]);
unset($imageRoles[\Magento\Swatches\Model\Swatch::SWATCH_IMAGE_NAME]);
}
}

Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Swatches/Model/Swatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class Swatch extends \Magento\Framework\Model\AbstractModel
/** Constant for identifying empty swatch type */
const SWATCH_TYPE_EMPTY = 3;

/**
* Name of swatch image
*/
const SWATCH_IMAGE_NAME = 'swatch_image';

/**
* Name of swatch thumbnail
*/
const SWATCH_THUMBNAIL_NAME = 'swatch_thumb';

/**
* Initialize resource model
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public function testGetJsonSwatchConfigNotVisualImageType()

$this->imageHelper->expects($this->exactly(2))->method('init')
->willReturnMap([
[$this->product, 'swatch_image', [], $this->imageHelper],
[$this->product, 'swatch_thumb', [], $this->imageHelper],
[$this->product, 'swatch_image', ['type' => 'swatch_image'], $this->imageHelper],
[$this->product, 'swatch_thumb', ['type' => 'swatch_image'], $this->imageHelper],
]);

$this->jsonEncoder->expects($this->once())->method('encode');
Expand Down Expand Up @@ -222,8 +222,8 @@ public function testGetJsonSwatchConfigVisualImageType()

$this->imageHelper->expects($this->exactly(2))->method('init')
->willReturnMap([
[$this->product, 'swatch_image_base', [], $this->imageHelper],
[$this->product, 'swatch_thumb_base', [], $this->imageHelper],
[$this->product, 'swatch_image_base', ['type' => 'image'], $this->imageHelper],
[$this->product, 'swatch_thumb_base', ['type' => 'image'], $this->imageHelper],
]);

$this->jsonEncoder->expects($this->once())->method('encode');
Expand Down
Loading

0 comments on commit 0d08a72

Please sign in to comment.