Skip to content

Commit 32ec76e

Browse files
author
Ganin, Roman(rganin)
committed
Merge pull request #234 from magento-troll/bugfix_s47
[Troll] Bugfixes S47
2 parents d391b29 + 993d62f commit 32ec76e

File tree

22 files changed

+341
-121
lines changed

22 files changed

+341
-121
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/File/Validator.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ protected function getValidatorErrors($errors, $fileInfo, $option)
100100
$this->fileSize->getMaxFileSizeInMb()
101101
);
102102
break;
103+
case \Zend_Validate_File_ImageSize::NOT_DETECTED:
104+
$result[] = __(
105+
"The file '%1' is empty. Please choose another one",
106+
$fileInfo['title']
107+
);
108+
break;
109+
default:
110+
$result[] = __(
111+
"The file '%1' is invalid. Please choose another one",
112+
$fileInfo['title']
113+
);
103114
}
104115
}
105116
return $result;

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,30 @@ class ValidatorFile extends Validator
5757
*/
5858
protected $product;
5959

60+
/**
61+
* @var \Magento\Framework\Validator\File\IsImage
62+
*/
63+
protected $isImageValidator;
64+
6065
/**
6166
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
6267
* @param \Magento\Framework\Filesystem $filesystem
6368
* @param \Magento\Framework\File\Size $fileSize
6469
* @param \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory
70+
* @param \Magento\Framework\Validator\File\IsImage $isImageValidator
6571
* @throws \Magento\Framework\Exception\FileSystemException
6672
*/
6773
public function __construct(
6874
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
6975
\Magento\Framework\Filesystem $filesystem,
7076
\Magento\Framework\File\Size $fileSize,
71-
\Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory
77+
\Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory,
78+
\Magento\Framework\Validator\File\IsImage $isImageValidator
7279
) {
7380
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
7481
$this->filesystem = $filesystem;
7582
$this->httpFactory = $httpFactory;
83+
$this->isImageValidator = $isImageValidator;
7684
parent::__construct($scopeConfig, $filesystem, $fileSize);
7785
}
7886

@@ -169,8 +177,15 @@ public function validate($processingParams, $option)
169177
$_height = 0;
170178

