Skip to content

Commit 1865e82

Browse files
Merge pull request #1759 from magento-qwerty/PR-22-2017-11-23
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)'
2 parents 6260a36 + 5e6f1cb commit 1865e82

File tree

19 files changed

+671
-74
lines changed

19 files changed

+671
-74
lines changed

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Catalog\Api\Data\ProductInterface;
1414
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
1515
use Magento\Framework\EntityManager\MetadataPool;
16+
use Magento\Framework\Exception\LocalizedException;
1617

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

3536
const ERROR_DUPLICATED_VARIATIONS = 'duplicatedVariations';
3637

38+
const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation';
39+
3740
/**
3841
* Validation failure message template definitions
3942
*
4043
* @var array
4144
*/
4245
protected $_messageTemplates = [
43-
self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Attribute with code "%s" is not super',
44-
self::ERROR_INVALID_OPTION_VALUE => 'Invalid option value for attribute "%s"',
45-
self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute',
46-
self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations',
46+
self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER =>
47+
'Attribute with code "%s" is not super',
48+
self::ERROR_INVALID_OPTION_VALUE =>
49+
'Invalid option value for attribute "%s"',
50+
self::ERROR_INVALID_WEBSITE =>
51+
'Invalid website code for super attribute',
52+
self::ERROR_DUPLICATED_VARIATIONS =>
53+
'SKU %s contains duplicated variations',
54+
self::ERROR_UNIDENTIFIABLE_VARIATION =>
55+
'Configurable variation "%s" is unidentifiable',
4756
];
4857

4958
/**
@@ -471,13 +480,14 @@ protected function _processSuperData()
471480
* @param array $rowData
472481
*
473482
* @return array
483+
* @throws LocalizedException
474484
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
475485
* @SuppressWarnings(PHPMD.NPathComplexity)
476486
*/
477487
protected function _parseVariations($rowData)
478488
{
479489
$additionalRows = [];
480-
if (!isset($rowData['configurable_variations'])) {
490+
if (empty($rowData['configurable_variations'])) {
481491
return $additionalRows;
482492
}
483493
$variations = explode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $rowData['configurable_variations']);
@@ -489,8 +499,10 @@ protected function _parseVariations($rowData)
489499
foreach ($fieldAndValuePairsText as $nameAndValue) {
490500
$nameAndValue = explode(ImportProduct::PAIR_NAME_VALUE_SEPARATOR, $nameAndValue);
491501
if (!empty($nameAndValue)) {
492-
$value = isset($nameAndValue[1]) ? trim($nameAndValue[1]) : '';
493-
$fieldName = trim($nameAndValue[0]);
502+
$value = isset($nameAndValue[1]) ?
503+
trim($nameAndValue[1]) : '';
504+
//Ignoring field names' case.
505+
$fieldName = strtolower(trim($nameAndValue[0]));
494506
if ($fieldName) {
495507
$fieldAndValuePairs[$fieldName] = $value;
496508
}
@@ -511,8 +523,19 @@ protected function _parseVariations($rowData)
511523
$additionalRow = [];
512524
$position += 1;
513525
}
526+
} else {
527+
$errorCode = self::ERROR_UNIDENTIFIABLE_VARIATION;
528+
throw new LocalizedException(
529+
__(
530+
sprintf(
531+
$this->_messageTemplates[$errorCode],
532+
$variation
533+
)
534+
)
535+
);
514536
}
515537
}
538+
516539
return $additionalRows;
517540
}
518541

@@ -823,7 +846,14 @@ protected function configurableInBunch($bunch)
823846
public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
824847
{
825848
$error = false;
826-
$dataWithExtraVirtualRows = $this->_parseVariations($rowData);
849+
try {
850+
$dataWithExtraVirtualRows = $this->_parseVariations($rowData);
851+
} catch (LocalizedException $exception) {
852+
$this->_entityModel->addRowError($exception->getMessage(), $rowNum);
853+
854+
return false;
855+
}
856+
827857
$skus = [];
828858
$rowData['price'] = isset($rowData['price']) && $rowData['price'] ? $rowData['price'] : '0.00';
829859
if (!empty($dataWithExtraVirtualRows)) {
@@ -841,6 +871,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
841871
}
842872
$error |= !parent::isRowValid($option, $rowNum, $isNewProduct);
843873
}
874+
844875
return !$error;
845876
}
846877

