Skip to content

Commit 4427d1a

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into PR-3
2 parents 409d750 + 91c7893 commit 4427d1a

File tree

19 files changed

+129
-64
lines changed

19 files changed

+129
-64
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Category/Tab/Product.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ protected function _prepareCollection()
104104
'sku'
105105
)->addAttributeToSelect(
106106
'price'
107-
)->addStoreFilter(
108-
$this->getRequest()->getParam('store')
109107
)->joinField(
110108
'position',
111109
'catalog_category_product',
@@ -114,6 +112,10 @@ protected function _prepareCollection()
114112
'category_id=' . (int)$this->getRequest()->getParam('id', 0),
115113
'left'
116114
);
115+
$storeId = (int)$this->getRequest()->getParam('store', 0);
116+
if ($storeId > 0) {
117+
$collection->addStoreFilter($storeId);
118+
}
117119
$this->setCollection($collection);
118120

119121
if ($this->getCategory()->getProductsReadonly()) {

app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public function execute()
6767
throw new \Exception(__('Category is not available for requested store.'));
6868
}
6969
$category->move($parentNodeId, $prevNodeId);
70-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
71-
$error = true;
72-
$this->messageManager->addError(__('There was a category move error.'));
7370
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
7471
$error = true;
7572
$this->messageManager->addError(__('There was a category move error. %1', $e->getMessage()));
73+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
74+
$error = true;
75+
$this->messageManager->addError($e->getMessage());
7676
} catch (\Exception $e) {
7777
$error = true;
7878
$this->messageManager->addError(__('There was a category move error.'));

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Exception\LocalizedException;
1011

1112
/**
1213
* @api
@@ -561,6 +562,7 @@ public function getSpecifyOptionMessage()
561562
* @param \Magento\Catalog\Model\Product $product
562563
* @param string $processMode
563564
* @return array
565+
* @throws LocalizedException
564566
*/
565567
protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $product, $processMode)
566568
{
@@ -571,20 +573,29 @@ protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $p
571573
$options = $product->getOptions();
572574
}
573575
if ($options !== null) {
576+
$results = [];
574577
foreach ($options as $option) {
575578
/* @var $option \Magento\Catalog\Model\Product\Option */
576-
$group = $option->groupFactory($option->getType())
577-
->setOption($option)
578-
->setProduct($product)
579-
->setRequest($buyRequest)
580-
->setProcessMode($processMode)
581-
->validateUserValue($buyRequest->getOptions());
579+
try {
580+
$group = $option->groupFactory($option->getType())
581+
->setOption($option)
582+
->setProduct($product)
583+
->setRequest($buyRequest)
584+
->setProcessMode($processMode)
585+
->validateUserValue($buyRequest->getOptions());
586+
} catch (LocalizedException $e) {
587+
$results[] = $e->getMessage();
588+
continue;
589+
}
582590

583591
$preparedValue = $group->prepareForCart();
584592
if ($preparedValue !== null) {
585593
$transport->options[$option->getId()] = $preparedValue;
586594
}
587595
}
596+
if (count($results) > 0) {
597+
throw new LocalizedException(__(implode("\n", $results)));
598+
}
588599
}
589600

590601
$eventName = sprintf('catalog_product_type_prepare_%s_options', $processMode);

app/code/Magento/Catalog/Model/ResourceModel/Product.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,17 +522,14 @@ public function duplicate($oldId, $newId)
522522
)->where(
523523
$this->getLinkField() . ' = ?',
524524
$oldId
525-
)->where(
526-
'store_id >= ?',
527-
0
528525
);
529526