171179
if ($tmpDirectory->isReadable($tmpDirectory->getRelativePath($fileInfo['tmp_name']))) {
172-
$imageSize = getimagesize($fileInfo['tmp_name']);
173-
if ($imageSize) {
180+
if (filesize($fileInfo['tmp_name'])) {
181+
if ($this->isImageValidator->isValid($fileInfo['tmp_name'])) {
182+
$imageSize = getimagesize($fileInfo['tmp_name']);
183+
}
184+
} else {
185+
throw new LocalizedException(__('The file is empty. Please choose another one'));
186+
}
187+
188+
if (!empty($imageSize)) {
174189
$_width = $imageSize[0];
175190
$_height = $imageSize[1];
176191
}

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,4 @@ Autosettings,Autosettings
699699
"Allow Gift Message","Allow Gift Message"
700700
"Meta Title","Meta Title"
701701
"Maximum 255 chars","Maximum 255 chars"
702+
"The file is empty. Please choose another one","The file is empty. Please choose another one"

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/composite/fieldset/options/type/file.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ require(['prototype'], function(){
6868
</label>
6969
<div class="admin__field-control control">
7070
<?php if ($_fileExists): ?>
71-
<span class="<?php /* @escapeNotVerified */ echo $_fileNamed ?>"><?php /* @escapeNotVerified */ echo $_fileInfo->getTitle(); ?></span>
71+
<span class="<?php /* @noEscape */ echo $_fileNamed ?>"><?php echo $block->escapeHtml($_fileInfo->getTitle()); ?></span>
7272
<a href="javascript:void(0)" class="label" onclick="opFile<?php /* @escapeNotVerified */ echo $_rand; ?>.toggleFileChange($(this).next('.input-box'))">
7373
<?php /* @escapeNotVerified */ echo __('Change') ?>
7474
</a>&nbsp;
@@ -79,7 +79,7 @@ require(['prototype'], function(){
7979
<?php endif; ?>
8080
<div class="input-box" <?php echo $_fileExists ? 'style="display:none"' : '' ?>>
8181
<!-- ToDo UI: add appropriate file class when z-index issue in ui dialog will be resolved -->
82-
<input type="file" name="<?php /* @escapeNotVerified */ echo $_fileName; ?>" class="product-custom-option<?php echo $_option->getIsRequire() ? ' required-entry' : '' ?>" price="<?php /* @escapeNotVerified */ echo $block->getCurrencyPrice($_option->getPrice(true)) ?>" <?php echo $_fileExists ? 'disabled="disabled"' : '' ?>/>
82+
<input type="file" name="<?php /* @noEscape */ echo $_fileName; ?>" class="product-custom-option<?php echo $_option->getIsRequire() ? ' required-entry' : '' ?>" price="<?php /* @escapeNotVerified */ echo $block->getCurrencyPrice($_option->getPrice(true)) ?>" <?php echo $_fileExists ? 'disabled="disabled"' : '' ?>/>
8383
<input type="hidden" name="<?php /* @escapeNotVerified */ echo $_fieldNameAction; ?>" value="<?php /* @escapeNotVerified */ echo $_fieldValueAction; ?>" />
8484

8585
<?php if ($_option->getFileExtension()): ?>

app/code/Magento/Catalog/view/frontend/templates/product/view/options/type/file.phtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
<?php $class = ($_option->getIsRequire()) ? ' required' : ''; ?>
1818

1919
<div class="field file<?php /* @escapeNotVerified */ echo $class; ?>">
20-
<label class="label" for="<?php /* @escapeNotVerified */ echo $_fileName; ?>" id="<?php /* @escapeNotVerified */ echo $_fileName; ?>-label">
20+
<label class="label" for="<?php /* @noEscape */ echo $_fileName; ?>" id="<?php /* @noEscape */ echo $_fileName; ?>-label">
2121
<span><?php echo $block->escapeHtml($_option->getTitle()) ?></span>
2222
<?php /* @escapeNotVerified */ echo $block->getFormatedPrice() ?>
2323
</label>
2424
<?php if ($_fileExists): ?>
2525
<div class="control">
26-
<span class="<?php /* @escapeNotVerified */ echo $_fileNamed ?>"><?php /* @escapeNotVerified */ echo $_fileInfo->getTitle(); ?></span>
27-
<a href="javascript:void(0)" class="label" id="change-<?php /* @escapeNotVerified */ echo $_fileName ?>" >
26+
<span class="<?php /* @noEscape */ echo $_fileNamed ?>"><?php echo $block->escapeHtml($_fileInfo->getTitle()); ?></span>
27+
<a href="javascript:void(0)" class="label" id="change-<?php /* @noEscape */ echo $_fileName ?>" >
2828
<?php /* @escapeNotVerified */ echo __('Change') ?>
2929
</a>
3030
<?php if (!$_option->getIsRequire()): ?>
@@ -35,8 +35,8 @@
3535
<?php endif; ?>
3636
<div class="control" id="input-box-<?php /* @escapeNotVerified */ echo $_fileName ?>"
3737
data-mage-init='{"priceOptionFile":{
38-
"fileName":"<?php /* @escapeNotVerified */ echo $_fileName ?>",
39-
"fileNamed":"<?php /* @escapeNotVerified */ echo $_fileNamed ?>",
38+
"fileName":"<?php /* @noEscape */ echo $_fileName ?>",
39+
"fileNamed":"<?php /* @noEscape */ echo $_fileNamed ?>",
4040
"fieldNameAction":"<?php /* @escapeNotVerified */ echo $_fieldNameAction ?>",
4141
"changeFileSelector":"#change-<?php /* @escapeNotVerified */ echo $_fileName ?>",
4242
"deleteFileSelector":"#delete-<?php /* @escapeNotVerified */ echo $_fileName ?>"}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogRule\Plugin\Indexer\Product\Save;
7+
8+
use Magento\CatalogRule\Model\Indexer\Product\ProductRuleProcessor;
9+
10+
class ApplyRulesAfterReindex
11+
{
12+
/**
13+
* @var ProductRuleProcessor
14+
*/
15+
protected $productRuleProcessor;
16+
17+
/**
18+
* @param ProductRuleProcessor $productRuleProcessor
19+
*/
20+
public function __construct(ProductRuleProcessor $productRuleProcessor)
21+
{
22+
$this->productRuleProcessor = $productRuleProcessor;
23+
}
24+
25+
/**
26+
* Apply catalog rules after product resource model save
27+
*
28+
* @param \Magento\Catalog\Model\Product $subject
29+
* @param callable $proceed
30+
* @return \Magento\Catalog\Model\Product
31+
*/
32+
public function aroundReindex(
33+
\Magento\Catalog\Model\Product $subject,
34+
callable $proceed
35+
) {
36+
$proceed();
37+
$this->productRuleProcessor->reindexRow($subject->getId());
38+
return;
39+
}
40+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Catalog\Model\Product">
10+
<plugin name="apply_catalog_rules_after_product_save_and_reindex" type="Magento\CatalogRule\Plugin\Indexer\Product\Save\ApplyRulesAfterReindex"/>
11+
</type>
12+
</config>

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddedProductAttributeOnProductForm.php

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Test\Fixture\CatalogAttributeSet;
1010
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
1111
use Magento\Mtf\Fixture\InjectableFixture;
12+
use Magento\Mtf\Fixture\FixtureFactory;
1213
use Magento\Mtf\Constraint\AbstractConstraint;
1314
use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
1415
use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
@@ -20,13 +21,35 @@
2021
*/
2122
class AssertAddedProductAttributeOnProductForm extends AbstractConstraint
2223
{
24+
/**
25+
* Fixture factory.
26+
*
27+
* @var FixtureFactory
28+
*/
29+
protected $fixtureFactory;
30+
31+
/**
32+
* Catalog Product Index page.
33+
*
34+
* @var CatalogProductIndex
35+
*/
36+
protected $catalogProductIndex;
37+
38+
/**
39+
* Catalog Product Edit page.
40+
*
41+
* @var CatalogProductEdit
42+
*/
43+
protected $catalogProductEdit;
44+
2345
/**
2446
* Add this attribute to Default attribute Template. Create product and Assert that created attribute
2547
* is displayed on product form (Products > Inventory > Catalog).
2648
*
2749
* @param InjectableFixture $product
28-
* @param CatalogProductIndex $productGrid
29-
* @param CatalogProductEdit $productEdit
50+
* @param FixtureFactory $fixtureFactory
51+
* @param CatalogProductIndex $catalogProductIndex
52+
* @param CatalogProductEdit $catalogProductEdit
3053
* @param CatalogProductAttribute $attribute
3154
* @param CatalogAttributeSet $attributeSet
3255
* @param CatalogProductAttribute $productAttributeOriginal
@@ -35,47 +58,44 @@ class AssertAddedProductAttributeOnProductForm extends AbstractConstraint
3558
*/
3659
public function processAssert(
3760
InjectableFixture $product,
38-
CatalogProductIndex $productGrid,
39-
CatalogProductEdit $productEdit,
61+
FixtureFactory $fixtureFactory,
62+
CatalogProductIndex $catalogProductIndex,
63+
CatalogProductEdit $catalogProductEdit,
4064
CatalogProductAttribute $attribute,
4165
CatalogAttributeSet $attributeSet,
4266
CatalogProductAttribute $productAttributeOriginal = null
4367
) {
68+
$this->fixtureFactory = $fixtureFactory;
69+
$this->catalogProductIndex = $catalogProductIndex;
70+
$this->catalogProductEdit = $catalogProductEdit;
71+
4472
if (!$product->hasData('sku')) {
45-
$product = $this->createProductWithAttributeSet($productAttributeOriginal, $attributeSet);
73+
if (!$productAttributeOriginal) {
74+
$productAttributeOriginal = $attribute;
75+
}
76+
$product = $this->objectManager->create(
77+
'Magento\Catalog\Test\TestStep\CreateProductWithAttributeSetStep',
78+
[
79+
'attribute' => $productAttributeOriginal,
80+
'attributeSet' => $attributeSet
81+
]
82+
)->run();
83+
$product = $product['product'];
4684
}
4785
$filterProduct = ['sku' => $product->getSku()];
48-
$productGrid->open();
49-
$productGrid->getProductGrid()->searchAndOpen($filterProduct);
86+
$catalogProductIndex->open();
87+
$catalogProductIndex->getProductGrid()->searchAndOpen($filterProduct);
5088

5189
$catalogProductAttribute = ($productAttributeOriginal !== null)
5290
? array_merge($productAttributeOriginal->getData(), $attribute->getData())
5391
: $attribute->getData();
5492

5593
\PHPUnit_Framework_Assert::assertTrue(
56-
$productEdit->getProductForm()->checkAttributeLabel($catalogProductAttribute),
94+
$catalogProductEdit->getProductForm()->checkAttributeLabel($catalogProductAttribute),
5795
"Product Attribute is absent on Product form."
5896
);
5997
}
6098

61-
/**
62-
* Create Product With AttributeSet.
63-
*
64-
* @param CatalogProductAttribute $attribute
65-
* @param CatalogAttributeSet $attributeSet
66-
* @return CatalogProductSimple
67-
*/
68-
protected function createProductWithAttributeSet(
69-
CatalogProductAttribute $attribute,
70-
CatalogAttributeSet $attributeSet
71-
) {
72-
$product = ObjectManager::getInstance()->create(
73-
'Magento\Catalog\Test\TestStep\AddAttributeToAttributeSetStep',
74-
['attribute' => $attribute, 'attributeSet' => $attributeSet]
75-
)->run();
76-
return $product['product'];
77-
}
78-
7999
/**
80100
* Text of Product Attribute is present on the Product form.
81101
*

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/UpdateProductAttributeEntityTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ public function __prepare(FixtureFactory $fixtureFactory)
6464
* @param CatalogAttributeSet $attributeSet
6565
* @param CatalogProductAttributeIndex $attributeIndex
6666
* @param CatalogProductAttributeNew $attributeNew
67-
* @param CatalogProductSimple $productSimple
6867
* @return array
6968
*/
7069
public function testUpdateProductAttribute(
7170
CatalogProductAttribute $productAttributeOriginal,
7271
CatalogProductAttribute $attribute,
7372
CatalogAttributeSet $attributeSet,
7473
CatalogProductAttributeIndex $attributeIndex,
75-
CatalogProductAttributeNew $attributeNew,
76-
CatalogProductSimple $productSimple
74+
CatalogProductAttributeNew $attributeNew
7775
) {
7876
//Precondition
7977
$attributeSet->persist();
@@ -83,15 +81,32 @@ public function testUpdateProductAttribute(
8381
'attribute_code' => $productAttributeOriginal->getAttributeCode(),
8482
];
8583

84+
/** @var CatalogProductSimple $product */
85+
$product = $this->fixtureFactory->createByCode(
86+
'catalogProductSimple',
87+
[
88+
'dataset' => 'default',
89+
'data' => ['attribute_set_id' => ['attribute_set' => $attributeSet]]
90+
]
91+
);
92+
$product->persist();
93+
94+
$this->objectManager->create(
95+
'Magento\Catalog\Test\TestStep\AddAttributeToAttributeSetStep',
96+
[
97+
'attribute' => $productAttributeOriginal,
98+
'attributeSet' => $attributeSet
99+
]
100+
)->run();
101+
86102
//Steps
87103
$attributeIndex->open();
88104
$attributeIndex->getGrid()->searchAndOpen($filter);
89105
$attributeNew->getAttributeForm()->fill($attribute);
90106
$attributeNew->getPageActions()->save();
91107
$attribute = $this->prepareAttribute($attribute, $productAttributeOriginal);
92-
$productSimple->persist();
93108

94-
return ['product' => $this->prepareProduct($productSimple, $attribute, $attributeSet)];
109+
return ['product' => $this->prepareProduct($product, $attribute, $attributeSet)];
95110
}
96111

97112
/**

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/ProductAttribute/UpdateProductAttributeEntityTest.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
<data name="attributeSet/dataset" xsi:type="string">custom_attribute_set</data>
3232
<data name="productAttributeOriginal/dataset" xsi:type="string">attribute_type_dropdown</data>
3333
<data name="attribute/data/frontend_label" xsi:type="string">Dropdown_%isolation%</data>
34-
<data name="attribute/data/options/dataset" xsi:type="string">default</data>
3534
<data name="attribute/data/is_required" xsi:type="string">Yes</data>
3635
<data name="attribute/data/is_global" xsi:type="string">Global</data>
37-
<data name="attribute/data/default_value_text" xsi:type="string">attribute_edited%isolation%</data>
36+
<data name="attribute/data/options/dataset" xsi:type="string">default</data>
37+
<data name="attribute/data/options/3/is_default" xsi:type="string">Yes</data>
38+
<data name="attribute/data/options/3/admin" xsi:type="string">white_edited</data>
39+
<data name="attribute/data/options/3/view" xsi:type="string">option_1_%isolation%_edited</data>
3840
<data name="attribute/data/is_unique" xsi:type="string">Yes</data>
3941
<data name="attribute/data/is_searchable" xsi:type="string">Yes</data>
4042
<data name="attribute/data/is_visible_in_advanced_search" xsi:type="string">Yes</data>
@@ -51,7 +53,7 @@
5153
<constraint name="Magento\Catalog\Test\Constraint\AssertAddedProductAttributeOnProductForm" />
5254
</variation>
5355
<variation name="UpdateProductAttributeEntityTestVariation3">
54-
<data name="productTemplate/dataset" xsi:type="string">custom_attribute_set</data>
56+
<data name="attributeSet/dataset" xsi:type="string">custom_attribute_set</data>
5557
<data name="productAttributeOriginal/dataset" xsi:type="string">tax_class_id</data>
5658
<data name="attribute/data/is_searchable" xsi:type="string">Yes</data>
5759
<data name="attribute/data/is_visible_in_advanced_search" xsi:type="string">Yes</data>

0 commit comments

Comments
 (0)