Skip to content

Commit 51b1ae8

Browse files
author
Serhiy Shkolyarenko
committed
Merge remote-tracking branch 'mainline/develop' into exception_logger
2 parents 8cb20fa + 45f2cae commit 51b1ae8

File tree

203 files changed

+15009
-3702
lines changed

Some content is hidden

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

203 files changed

+15009
-3702
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function execute()
162162
$this->attributeHelper->getStoreWebsiteId($storeId)
163163
);
164164
if (!$stockItemDo->getProductId()) {
165-
$inventoryData[] = $productId;
165+
$inventoryData['product_id'] = $productId;
166166
}
167167

168168
$stockItemId = $stockItemDo->getId();

app/code/Magento/Catalog/Model/Product/Attribute/Repository.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ class Repository implements \Magento\Catalog\Api\ProductAttributeRepositoryInter
5050
*/
5151
protected $searchCriteriaBuilder;
5252

53-
/**
54-
* @var \Magento\Catalog\Api\ProductAttributeOptionManagementInterface
55-
*/
56-
private $optionManagement;
57-
5853
/**
5954
* @param \Magento\Catalog\Model\ResourceModel\Attribute $attributeResource
6055
* @param \Magento\Catalog\Helper\Product $productHelper
@@ -177,13 +172,31 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
177172
);
178173
$attribute->setIsUserDefined(1);
179174
}
180-
$this->attributeResource->save($attribute);
181-
182175
if (!empty($attribute->getData(AttributeInterface::OPTIONS))) {
176+
$options = [];
177+
$sortOrder = 0;
178+
$default = [];
179+
$optionIndex = 0;
183180
foreach ($attribute->getOptions() as $option) {
184-
$this->getOptionManagement()->add($attribute->getAttributeCode(), $option);
181+
$optionIndex++;
182+
$optionId = $option->getValue() ?: 'option_' . $optionIndex;
183+
$options['value'][$optionId][0] = $option->getLabel();
184+
$options['order'][$optionId] = $option->getSortOrder() ?: $sortOrder++;
185+
if (is_array($option->getStoreLabels())) {
186+
foreach ($option->getStoreLabels() as $label) {
187+
$options['value'][$optionId][$label->getStoreId()] = $label->getLabel();
188+
}
189+
}
190+
if ($option->getIsDefault()) {
191+
$default[] = $optionId;
192+
}
193+
}
194+
$attribute->setDefault($default);
195+
if (count($options)) {
196+
$attribute->setOption($options);
185197
}
186198
}
199+
$this->attributeResource->save($attribute);
187200
return $this->get($attribute->getAttributeCode());
188201
}
189202

@@ -262,16 +275,4 @@ protected function validateFrontendInput($frontendInput)
262275
throw InputException::invalidFieldValue('frontend_input', $frontendInput);
263276
}
264277
}
265-
266-
/**
267-
* @return \Magento\Catalog\Api\ProductAttributeOptionManagementInterface
268-
*/
269-
private function getOptionManagement()
270-
{
271-
if (null === $this->optionManagement) {
272-
$this->optionManagement = \Magento\Framework\App\ObjectManager::getInstance()
273-
->get(\Magento\Catalog\Api\ProductAttributeOptionManagementInterface::class);
274-
}
275-
return $this->optionManagement;
276-
}
277278
}