530527
$connection->query(
531528
$connection->insertFromSelect(
532529
$select,
533530
$tableName,
534531
['attribute_id', 'store_id', $this->getLinkField(), 'value'],
535-
\Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
532+
\Magento\Framework\DB\Adapter\AdapterInterface::INSERT_IGNORE
536533
)
537534
);
538535
}
@@ -541,7 +538,6 @@ public function duplicate($oldId, $newId)
541538
$statusAttribute = $this->getAttribute('status');
542539
$statusAttributeId = $statusAttribute->getAttributeId();
543540
$statusAttributeTable = $statusAttribute->getBackend()->getTable();
544-
$updateCond[] = 'store_id >= 0';
545541
$updateCond[] = $connection->quoteInto($this->getLinkField() . ' = ?', $newId);
546542
$updateCond[] = $connection->quoteInto('attribute_id = ?', $statusAttributeId);
547543
$connection->update(

app/code/Magento/Catalog/Test/Unit/Model/Product/Gallery/GalleryManagementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testCreateWithCannotSaveException()
9797
$productSku = 'mediaProduct';
9898
$entryContentMock = $this->getMockBuilder('\Magento\Framework\Api\Data\ImageContentInterface')
9999
->disableOriginalConstructor()
100-
->getMock();;
100+
->getMock();
101101
$this->mediaGalleryEntryMock->expects($this->any())->method('getContent')->willReturn($entryContentMock);
102102
$this->productRepositoryMock->expects($this->once())
103103
->method('get')

app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/tree.phtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@
493493
} else {
494494
$(obj.tree.container.dom).trigger('categoryMove.tree');
495495
}
496+
$('.page-main-actions').next('.messages').remove();
497+
$('.page-main-actions').next('#messages').remove();
498+
$('.page-main-actions').after(data.messages);
496499
}).fail(function (jqXHR, textStatus) {
497500
if (window.console) {
498501
console.log(textStatus);

app/code/Magento/Catalog/view/frontend/templates/product/view/opengraph/general.phtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
?>
1111

1212
<meta property="og:type" content="og:product" />
13-
<meta property="og:title" content="<?php /* @escapeNotVerified */ echo $block->stripTags($block->getProduct()->getName()); ?>" />
14-
<meta property="og:image" content="<?php /* @escapeNotVerified */ echo $block->stripTags($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()); ?>" />
15-
<meta property="og:description" content="<?php /* @escapeNotVerified */ echo $block->stripTags($block->getProduct()->getShortDescription()); ?>" />
16-
<meta property="og:url" content="<?php /* @escapeNotVerified */ echo $block->stripTags($block->getProduct()->getProductUrl()); ?>" />
13+
<meta property="og:title" content="<?php echo $block->escapeHtml($block->getProduct()->getName()); ?>" />
14+
<meta property="og:image" content="<?php echo $block->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()); ?>" />
15+
<meta property="og:description" content="<?php echo $block->escapeHtml($block->getProduct()->getShortDescription()); ?>" />
16+
<meta property="og:url" content="<?php echo $block->escapeUrl($block->getProduct()->getProductUrl()); ?>" />
1717
<?php if ($priceAmount = $block->getProduct()->getFinalPrice()):?>
1818
<meta property="product:price:amount" content="<?php /* @escapeNotVerified */ echo $priceAmount; ?>"/>
1919
<?php echo $block->getChildHtml('meta.currency'); ?>

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ define([
4444
return this.options.processStart && this.options.processStop;
4545
},
4646

47-
submitForm: function(form) {
48-
var self = this;
47+
/**
48+
* Handler for the form 'submit' event
49+
*
50+
* @param {Object} form
51+
*/
52+
submitForm: function (form) {
53+
var addToCartButton, self = this;
54+
4955
if (form.has('input[type="file"]').length && form.find('input[type="file"]').val() !== '') {
5056
self.element.off('submit');
57+
// disable 'Add to Cart' button
58+
addToCartButton = $(form).find(this.options.addToCartButtonSelector);
59+
addToCartButton.prop('disabled', true);
60+
addToCartButton.addClass(this.options.addToCartButtonDisabledClass);
5161
form.submit();
5262
} else {
5363
self.ajaxSubmit(form);

app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,13 @@ protected function _getDefaultSourceModel()
593593
*/
594594
public function isValueEmpty($value)
595595
{
596-
$attrType = $this->getBackend()->getType();
597-
$isEmpty = (is_array($value) && count($value) == 0) ||
598-
$value === null ||
599-
$value === false && $attrType != 'int' ||
600-
$value === '' && ($attrType == 'int' ||
601-
$attrType == 'decimal' ||
602-
$attrType == 'datetime');
603-
604-
return $isEmpty;
596+
/** @var array $emptyStringTypes list of attribute types that treat empty string as a possible value */
597+
$emptyStringTypes = ['int', 'decimal', 'datetime', 'varchar', 'text'];
598+
$attributeType = $this->getBackend()->getType();
599+
return (is_array($value) && count($value) == 0)
600+
|| $value === null
601+
|| ($value === false && $attributeType != 'int')
602+
|| ($value === '' && in_array($attributeType, $emptyStringTypes));
605603
}
606604

607605
/**

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/AbstractAttributeTest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public function testGetOptionWhenOptionsAreSet()
3333
->with(['options'])
3434
->willReturn('expected value');
3535

36-
3736
$this->assertEquals('expected value', $model->getOptions());
3837
}
3938

@@ -175,4 +174,59 @@ public function testGetValidationRulesWhenRuleIsEmpty()
175174

176175
$this->assertEquals([], $model->getValidationRules());
177176
}
177+
178+
/**
179+
* @param bool $isEmpty
180+
* @param mixed $value
181+
* @param string $attributeType
182+
* @dataProvider attributeValueDataProvider
183+
*/
184+
public function testIsValueEmpty($isEmpty, $value, $attributeType)
185+
{
186+
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $model */
187+
$model = $this->getMockForAbstractClass(
188+
'\Magento\Eav\Model\Entity\Attribute\AbstractAttribute',
189+
[],
190+
'',
191+
false,
192+
false,
193+
true,
194+
[
195+
'getBackend'
196+
]
197+
);
198+
$backendModelMock = $this->getMockForAbstractClass(
199+
'\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend',
200+
[],
201+
'',
202+
false,
203+
false,
204+
true,
205+
[
206+
'getType'
207+
]
208+
);
209+
$backendModelMock->expects($this->any())->method('getType')->willReturn($attributeType);
210+
$model->expects($this->once())->method('getBackend')->willReturn($backendModelMock);
211+
$this->assertEquals($isEmpty, $model->isValueEmpty($value));
212+
}
213+
214+
/**
215+
* @return array
216+
*/
217+
public function attributeValueDataProvider()
218+
{
219+
return [
220+
[true, '', 'int'],
221+
[true, '', 'decimal'],
222+
[true, '', 'datetime'],
223+
[true, '', 'varchar'],
224+
[true, '', 'text'],
225+
[true, null, 'varchar'],
226+
[true, [], 'varchar'],
227+
[true, false, 'varchar'],
228+
[false, 'not empty value', 'varchar'],
229+
[false, false, 'int'],
230+
];
231+
}
178232
}

0 commit comments

Comments
 (0)