Skip to content

Commit

Permalink
Merge pull request #1759 from magento-qwerty/PR-22-2017-11-23
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-75217: SKU parameter in capital letters on CSV ignored by database in Import but OK'd by validator
- MAGETWO-77840: [2.2.x] - Special/lowest price in child of a Configurable Product causes the entire product to show that price
- MAGETWO-70725: Admin token does not expire after 'Admin Token Lifetime (hours)'
  • Loading branch information
dvoskoboinikov authored Nov 24, 2017
2 parents 6260a36 + 5e6f1cb commit 1865e82
Show file tree
Hide file tree
Showing 19 changed files with 671 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Exception\LocalizedException;

/**
* Importing configurable products
Expand All @@ -34,16 +35,24 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ

const ERROR_DUPLICATED_VARIATIONS = 'duplicatedVariations';

const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation';

/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = [
self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Attribute with code "%s" is not super',
self::ERROR_INVALID_OPTION_VALUE => 'Invalid option value for attribute "%s"',
self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute',
self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations',
self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER =>
'Attribute with code "%s" is not super',
self::ERROR_INVALID_OPTION_VALUE =>
'Invalid option value for attribute "%s"',
self::ERROR_INVALID_WEBSITE =>
'Invalid website code for super attribute',
self::ERROR_DUPLICATED_VARIATIONS =>
'SKU %s contains duplicated variations',
self::ERROR_UNIDENTIFIABLE_VARIATION =>
'Configurable variation "%s" is unidentifiable',
];

/**
Expand Down Expand Up @@ -471,13 +480,14 @@ protected function _processSuperData()
* @param array $rowData
*
* @return array
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _parseVariations($rowData)
{
$additionalRows = [];
if (!isset($rowData['configurable_variations'])) {
if (empty($rowData['configurable_variations'])) {
return $additionalRows;
}
$variations = explode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $rowData['configurable_variations']);
Expand All @@ -489,8 +499,10 @@ protected function _parseVariations($rowData)
foreach ($fieldAndValuePairsText as $nameAndValue) {
$nameAndValue = explode(ImportProduct::PAIR_NAME_VALUE_SEPARATOR, $nameAndValue);
if (!empty($nameAndValue)) {
$value = isset($nameAndValue[1]) ? trim($nameAndValue[1]) : '';
$fieldName = trim($nameAndValue[0]);
$value = isset($nameAndValue[1]) ?
trim($nameAndValue[1]) : '';
//Ignoring field names' case.
$fieldName = strtolower(trim($nameAndValue[0]));
if ($fieldName) {
$fieldAndValuePairs[$fieldName] = $value;
}
Expand All @@ -511,8 +523,19 @@ protected function _parseVariations($rowData)
$additionalRow = [];
$position += 1;
}
} else {
$errorCode = self::ERROR_UNIDENTIFIABLE_VARIATION;
throw new LocalizedException(
__(
sprintf(
$this->_messageTemplates[$errorCode],
$variation
)
)
);
}
}

return $additionalRows;
}

Expand Down Expand Up @@ -823,7 +846,14 @@ protected function configurableInBunch($bunch)
public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
{
$error = false;
$dataWithExtraVirtualRows = $this->_parseVariations($rowData);
try {
$dataWithExtraVirtualRows = $this->_parseVariations($rowData);
} catch (LocalizedException $exception) {
$this->_entityModel->addRowError($exception->getMessage(), $rowNum);

return false;
}

$skus = [];
$rowData['price'] = isset($rowData['price']) && $rowData['price'] ? $rowData['price'] : '0.00';
if (!empty($dataWithExtraVirtualRows)) {
Expand All @@ -841,6 +871,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
}
$error |= !parent::isRowValid($option, $rowNum, $isNewProduct);
}

return !$error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,56 @@ public function testIsRowValid()
'_type' => 'configurable',
'_product_websites' => 'website_1',
];
//Checking that variations' field names are case-insensitive with this
//product.
$caseInsensitiveSKU = 'configurableskuI22CaseInsensitive';
$caseInsensitiveProduct = [
'sku' => $caseInsensitiveSKU,
'store_view_code' => null,
'attribute_set_code' => 'Default',
'product_type' => 'configurable',
'name' => 'Configurable Product 21',
'product_websites' => 'website_1',
'configurable_variation_labels' => 'testattr2=Select Color, testattr3=Select Size',
'configurable_variations' => 'SKU=testconf2-attr2val1-testattr3v1,'
. 'testattr2=attr2val1,'
. 'testattr3=testattr3v1,'
. 'display=1|sku=testconf2-attr2val1-testattr3v2,'
. 'testattr2=attr2val1,'
. 'testattr3=testattr3v2,'
. 'display=0',
'_store' => null,
'_attribute_set' => 'Default',
'_type' => 'configurable',
'_product_websites' => 'website_1',
];
$bunch[] = $badProduct;
$bunch[] = $caseInsensitiveProduct;
// Set _attributes to avoid error in Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType.
$this->setPropertyValue($this->configurable, '_attributes', [
$badProduct[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
]);
//Avoiding errors about attributes not being super
$this->setPropertyValue(
$this->configurable,
'_superAttributes',
[
'testattr2' => ['options' => ['attr2val1' => 1]],
'testattr3' => [
'options' => [
'testattr3v2' => 1,
'testattr3v1' => 1,
],
],
]
);

foreach ($bunch as $rowData) {
$result = $this->configurable->isRowValid($rowData, 0, !isset($this->_oldSku[$rowData['sku']]));
$this->assertNotNull($result);
if ($rowData['sku'] === $caseInsensitiveSKU) {
$this->assertTrue($result);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ $finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;
?>
<?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
<span class="special-price">
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('Special Price'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',

<span class="normal-price">
<?php
$arguments = [
'display_label' => __('As low as'),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
</span>
];

/* @noEscape */ echo $block->renderAmount($finalPriceModel->getAmount(), $arguments);
?>
</span>