app/code/Magento/Catalog/view/frontend/templates/product/list/items.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ switch ($type = $block->getType()) {
110110

111111
case 'crosssell':
112112
/** @var \Magento\Catalog\Block\Product\ProductList\Crosssell $block */
113-
if ($exist = $block->getItemCount()) {
113+
if ($exist = count($block->getItems())) {
114114
$type = 'crosssell';
115115
$class = $type;
116116

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ protected function _initAttributeSets()
10151015
protected function _initSkus()
10161016
{
10171017
$this->skuProcessor->setTypeModels($this->_productTypeModels);
1018-
$this->_oldSku = $this->skuProcessor->getOldSkus();
1018+
$this->_oldSku = $this->skuProcessor->reloadOldSkus()->getOldSkus();
10191019
return $this;
10201020
}
10211021

app/code/Magento/CatalogImportExport/Model/Import/Uploader.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\CatalogImportExport\Model\Import;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Exception\LocalizedException;
910
use Magento\Framework\Filesystem\DriverPool;
1011

1112
/**
@@ -15,6 +16,14 @@
1516
*/
1617
class Uploader extends \Magento\MediaStorage\Model\File\Uploader
1718
{
19+
20+
/**
21+
* HTTP scheme
22+
* used to compare against the filename and select the proper DriverPool adapter
23+
* @var string
24+
*/
25+
private $httpScheme = 'http://';
26+
1827
/**
1928
* Temp directory.
2029
*
@@ -145,7 +154,13 @@ public function move($fileName, $renameFileOff = false)
145154
}
146155
if (preg_match('/\bhttps?:\/\//i', $fileName, $matches)) {
147156
$url = str_replace($matches[0], '', $fileName);
148-
$read = $this->_readFactory->create($url, DriverPool::HTTP);
157+
158+
if ($matches[0] === $this->httpScheme) {
159+
$read = $this->_readFactory->create($url, DriverPool::HTTP);
160+
} else {
161+
$read = $this->_readFactory->create($url, DriverPool::HTTPS);
162+
}
163+
149164
$fileName = preg_replace('/[^a-z0-9\._-]+/i', '', $fileName);
150165
$this->_directory->writeFile(
151166
$this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName),

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ protected function _initTypeModels()
516516
protected function _initSkus()
517517
{
518518
$this->skuProcessor->expects($this->once())->method('setTypeModels');
519+
$this->skuProcessor->expects($this->once())->method('reloadOldSkus')->willReturnSelf();
519520
$this->skuProcessor->expects($this->once())->method('getOldSkus');
520521
return $this;
521522
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,63 @@ public function testMoveFileName()
152152
$this->assertEquals(['name' => $fileName], $this->uploader->move($fileName));
153153
}
154154

155+
/**
156+
* @dataProvider moveFileUrlDriverPoolDataProvider
157+
*/
158+
public function testMoveFileUrlDrivePool($fileUrl, $expectedHost, $expectedDriverPool, $expectedScheme)
159+
{
160+
161+
$driverPool = $this->getMock(\Magento\Framework\Filesystem\DriverPool::class, ['getDriver']);
162+
$driverMock = $this->getMock($expectedDriverPool, ['readAll']);
163+
$driverMock->expects($this->any())->method('isExists')->willReturn(true);
164+
$driverMock->expects($this->any())->method('readAll')->willReturn(null);
165+
$driverPool->expects($this->any())->method('getDriver')->willReturn($driverMock);
166+
167+
$readFactory = $this->getMockBuilder(\Magento\Framework\Filesystem\File\ReadFactory::class)
168+
->setConstructorArgs(
169+
[
170+
$driverPool,
171+
]
172+
)
173+
->setMethods(['create'])
174+
->getMock();
175+
176+
$readFactory->expects($this->any())->method('create')
177+
->with($expectedHost, $expectedScheme)
178+
->willReturn($driverMock);
179+
180+
$uploaderMock = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Uploader::class)
181+
->setConstructorArgs([
182+
$this->coreFileStorageDb,
183+
$this->coreFileStorage,
184+
$this->imageFactory,
185+
$this->validator,
186+
$this->filesystem,
187+
$readFactory,
188+
])
189+
->getMock();
190+
191+
$uploaderMock->move($fileUrl);
192+
}
193+
194+
public function moveFileUrlDriverPoolDataProvider()
195+
{
196+
return [
197+
[
198+
'$fileUrl' => 'http://test_uploader_file',
199+
'$expectedHost' => 'test_uploader_file',
200+
'$expectedDriverPool' => \Magento\Framework\Filesystem\Driver\Http::class,
201+
'$expectedScheme' => \Magento\Framework\Filesystem\DriverPool::HTTP,
202+
],
203+
[
204+
'$fileUrl' => 'https://!:^&`;file',
205+
'$expectedHost' => '!:^&`;file',
206+
'$expectedDriverPool' => \Magento\Framework\Filesystem\Driver\Https::class,
207+
'$expectedScheme' => \Magento\Framework\Filesystem\DriverPool::HTTPS,
208+
],
209+
];
210+
}
211+
155212
public function moveFileUrlDataProvider()
156213
{
157214
return [

app/code/Magento/CatalogRule/Pricing/Price/CatalogRulePrice.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public function getValue()
9999
$this->product->getId()
100100
);
101101
$this->value = $this->value ? floatval($this->value) : false;
102-
if ($this->value) {
103-
$this->value = $this->priceCurrency->convertAndRound($this->value);
104-
}
102+
}
103+
if ($this->value) {
104+
$this->value = $this->priceCurrency->convertAndRound($this->value);
105105
}
106106
}
107107

app/code/Magento/CatalogRule/Test/Unit/Pricing/Price/CatalogRulePriceTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,20 @@ public function testGetValue()
208208

209209
public function testGetValueFromData()
210210
{
211+
$catalogRulePrice = 7.1;
212+
$convertedPrice = 5.84;
213+
214+
$this->priceCurrencyMock->expects($this->any())
215+
->method('convertAndRound')
216+
->with($catalogRulePrice)
217+
->will($this->returnValue($convertedPrice));
218+
211219
$this->saleableItemMock->expects($this->once())->method('hasData')
212220
->with('catalog_rule_price')->willReturn(true);
213221
$this->saleableItemMock->expects($this->once())->method('getData')
214-
->with('catalog_rule_price')->willReturn('7.1');
222+
->with('catalog_rule_price')->willReturn($catalogRulePrice);
215223

216-
$this->assertEquals(7.1, $this->object->getValue());
224+
$this->assertEquals($convertedPrice, $this->object->getValue());
217225
}
218226

219227
public function testGetAmountNoBaseAmount()

app/code/Magento/Checkout/view/frontend/templates/cart/coupon.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"removeCouponSelector": "#remove-coupon",
2020
"applyButton": "button.action.apply",
2121
"cancelButton": "button.action.cancel"}}'>
22-
<div class="fieldset coupon<?php strlen($block->getCouponCode()) ? ' applied' : ''?>">
22+
<div class="fieldset coupon<?php echo strlen($block->getCouponCode()) ? ' applied' : ''?>">
2323
<input type="hidden" name="remove" id="remove-coupon" value="0" />
2424
<div class="field">
2525
<label for="coupon_code" class="label"><span><?php /* @escapeNotVerified */ echo __('Enter discount code') ?></span></label>