app/code/Magento/ConfigurableImportExport/Test/Unit/Model/Import/Product/Type/ConfigurableTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,56 @@ public function testIsRowValid()
560560
'_type' => 'configurable',
561561
'_product_websites' => 'website_1',
562562
];
563+
//Checking that variations' field names are case-insensitive with this
564+
//product.
565+
$caseInsensitiveSKU = 'configurableskuI22CaseInsensitive';
566+
$caseInsensitiveProduct = [
567+
'sku' => $caseInsensitiveSKU,
568+
'store_view_code' => null,
569+
'attribute_set_code' => 'Default',
570+
'product_type' => 'configurable',
571+
'name' => 'Configurable Product 21',
572+
'product_websites' => 'website_1',
573+
'configurable_variation_labels' => 'testattr2=Select Color, testattr3=Select Size',
574+
'configurable_variations' => 'SKU=testconf2-attr2val1-testattr3v1,'
575+
. 'testattr2=attr2val1,'
576+
. 'testattr3=testattr3v1,'
577+
. 'display=1|sku=testconf2-attr2val1-testattr3v2,'
578+
. 'testattr2=attr2val1,'
579+
. 'testattr3=testattr3v2,'
580+
. 'display=0',
581+
'_store' => null,
582+
'_attribute_set' => 'Default',
583+
'_type' => 'configurable',
584+
'_product_websites' => 'website_1',
585+
];
563586
$bunch[] = $badProduct;
587+
$bunch[] = $caseInsensitiveProduct;
564588
// Set _attributes to avoid error in Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType.
565589
$this->setPropertyValue($this->configurable, '_attributes', [
566590
$badProduct[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
567591
]);
592+
//Avoiding errors about attributes not being super
593+
$this->setPropertyValue(
594+
$this->configurable,
595+
'_superAttributes',
596+
[
597+
'testattr2' => ['options' => ['attr2val1' => 1]],
598+
'testattr3' => [
599+
'options' => [
600+
'testattr3v2' => 1,
601+
'testattr3v1' => 1,
602+
],
603+
],
604+
]
605+
);
568606

569607
foreach ($bunch as $rowData) {
570608
$result = $this->configurable->isRowValid($rowData, 0, !isset($this->_oldSku[$rowData['sku']]));
571609
$this->assertNotNull($result);
610+
if ($rowData['sku'] === $caseInsensitiveSKU) {
611+
$this->assertTrue($result);
612+
}
572613
}
573614
}
574615

app/code/Magento/ConfigurableProduct/view/base/templates/product/price/final_price.phtml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@ $finalPriceModel = $block->getPriceType('final_price');
1919
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
2020
$schema = ($block->getZone() == 'item_view') ? true : false;
2121
?>
22-
<?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
23-
<span class="special-price">
24-
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
25-
'display_label' => __('Special Price'),
26-
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
27-
'price_type' => 'finalPrice',
22+
23+
<span class="normal-price">
24+
<?php
25+
$arguments = [
26+
'display_label' => __('As low as'),
27+
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
28+
'price_type' => 'finalPrice',
2829
'include_container' => true,
2930
'schema' => $schema
30-
]); ?>
31-
</span>
31+
];
32+
33+
/* @noEscape */ echo $block->renderAmount($finalPriceModel->getAmount(), $arguments);
34+
?>
35+
</span>
36+
37+
<?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
3238
<span class="old-price sly-old-price no-display">
3339
<?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
3440
'display_label' => __('Regular Price'),
@@ -38,13 +44,6 @@ $schema = ($block->getZone() == 'item_view') ? true : false;
3844
'skip_adjustments' => true
3945
]); ?>
4046
</span>
41-
<?php else: ?>
42-
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
43-
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
44-
'price_type' => 'finalPrice',
45-
'include_container' => true,
46-
'schema' => $schema
47-
]); ?>
4847
<?php endif; ?>
4948

