Skip to content

Commit d358de0

Browse files
author
Roman Leshchenko
committed
Merge branch '2.2.6-develop' of github.com:magento-qwerty/magento2ce into MAGETWO-92725
2 parents 0edd746 + eeb0784 commit d358de0

File tree

68 files changed

+689
-2776
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+689
-2776
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
159159
}
160160

161161
$productData = $this->normalize($productData);
162+
$productData = $this->convertSpecialFromDateStringToObject($productData);
162163

163164
if (!empty($productData['is_downloadable'])) {
164165
$productData['product_has_weight'] = 0;
@@ -452,4 +453,19 @@ private function fillProductOptions(Product $product, array $productOptions)
452453

453454
return $product->setOptions($customOptions);
454455
}
456+
457+
/**
458+
* Convert string date presentation into object
459+
*
460+
* @param array $productData
461+
* @return array
462+
*/
463+
private function convertSpecialFromDateStringToObject($productData)
464+
{
465+
if (isset($productData['special_from_date']) && $productData['special_from_date'] != '') {
466+
$productData['special_from_date'] = new \DateTime($productData['special_from_date']);
467+
}
468+
469+
return $productData;
470+
}
455471
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\Product\Option\Type\File;
8+
9+
/**
10+
* Validator for existing (already saved) files.
11+
*/
12+
class ExistingValidate extends \Zend_Validate
13+
{
14+
/**
15+
* @inheritDoc
16+
*
17+
* @param string $value File's full path.
18+
* @param string|null $originalName Original file's name (when uploaded).
19+
*/
20+
public function isValid($value, string $originalName = null)
21+
{
22+
$this->_messages = [];
23+
$this->_errors = [];
24+
25+
if (!is_string($value)) {
26+
$this->_messages[] = __('Full file path is expected.')->render();
27+
return false;
28+
}
29+
30+
$result = true;
31+
$fileInfo = null;
32+
if ($originalName) {
33+
$fileInfo = ['name' => $originalName];
34+
}
35+
foreach ($this->_validators as $element) {
36+
$validator = $element['instance'];
37+
if ($validator->isValid($value, $fileInfo)) {
38+
continue;
39+
}
40+
$result = false;
41+
$messages = $validator->getMessages();
42+
$this->_messages = array_merge($this->_messages, $messages);
43+
$this->_errors = array_merge($this->_errors, array_keys($messages));
44+
if ($element['breakChainOnFailure']) {
45+
break;
46+
}
47+
}
48+
return $result;
49+
}
50+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class ValidateFactory
1313
*/
1414
public function create()
1515
{
16-
return new \Zend_Validate();
16+
return new ExistingValidate();
1717
}
1818
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Catalog\Model\Product\Exception as ProductException;
1212
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Math\Random;
14+
use Magento\Framework\App\ObjectManager;
1315

1416
/**
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -62,25 +64,34 @@ class ValidatorFile extends Validator
6264
*/
6365
protected $isImageValidator;
6466

67+
/**
68+
* @var Random
69+
*/
70+
private $random;
71+
6572
/**
6673
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
6774
* @param \Magento\Framework\Filesystem $filesystem
6875
* @param \Magento\Framework\File\Size $fileSize
6976
* @param \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory
7077
* @param \Magento\Framework\Validator\File\IsImage $isImageValidator
78+
* @param Random|null $random
7179
* @throws \Magento\Framework\Exception\FileSystemException
7280
*/
7381
public function __construct(
7482
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
7583
\Magento\Framework\Filesystem $filesystem,
7684
\Magento\Framework\File\Size $fileSize,
7785
\Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory,
78-
\Magento\Framework\Validator\File\IsImage $isImageValidator
86+
\Magento\Framework\Validator\File\IsImage $isImageValidator,
87+
Random $random = null
7988
) {
8089
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
8190
$this->filesystem = $filesystem;
8291
$this->httpFactory = $httpFactory;
8392
$this->isImageValidator = $isImageValidator;
93+
$this->random = $random
94+
?? ObjectManager::getInstance()->get(Random::class);
8495
parent::__construct($scopeConfig, $filesystem, $fileSize);
8596
}
8697

@@ -147,16 +158,15 @@ public function validate($processingParams, $option)
147158
$userValue = [];
148159

149160
if ($upload->isUploaded($file) && $upload->isValid($file)) {
150-
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
151-
152161
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
153162
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispersionPath($fileName);
154163

155164
$filePath = $dispersion;
156165

157166
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
158167
$fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name'])));
159-
$filePath .= '/' . $fileHash . '.' . $extension;
168+
$fileRandomName = $this->random->getRandomString(32);
169+
$filePath .= '/' .$fileRandomName;
160170
$fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath);
161171

162172
$upload->addFilter(new \Zend_Filter_File_Rename(['target' => $fileFullPath, 'overwrite' => true]));

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Catalog\Model\Product\Option\Type\File;
88

9+
/**
10+
* Validator for existing files.
11+
*/
912
class ValidatorInfo extends Validator
1013
{
1114
/**
@@ -90,7 +93,7 @@ public function validate($optionValue, $option)
9093
}
9194

9295
$result = false;
93-
if ($validatorChain->isValid($this->fileFullPath)) {
96+
if ($validatorChain->isValid($this->fileFullPath, $optionValue['title'])) {
9497
$result = $this->rootDirectory->isReadable($this->fileRelativePath)
9598
&& isset($optionValue['secret_key'])
9699
&& $this->buildSecretKey($this->fileRelativePath) == $optionValue['secret_key'];

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,12 @@ public function testInitialize(
198198
'option2' => ['is_delete' => false, 'name' => 'name1', 'price' => 'price1', 'option_id' => '13'],
199199
'option3' => ['is_delete' => false, 'name' => 'name1', 'price' => 'price1', 'option_id' => '14']
200200
];
201+
$specialFromDate = '2018-03-03 19:30:00';
201202
$productData = [
202203
'stock_data' => ['stock_data'],
203204
'options' => $optionsData,
204-
'website_ids' => $websiteIds
205+
'website_ids' => $websiteIds,
206+
'special_from_date' => $specialFromDate,
205207
];
206208
if (!empty($tierPrice)) {
207209
$productData = array_merge($productData, ['tier_price' => $tierPrice]);
@@ -306,6 +308,7 @@ public function testInitialize(
306308
}
307309

308310
$this->assertEquals($expectedLinks, $resultLinks);
311+
$this->assertEquals($specialFromDate, $productData['special_from_date']);
309312
}
310313

311314
/**

app/code/Magento/Customer/Controller/Account/EditPost.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Framework\Exception\InputException;
2121
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
2222
use Magento\Framework\Exception\State\UserLockedException;
23+
use Magento\Framework\Escaper;
2324

2425
/**
2526
* Class EditPost
@@ -72,28 +73,34 @@ class EditPost extends \Magento\Customer\Controller\AbstractAccount
7273
*/
7374
private $customerMapper;
7475

76+
/** @var Escaper */
77+
private $escaper;
78+
7579
/**
7680
* @param Context $context
7781
* @param Session $customerSession
7882
* @param AccountManagementInterface $customerAccountManagement
7983
* @param CustomerRepositoryInterface $customerRepository
8084
* @param Validator $formKeyValidator
8185
* @param CustomerExtractor $customerExtractor
86+
* @param Escaper|null $escaper
8287
*/
8388
public function __construct(
8489
Context $context,
8590
Session $customerSession,
8691
AccountManagementInterface $customerAccountManagement,
8792
CustomerRepositoryInterface $customerRepository,
8893
Validator $formKeyValidator,
89-
CustomerExtractor $customerExtractor
94+
CustomerExtractor $customerExtractor,
95+
Escaper $escaper = null
9096
) {
9197
parent::__construct($context);
9298
$this->session = $customerSession;
9399
$this->customerAccountManagement = $customerAccountManagement;
94100
$this->customerRepository = $customerRepository;
95101
$this->formKeyValidator = $formKeyValidator;
96102
$this->customerExtractor = $customerExtractor;
103+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
97104
}
98105

99106
/**
@@ -175,9 +182,9 @@ public function execute()
175182
$this->messageManager->addError($message);
176183
return $resultRedirect->setPath('customer/account/login');
177184
} catch (InputException $e) {
178-
$this->messageManager->addError($e->getMessage());
185+
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
179186
foreach ($e->getErrors() as $error) {
180-
$this->messageManager->addError($error->getMessage());
187+
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage()));
181188
}
182189
} catch (\Magento\Framework\Exception\LocalizedException $e) {
183190
$this->messageManager->addError($e->getMessage());

app/code/Magento/Customer/Controller/Adminhtml/Index/AbstractMassAction.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\ResponseInterface;
1111
use Magento\Framework\Controller\ResultInterface;
1212
use Magento\Backend\App\Action\Context;
13+
use Magento\Framework\Exception\NotFoundException;
1314
use Magento\Ui\Component\MassAction\Filter;
1415
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
1516

@@ -60,6 +61,10 @@ public function __construct(Context $context, Filter $filter, CollectionFactory
6061
*/
6162
public function execute()
6263
{
64+
if (!$this->getRequest()->isPost()) {
65+
throw new NotFoundException(__('Page not found'));
66+
}
67+
6368
try {
6469
$collection = $this->filter->getCollection($this->collectionFactory->create());
6570
return $this->massAction($collection);

app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerOrderSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
1111
<section name="StorefrontCustomerOrderSection">
12+
<element name="isMyOrdersSection" type="text" selector="//*[@class='page-title']//*[contains(text(), 'My Orders')]"/>
1213
<element name="productCustomOptions" type="text" selector="//strong[contains(@class, 'product-item-name') and normalize-space(.)='{{var1}}']/following-sibling::*[contains(@class, 'item-options')]/dt[normalize-space(.)='{{var2}}']/following-sibling::dd[normalize-space(.)='{{var3}}']" parameterized="true"/>
1314
<element name="productCustomOptionsFile" type="text" selector="//strong[contains(@class, 'product-item-name') and normalize-space(.)='{{var1}}']/following-sibling::*[contains(@class, 'item-options')]/dt[normalize-space(.)='{{var2}}']/following-sibling::dd[contains(.,'{{var3}}')]" parameterized="true"/>
1415
</section>

app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerOrderViewSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
<element name="myOrdersTable" type="text" selector="#my-orders-table"/>
1414
<element name="subtotal" type="text" selector=".subtotal .amount"/>
1515
<element name="paymentMethod" type="text" selector=".payment-method dt"/>
16+
<element name="printOrderLink" type="text" selector="a.action.print" timeout="30"/>
1617
</section>
1718
</sections>

0 commit comments

Comments
 (0)