Skip to content

Commit 8bc4691

Browse files
committed
Merge pull request #563 from magento-folks/bugs
[Folks] Bugfixes
2 parents e60afa2 + 79b37e7 commit 8bc4691

File tree

6 files changed

+95
-21
lines changed

6 files changed

+95
-21
lines changed

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/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
}

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function saveActionDataProvider()
233233
'display_mode' => true,
234234
'meta_title' => true,
235235
'custom_design' => true,
236-
'page_layout' => true,
236+
'page_layout' => false,
237237
'is_active' => true,
238238
'include_in_menu' => true,
239239
'landing_page' => true,
@@ -242,7 +242,7 @@ public function saveActionDataProvider()
242242
'description' => true,
243243
'meta_keywords' => true,
244244
'meta_description' => true,
245-
'custom_layout_update' => true,
245+
'custom_layout_update' => false,
246246
'custom_design_from' => true,
247247
'custom_design_to' => true,
248248
'filter_price_range' => false

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ public function testPrepareForCartOptionsException()
190190
);
191191
$product = $repository->get('simple');
192192
// fixture
193-
$this->assertEquals(
193+
194+
$this->assertContains(
194195
'Please specify product\'s required option(s).',
195196
$this->_model->prepareForCart(new \Magento\Framework\DataObject(), $product)
196197
);

0 commit comments

Comments
 (0)