diff --git a/app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php b/app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php
index 6bd6e5e1209bf..5c2fbabbaf297 100644
--- a/app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php
+++ b/app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php
@@ -124,7 +124,7 @@ public function getValue()
$value = $product->getData('final_price') * ($selectionPriceValue / 100);
} else {
// calculate price for selection type fixed
- $value = $this->priceCurrency->convert($selectionPriceValue) * $this->quantity;
+ $value = $this->priceCurrency->convert($selectionPriceValue);
}
}
if (!$this->useRegularPrice) {
diff --git a/app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionPriceTest.php b/app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionPriceTest.php
index 5345cd4b424b1..5b14e59fd9084 100644
--- a/app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionPriceTest.php
+++ b/app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionPriceTest.php
@@ -66,18 +66,13 @@ class BundleSelectionPriceTest extends \PHPUnit_Framework_TestCase
*/
protected $priceCurrencyMock;
- /**
- * @var float
- */
- protected $quantity;
-
/**
* Test setUp
*/
protected function setUp()
{
$this->productMock = $this->getMock(
- 'Magento\Catalog\Model\Product',
+ \Magento\Catalog\Model\Product::class,
['__wakeup', 'getPriceInfo', 'getSelectionPriceType', 'getSelectionPriceValue'],
[],
'',
@@ -85,44 +80,44 @@ protected function setUp()
);
$this->bundleMock = $this->getMock(
- 'Magento\Catalog\Model\Product',
+ \Magento\Catalog\Model\Product::class,
['__wakeup', 'getPriceType', 'getPriceInfo', 'setFinalPrice', 'getData'],
[],
'',
false
);
- $this->calculatorMock = $this->getMockBuilder('Magento\Framework\Pricing\Adjustment\CalculatorInterface')
+ $this->calculatorMock = $this->getMockBuilder(\Magento\Framework\Pricing\Adjustment\CalculatorInterface::class)
->getMockForAbstractClass();
$this->eventManagerMock = $this->getMock(
- 'Magento\Framework\Event\Manager',
+ \Magento\Framework\Event\Manager::class,
['dispatch'],
[],
'',
false
);
$this->priceInfoMock = $this->getMock(
- 'Magento\Framework\Pricing\PriceInfo\Base',
+ \Magento\Framework\Pricing\PriceInfo\Base::class,
['getPrice'],
[],
'',
false
);
$this->discountCalculatorMock = $this->getMock(
- 'Magento\Bundle\Pricing\Price\DiscountCalculator',
+ \Magento\Bundle\Pricing\Price\DiscountCalculator::class,
[],
[],
'',
false
);
$this->finalPriceMock = $this->getMock(
- 'Magento\Catalog\Pricing\Price\FinalPrice',
+ \Magento\Catalog\Pricing\Price\FinalPrice::class,
[],
[],
'',
false
);
$this->regularPriceMock = $this->getMock(
- 'Magento\Catalog\Pricing\Price\RegularPrice',
+ \Magento\Catalog\Pricing\Price\RegularPrice::class,
[],
[],
'',
@@ -132,18 +127,16 @@ protected function setUp()
->method('getPriceInfo')
->will($this->returnValue($this->priceInfoMock));
- $this->priceCurrencyMock = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface');
-
- $this->quantity = 1;
+ $this->priceCurrencyMock = $this->getMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
$this->setupSelectionPrice();
}
- protected function setupSelectionPrice($useRegularPrice = false)
+ protected function setupSelectionPrice($useRegularPrice = false, $qty = 1)
{
$this->selectionPrice = new \Magento\Bundle\Pricing\Price\BundleSelectionPrice(
$this->productMock,
- $this->quantity,
+ $qty,
$this->calculatorMock,
$this->priceCurrencyMock,
$this->bundleMock,
@@ -313,6 +306,58 @@ public function testGetValueTypeFixedWithoutSelectionPriceType($useRegularPrice)
$this->assertEquals($expectedPrice, $this->selectionPrice->getValue());
}
+ /**
+ * Test for method getValue with type Fixed and selectionPriceType is empty or zero.
+ *
+ * @param bool $useRegularPrice
+ * @return void
+ *
+ * @dataProvider useRegularPriceDataProvider
+ */
+ public function testFixedPriceWithMultipleQty($useRegularPrice)
+ {
+ $qty = 2;
+
+ $this->setupSelectionPrice($useRegularPrice, $qty);
+ $regularPrice = 100.125;
+ $discountedPrice = 70.453;
+ $convertedValue = 100.247;
+ $actualPrice = $useRegularPrice ? $convertedValue : $discountedPrice;
+ $expectedPrice = $useRegularPrice ? round($convertedValue, 2) : round($discountedPrice, 2);
+
+ $this->bundleMock->expects($this->once())
+ ->method('getPriceType')
+ ->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED));
+ $this->productMock->expects($this->once())
+ ->method('getSelectionPriceType')
+ ->will($this->returnValue(false));
+ $this->productMock->expects($this->any())
+ ->method('getSelectionPriceValue')
+ ->will($this->returnValue($regularPrice));
+
+ $this->priceCurrencyMock->expects($this->once())
+ ->method('convert')
+ ->with($regularPrice)
+ ->will($this->returnValue($convertedValue));
+
+ if (!$useRegularPrice) {
+ $this->discountCalculatorMock->expects($this->once())
+ ->method('calculateDiscount')
+ ->with(
+ $this->equalTo($this->bundleMock),
+ $this->equalTo($convertedValue)
+ )
+ ->will($this->returnValue($discountedPrice));
+ }
+
+ $this->priceCurrencyMock->expects($this->once())
+ ->method('round')
+ ->with($actualPrice)
+ ->will($this->returnValue($expectedPrice));
+
+ $this->assertEquals($expectedPrice, $this->selectionPrice->getValue());
+ }
+
public function useRegularPriceDataProvider()
{
return [
diff --git a/app/code/Magento/Bundle/view/base/web/js/price-bundle.js b/app/code/Magento/Bundle/view/base/web/js/price-bundle.js
index 5b8b18cfffe5c..f2103416b7a92 100644
--- a/app/code/Magento/Bundle/view/base/web/js/price-bundle.js
+++ b/app/code/Magento/Bundle/view/base/web/js/price-bundle.js
@@ -55,7 +55,6 @@ define([
this._setOption('priceFormat', priceBox.priceBox('option').priceConfig.priceFormat);
priceBox.priceBox('setDefault', this.options.optionConfig.prices);
}
- this._applyQtyFix();
this._applyOptionNodeFix(options);
options.on('change', this._onBundleOptionChanged.bind(this));
diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes/Listing.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes/Listing.php
index c2fc471a4b6f4..91e73ea6e4189 100644
--- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes/Listing.php
+++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Attributes/Listing.php
@@ -41,7 +41,6 @@ public function __construct(
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->request = $request;
$this->collection = $collectionFactory->create();
- $this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
}
/**
@@ -49,6 +48,9 @@ public function __construct(
*/
public function getData()
{
+ $this->collection->setExcludeSetFilter((int)$this->request->getParam('template_id', 0));
+ $this->collection->getSelect()->setPart('order', []);
+
$items = [];
foreach ($this->getCollection()->getItems() as $attribute) {
$items[] = $attribute->toArray();
diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php
index bdc73b8fb22f7..a6abc09a8ff77 100644
--- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php
+++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php
@@ -1418,7 +1418,7 @@ protected function initMediaGalleryResources()
}
/**
- * Get existing images for current bucnh
+ * Get existing images for current bunch.
*
* @param array $bunch
* @return array
@@ -1438,7 +1438,21 @@ protected function getExistingImages($bunch)
)->joinInner(
['mgvte' => $this->mediaGalleryEntityToValueTableName],
'(mg.value_id = mgvte.value_id)',
- [$this->getProductEntityLinkField() => 'mgvte.' . $this->getProductEntityLinkField()]
+ [
+ $this->getProductEntityLinkField() => 'mgvte.' . $this->getProductEntityLinkField(),
+ 'value_id' => 'mgvte.value_id',
+ ]
+ )->joinLeft(
+ ['mgv' => $this->mediaGalleryValueTableName],
+ sprintf(
+ '(mg.value_id = mgv.value_id AND mgv.%s = mgvte.%s AND mgv.store_id = %d)',
+ $this->getProductEntityLinkField(),
+ $this->getProductEntityLinkField(),
+ \Magento\Store\Model\Store::DEFAULT_STORE_ID
+ ),
+ [
+ 'label' => 'mgv.label',
+ ]
)->joinInner(
['pe' => $this->productEntityTableName],
"(mgvte.{$this->getProductEntityLinkField()} = pe.{$this->getProductEntityLinkField()})",
@@ -1449,7 +1463,7 @@ protected function getExistingImages($bunch)
);
foreach ($this->_connection->fetchAll($select) as $image) {
- $result[$image['sku']][$image['value']] = true;
+ $result[$image['sku']][$image['value']] = $image;
}
return $result;
@@ -1464,22 +1478,21 @@ public function getImagesFromRow(array $rowData)
$images = [];
$labels = [];
foreach ($this->_imagesArrayKeys as $column) {
- $images[$column] = [];
- $labels[$column] = [];
if (!empty($rowData[$column])) {
$images[$column] = array_unique(
- explode($this->getMultipleValueSeparator(), $rowData[$column])
+ array_map(
+ 'trim',
+ explode($this->getMultipleValueSeparator(), $rowData[$column])
+ )
);
- }
- if (!empty($rowData[$column . '_label'])) {
- $labels[$column] = explode($this->getMultipleValueSeparator(), $rowData[$column . '_label']);
- }
+ if (!empty($rowData[$column . '_label'])) {
+ $labels[$column] = $this->parseMultipleValues($rowData[$column . '_label']);
- if (count($labels[$column]) > count($images[$column])) {
- $labels[$column] = array_slice($labels[$column], 0, count($images[$column]));
- } elseif (count($labels[$column]) < count($images[$column])) {
- $labels[$column] = array_pad($labels[$column], count($images[$column]), '');
+ if (count($labels[$column]) > count($images[$column])) {
+ $labels[$column] = array_slice($labels[$column], 0, count($images[$column]));
+ }
+ }
}
}
@@ -1509,6 +1522,7 @@ protected function _saveProducts()
$this->categoriesCache = [];
$tierPrices = [];
$mediaGallery = [];
+ $labelsForUpdate = [];
$uploadedImages = [];
$previousType = null;
$prevAttributeSet = null;
@@ -1624,7 +1638,7 @@ protected function _saveProducts()
foreach ($rowImages as $column => $columnImages) {
foreach ($columnImages as $columnImageKey => $columnImage) {
if (!isset($uploadedImages[$columnImage])) {
- $uploadedFile = $this->uploadMediaFiles(trim($columnImage), true);
+ $uploadedFile = $this->uploadMediaFiles($columnImage, true);
if ($uploadedFile) {
$uploadedImages[$columnImage] = $uploadedFile;
} else {
@@ -1644,22 +1658,30 @@ protected function _saveProducts()
$rowData[$column] = $uploadedFile;
}
- $imageNotAssigned = !isset($existingImages[$rowSku][$uploadedFile]);
-
- if ($uploadedFile && $imageNotAssigned) {
- if ($column == self::COL_MEDIA_IMAGE) {
- $rowData[$column][] = $uploadedFile;
+ if ($uploadedFile && !isset($mediaGallery[$rowSku][$uploadedFile])) {
+ if (isset($existingImages[$rowSku][$uploadedFile])) {
+ if (isset($rowLabels[$column][$columnImageKey])
+ && $rowLabels[$column][$columnImageKey]
+ != $existingImages[$rowSku][$uploadedFile]['label']
+ ) {
+ $labelsForUpdate[] = [
+ 'label' => $rowLabels[$column][$columnImageKey],
+ 'imageData' => $existingImages[$rowSku][$uploadedFile]
+ ];
+ }
+ } else {
+ if ($column == self::COL_MEDIA_IMAGE) {
+ $rowData[$column][] = $uploadedFile;
+ }
+ $mediaGallery[$rowSku][$uploadedFile] = [
+ 'attribute_id' => $this->getMediaGalleryAttributeId(),
+ 'label' => isset($rowLabels[$column][$columnImageKey])
+ ? $rowLabels[$column][$columnImageKey] : '',
+ 'position' => ++$position,
+ 'disabled' => isset($disabledImages[$columnImage]) ? '1' : '0',
+ 'value' => $uploadedFile,
+ ];
}
- $label = isset($rowLabels[$column][$columnImageKey]) ?
- $rowLabels[$column][$columnImageKey] : '';
- $mediaGallery[$rowSku][] = [
- 'attribute_id' => $this->getMediaGalleryAttributeId(),
- 'label' => $label,
- 'position' => ++$position,
- 'disabled' => isset($disabledImages[$columnImage]) ? '1' : '0',
- 'value' => $uploadedFile,
- ];
- $existingImages[$rowSku][$uploadedFile] = true;
}
}
}
@@ -1777,6 +1799,8 @@ protected function _saveProducts()
$mediaGallery
)->_saveProductAttributes(
$attributes
+ )->updateMediaGalleryLabels(
+ $labelsForUpdate
);
$this->_eventManager->dispatch(
@@ -2263,9 +2287,7 @@ public function validateRow(array $rowData, $rowNum)
$this->_processedEntitiesCount++;
$sku = $rowData[self::COL_SKU];
-
- $isNewProduct = !isset($this->_oldSku[$sku]) || (Import::BEHAVIOR_REPLACE == $this->getBehavior());
- if (!$isNewProduct) {
+ if (isset($this->_oldSku[$sku]) && Import::BEHAVIOR_REPLACE !== $this->getBehavior()) {
// can we get all necessary data from existent DB product?
// check for supported type of existing product
if (isset($this->_productTypeModels[$this->_oldSku[$sku]['type_id']])) {
@@ -2315,7 +2337,7 @@ public function validateRow(array $rowData, $rowNum)
$rowAttributesValid = $this->_productTypeModels[$newSku['type_id']]->isRowValid(
$rowData,
$rowNum,
- $isNewProduct
+ !(isset($this->_oldSku[$sku]) && Import::BEHAVIOR_REPLACE !== $this->getBehavior())
);
if (!$rowAttributesValid && self::SCOPE_DEFAULT == $rowScope) {
// mark SCOPE_DEFAULT row as invalid for future child rows if product not in DB already
@@ -2484,18 +2506,20 @@ private function parseAttributesWithWrappedValues($attributesData)
* Parse values of multiselect attributes depends on "Fields Enclosure" parameter
*
* @param string $values
+ * @param string $delimiter
* @return array
*/
- public function parseMultiselectValues($values)
+ public function parseMultiselectValues($values, $delimiter = self::PSEUDO_MULTI_LINE_SEPARATOR)
{
if (empty($this->_parameters[Import::FIELDS_ENCLOSURE])) {
- return explode(self::PSEUDO_MULTI_LINE_SEPARATOR, $values);
+ return explode($delimiter, $values);
}
if (preg_match_all('~"((?:[^"]|"")*)"~', $values, $matches)) {
return $values = array_map(function ($value) {
return str_replace('""', '"', $value);
}, $matches[1]);
}
+
return [$values];
}
@@ -2771,4 +2795,64 @@ private function formatBunchToStockDataRows(
$indexer->reindexList($productIdsToReindex);
}
}
+
+ /**
+ * Update media gallery labels.
+ *
+ * @param array $labels
+ * @return void
+ */
+ private function updateMediaGalleryLabels(array $labels)
+ {
+ if (empty($labels)) {
+ return;
+ }
+
+ $insertData = [];
+ foreach ($labels as $label) {
+ $imageData = $label['imageData'];
+
+ if ($imageData['label'] === null) {
+ $insertData[] = [
+ 'label' => $label['label'],
+ $this->getProductEntityLinkField() => $imageData[$this->getProductEntityLinkField()],
+ 'value_id' => $imageData['value_id'],
+ 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
+ ];
+ } else {
+ $this->_connection->update(
+ $this->mediaGalleryValueTableName,
+ [
+ 'label' => $label['label'],
+ ],
+ [
+ $this->getProductEntityLinkField() . ' = ?' => $imageData[$this->getProductEntityLinkField()],
+ 'value_id = ?' => $imageData['value_id'],
+ 'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
+ ]
+ );
+ }
+ }
+
+ if (!empty($insertData)) {
+ $this->_connection->insertMultiple(
+ $this->mediaGalleryValueTableName,
+ $insertData
+ );
+ }
+ }
+
+ /**
+ * Parse values from multiple attributes fields.
+ *
+ * @param string $labelRow
+ * @return array
+ */
+ private function parseMultipleValues($labelRow)
+ {
+ return $this->parseMultiselectValues(
+ $labelRow,
+ $this->getMultipleValueSeparator()
+ );
+ }
}
diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Media.php b/app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Media.php
index 45aae81ff4bf9..4f64355f3b646 100644
--- a/app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Media.php
+++ b/app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Media.php
@@ -5,7 +5,6 @@
*/
namespace Magento\CatalogImportExport\Model\Import\Product\Validator;
-use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator;
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
class Media extends AbstractImportValidator implements RowValidatorInterface
@@ -15,7 +14,11 @@ class Media extends AbstractImportValidator implements RowValidatorInterface
const PATH_REGEXP = '#^(?!.*[\\/]\.{2}[\\/])(?!\.{2}[\\/])[-\w.\\/]+$#';
const ADDITIONAL_IMAGES = 'additional_images';
-
+
+ /**
+ * @deprecated
+ * @see \Magento\CatalogImportExport\Model\Import\Product::getMultipleValueSeparator()
+ */
const ADDITIONAL_IMAGES_DELIMITER = ',';
/** @var array */
@@ -83,7 +86,7 @@ public function isValid($value)
}
}
if (isset($value[self::ADDITIONAL_IMAGES]) && strlen($value[self::ADDITIONAL_IMAGES])) {
- foreach (explode(self::ADDITIONAL_IMAGES_DELIMITER, $value[self::ADDITIONAL_IMAGES]) as $image) {
+ foreach (explode($this->context->getMultipleValueSeparator(), $value[self::ADDITIONAL_IMAGES]) as $image) {
if (!$this->checkPath($image) && !$this->checkValidUrl($image)) {
$this->_addMessages(
[
diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/MediaTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/MediaTest.php
index 501ff53b3e6d4..5033bd1b14776 100644
--- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/MediaTest.php
+++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/MediaTest.php
@@ -6,11 +6,14 @@
namespace Magento\CatalogImportExport\Test\Unit\Model\Import\Product\Validator;
+use Magento\CatalogImportExport\Model\Import\Product;
+use Magento\CatalogImportExport\Model\Import\Product\Validator\Media;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
+use Magento\ImportExport\Model\Import;
class MediaTest extends \PHPUnit_Framework_TestCase
{
- /** @var \Magento\CatalogImportExport\Model\Import\Product\Validator\Media */
+ /** @var Media */
protected $media;
/** @var ObjectManagerHelper */
@@ -21,10 +24,8 @@ protected function setUp()
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->media = $this->objectManagerHelper->getObject(
- 'Magento\CatalogImportExport\Model\Import\Product\Validator\Media',
- [
-
- ]
+ Media::class,
+ []
);
}
@@ -41,6 +42,18 @@ public function testInit()
*/
public function testIsValid($data, $expected)
{
+ $contextMock = $this->getMockBuilder(Product::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $contextMock->expects($this->any())
+ ->method('getMultipleValueSeparator')
+ ->willReturn(Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR);
+ $contextMock->expects($this->any())
+ ->method('retrieveMessageTemplate')
+ ->with(Media::ERROR_INVALID_MEDIA_URL_OR_PATH)
+ ->willReturn('%s');
+ $this->media->init($contextMock);
+
$result = $this->media->isValid($data);
$this->assertEquals($expected['result'], $result);
$messages = $this->media->getMessages();
@@ -50,7 +63,7 @@ public function testIsValid($data, $expected)
public function testIsValidClearMessagesCall()
{
$media = $this->getMock(
- '\Magento\CatalogImportExport\Model\Import\Product\Validator\Media',
+ Media::class,
['_clearMessages'],
[],
'',
@@ -78,7 +91,15 @@ public function isMediaValidDataProvider()
'invalid' => [
['_media_image' => 1],
['result' => true,'messages' => []],
- ]
+ ],
+ 'additional_images' => [
+ ['additional_images' => 'image1.png,image2.jpg'],
+ ['result' => true, 'messages' => []],
+ ],
+ 'additional_images_fail' => [
+ ['additional_images' => 'image1.png|image2.jpg|image3.gif'],
+ ['result' => false, 'messages' => [0 => 'additional_images']],
+ ],
];
}
}
diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php
index a6d27eb557eef..349bc51b9b541 100644
--- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php
+++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php
@@ -1278,6 +1278,46 @@ public function testValidateValidateOptionEntity()
$importProduct->validateRow($rowData, $rowNum);
}
+ /**
+ * @dataProvider getImagesFromRowDataProvider
+ */
+ public function testGetImagesFromRow($rowData, $expectedResult)
+ {
+ $this->assertEquals(
+ $this->importProduct->getImagesFromRow($rowData),
+ $expectedResult
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function getImagesFromRowDataProvider()
+ {
+ return [
+ [
+ [],
+ [[], []],
+ ],
+ [
+ [
+ 'image' => 'image3.jpg',
+ '_media_image' => 'image1.jpg,image2.png',
+ '_media_image_label' => 'label1,label2',
+ ],
+ [
+ [
+ 'image' => ['image3.jpg'],
+ '_media_image' => ['image1.jpg', 'image2.png'],
+ ],
+ [
+ '_media_image' => ['label1', 'label2'],
+ ],
+ ],
+ ],
+ ];
+ }
+
public function validateRowValidateNewProductTypeAddRowErrorCallDataProvider()
{
return [
diff --git a/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js b/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js
index 3c8027e053914..cff1212cb7dda 100644
--- a/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js
+++ b/app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js
@@ -12,9 +12,8 @@ define(
function ($) {
'use strict';
var checkoutConfig = window.checkoutConfig,
- agreementsConfig = checkoutConfig ? checkoutConfig.checkoutAgreements : {};
-
- var agreementsInputPath = '.payment-method._active div.checkout-agreements input';
+ agreementsConfig = checkoutConfig ? checkoutConfig.checkoutAgreements : {},
+ agreementsInputPath = '.payment-method._active div.checkout-agreements input';
return {
/**
@@ -23,26 +22,11 @@ define(
* @returns {boolean}
*/
validate: function() {
- if (!agreementsConfig.isEnabled) {
- return true;
- }
-
- if ($(agreementsInputPath).length == 0) {
+ if (!agreementsConfig.isEnabled || $(agreementsInputPath).length == 0) {
return true;
}
- return $('#co-payment-form').validate({
- errorClass: 'mage-error',
- errorElement: 'div',
- meta: 'validate',
- errorPlacement: function (error, element) {
- var errorPlacement = element;
- if (element.is(':checkbox') || element.is(':radio')) {
- errorPlacement = element.siblings('label').last();
- }
- errorPlacement.after(error);
- }
- }).element(agreementsInputPath);
+ return $.validator.validateSingleElement(agreementsInputPath, {errorElement: 'div'});
}
}
}
diff --git a/app/code/Magento/CheckoutAgreements/view/frontend/web/template/checkout/checkout-agreements.html b/app/code/Magento/CheckoutAgreements/view/frontend/web/template/checkout/checkout-agreements.html
index 3958822fbb788..6008530da13aa 100644
--- a/app/code/Magento/CheckoutAgreements/view/frontend/web/template/checkout/checkout-agreements.html
+++ b/app/code/Magento/CheckoutAgreements/view/frontend/web/template/checkout/checkout-agreements.html
@@ -8,14 +8,13 @@
-
-
+
+ }"/>