app/code/Magento/Config/Model/Config/Backend/Currency/AbstractCurrency.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ protected function _getAllowedCurrencies()
3232
)
3333
);
3434
}
35-
return $this->getData('groups/options/fields/allow/value');
35+
36+
return (array)$this->getData('groups/options/fields/allow/value');
3637
}
3738

3839
/**

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/**
1818
* Importing configurable products
19-
* @package Magento\ConfigurableImportExport\Model\Import\Product\Type
19+
*
2020
* @SuppressWarnings(PHPMD.TooManyFields)
2121
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2222
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend;
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
10+
11+
/**
12+
* Skip validate attributes used for create configurable product
13+
*/
14+
class AttributeValidation
15+
{
16+
/**
17+
* @var Configurable
18+
*/
19+
private $configurableProductType;
20+
21+
/**
22+
* AttributeValidation constructor.
23+
* @param Configurable $configurableProductType
24+
*/
25+
public function __construct(
26+
Configurable $configurableProductType
27+
) {
28+
$this->configurableProductType = $configurableProductType;
29+
}
30+
31+
/**
32+
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
33+
* @param \Closure $proceed
34+
* @param \Magento\Framework\DataObject $entity
35+
* @return bool
36+
*/
37+
public function aroundValidate(
38+
\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject,
39+
\Closure $proceed,
40+
\Magento\Framework\DataObject $entity
41+
) {
42+
$attribute = $subject->getAttribute();
43+
if ($entity instanceof ProductInterface
44+
&& $entity->getTypeId() == Configurable::TYPE_CODE
45+
&& in_array(
46+
$attribute->getAttributeId(),
47+
$this->configurableProductType->getUsedProductAttributeIds($entity),
48+
true
49+
)
50+
) {
51+
return true;
52+
}
53+
return $proceed($entity);
54+
}
55+
}

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<type name="Magento\Catalog\Helper\Product\Configuration">
2929
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Helper\Product\Configuration\Plugin" sortOrder="50" />
3030
</type>
31+
<type name="Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend">
32+
<plugin name="ConfigurableProduct::skipValidation" type="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation"/>
33+
</type>
3134
<type name="Magento\Catalog\Model\Entity\Product\Attribute\Group\AttributeMapperInterface">
3235
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Model\Entity\Product\Attribute\Group\AttributeMapper\Plugin" sortOrder="50" />
3336
</type>

0 commit comments

Comments
 (0)