<?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
<span class="old-price sly-old-price no-display">
<?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Regular Price'),
Expand All @@ -38,13 +44,6 @@ $schema = ($block->getZone() == 'item_view') ? true : false;
'skip_adjustments' => true
]); ?>
</span>
<?php else: ?>
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
<?php endif; ?>

<?php if ($block->showMinimalPrice()): ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define([
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
mediaGalleryInitial: null,
slyOldPriceSelector: '.sly-old-price',
normalPriceLabelSelector: '.normal-price .price-label',

/**
* Defines the mechanism of how images of a gallery should be
Expand Down Expand Up @@ -269,6 +270,7 @@ define([
this._reloadPrice();
this._displayRegularPriceBlock(this.simpleProduct);
this._displayTierPriceBlock(this.simpleProduct);
this._displayNormalPriceLabel();
this._changeProductImage();
},

Expand Down Expand Up @@ -527,8 +529,16 @@ define([
* @private
*/
_displayRegularPriceBlock: function (optionId) {
if (typeof optionId != 'undefined' &&
this.options.spConfig.optionPrices[optionId].oldPrice.amount != //eslint-disable-line eqeqeq
var shouldBeShown = true;

_.each(this.options.settings, function (element) {
if (element.value === '') {
shouldBeShown = false;
}
});

if (shouldBeShown &&
this.options.spConfig.optionPrices[optionId].oldPrice.amount !==
this.options.spConfig.optionPrices[optionId].finalPrice.amount
) {
$(this.options.slyOldPriceSelector).show();
Expand All @@ -537,6 +547,27 @@ define([
}
},

/**
* Show or hide normal price label
*
* @private
*/
_displayNormalPriceLabel: function () {
var shouldBeShown = false;

_.each(this.options.settings, function (element) {
if (element.value === '') {
shouldBeShown = true;
}
});

if (shouldBeShown) {
$(this.options.normalPriceLabelSelector).show();
} else {
$(this.options.normalPriceLabelSelector).hide();
}
},

/**
* Callback which fired after gallery gets initialized.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ define([
// tier prise selectors start
tierPriceTemplateSelector: '#tier-prices-template',
tierPriceBlockSelector: '[data-role="tier-price-block"]',
tierPriceTemplate: ''
tierPriceTemplate: '',
// tier prise selectors end

// A price label selector
normalPriceLabelSelector: '.normal-price .price-label'
},

/**
Expand Down Expand Up @@ -930,6 +933,22 @@ define([
} else {
$(this.options.tierPriceBlockSelector).hide();
}

$(this.options.normalPriceLabelSelector).hide();

_.each($('.' + this.options.classes.attributeOptionsWrapper), function (attribute) {
if ($(attribute).find('.' + this.options.classes.optionClass + '.selected').length === 0) {
if ($(attribute).find('.' + this.options.classes.selectClass).length > 0) {
_.each($(attribute).find('.' + this.options.classes.selectClass), function (dropdown) {
if ($(dropdown).val() === '0') {
$(this.options.normalPriceLabelSelector).show();
}
}.bind(this));
} else {
$(this.options.normalPriceLabelSelector).show();
}
}
}.bind(this));
},

/**
Expand Down
Loading

0 comments on commit 1865e82

Please sign in to comment.