5049
<?php if ($block->showMinimalPrice()): ?>

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ define([
3232
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
3333
mediaGalleryInitial: null,
3434
slyOldPriceSelector: '.sly-old-price',
35+
normalPriceLabelSelector: '.normal-price .price-label',
3536

3637
/**
3738
* Defines the mechanism of how images of a gallery should be
@@ -269,6 +270,7 @@ define([
269270
this._reloadPrice();
270271
this._displayRegularPriceBlock(this.simpleProduct);
271272
this._displayTierPriceBlock(this.simpleProduct);
273+
this._displayNormalPriceLabel();
272274
this._changeProductImage();
273275
},
274276

@@ -527,8 +529,16 @@ define([
527529
* @private
528530
*/
529531
_displayRegularPriceBlock: function (optionId) {
530-
if (typeof optionId != 'undefined' &&
531-
this.options.spConfig.optionPrices[optionId].oldPrice.amount != //eslint-disable-line eqeqeq
532+
var shouldBeShown = true;
533+
534+
_.each(this.options.settings, function (element) {
535+
if (element.value === '') {
536+
shouldBeShown = false;
537+
}
538+
});
539+
540+
if (shouldBeShown &&
541+
this.options.spConfig.optionPrices[optionId].oldPrice.amount !==
532542
this.options.spConfig.optionPrices[optionId].finalPrice.amount
533543
) {
534544
$(this.options.slyOldPriceSelector).show();
@@ -537,6 +547,27 @@ define([
537547
}
538548
},
539549

550+
/**
551+
* Show or hide normal price label
552+
*
553+
* @private
554+
*/
555+
_displayNormalPriceLabel: function () {
556+
var shouldBeShown = false;
557+
558+
_.each(this.options.settings, function (element) {
559+
if (element.value === '') {
560+
shouldBeShown = true;
561+
}
562+
});
563+
564+
if (shouldBeShown) {
565+
$(this.options.normalPriceLabelSelector).show();
566+
} else {
567+
$(this.options.normalPriceLabelSelector).hide();
568+
}
569+
},
570+
540571
/**
541572
* Callback which fired after gallery gets initialized.
542573
*

app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ define([
268268
// tier prise selectors start
269269
tierPriceTemplateSelector: '#tier-prices-template',
270270
tierPriceBlockSelector: '[data-role="tier-price-block"]',
271-
tierPriceTemplate: ''
271+
tierPriceTemplate: '',
272272
// tier prise selectors end
273+
274+
// A price label selector
275+
normalPriceLabelSelector: '.normal-price .price-label'
273276
},
274277

275278
/**
@@ -930,6 +933,22 @@ define([
930933
} else {
931934
$(this.options.tierPriceBlockSelector).hide();
932935
}
936+
937+
$(this.options.normalPriceLabelSelector).hide();
938+
939+
_.each($('.' + this.options.classes.attributeOptionsWrapper), function (attribute) {
940+
if ($(attribute).find('.' + this.options.classes.optionClass + '.selected').length === 0) {
941+
if ($(attribute).find('.' + this.options.classes.selectClass).length > 0) {
942+
_.each($(attribute).find('.' + this.options.classes.selectClass), function (dropdown) {
943+
if ($(dropdown).val() === '0') {
944+
$(this.options.normalPriceLabelSelector).show();
945+
}
946+
}.bind(this));
947+
} else {
948+
$(this.options.normalPriceLabelSelector).show();
949+
}
950+
}
951+
}.bind(this));
933952
},
934953

935954
/**

0 commit comments

Comments
 (0)