Skip to content

Commit baf0561

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into MAGETWO-90940
2 parents e34084d + e80727a commit baf0561

File tree

25 files changed

+363
-14
lines changed

25 files changed

+363
-14
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
103103
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
104104
* @param ImportProduct\StoreResolver $storeResolver
105105
* @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
106-
* @throws \Magento\Framework\Exception\LocalizedException
107106
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
108107
*/
109108
public function __construct(
@@ -192,6 +191,7 @@ protected function initTypeModels()
192191
* Export process
193192
*
194193
* @return string
194+
* @throws \Magento\Framework\Exception\LocalizedException
195195
*/
196196
public function export()
197197
{
@@ -461,6 +461,7 @@ protected function getTierPrices(array $productLinksIds, $table)
461461
*
462462
* @param int $websiteId
463463
* @return string
464+
* @throws \Magento\Framework\Exception\LocalizedException
464465
*/
465466
protected function _getWebsiteCode(int $websiteId): string
466467
{
@@ -491,6 +492,8 @@ protected function _getWebsiteCode(int $websiteId): string
491492
* @param int $customerGroupId
492493
* @param int $allGroups
493494
* @return string
495+
* @throws \Magento\Framework\Exception\LocalizedException
496+
* @throws \Magento\Framework\Exception\NoSuchEntityException
494497
*/
495498
protected function _getCustomerGroupById(
496499
int $customerGroupId,

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
99
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
1010
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
11-
use Magento\Framework\App\ResourceConnection;
1211

1312
/**
1413
* Class AdvancedPricing
@@ -619,6 +618,7 @@ protected function processCountNewPrices(array $tierPrices)
619618
* Get product entity link field
620619
*
621620
* @return string
621+
* @throws \Exception
622622
*/
623623
private function getProductEntityLinkField()
624624
{

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing/Validator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function __construct($validators = [])
2828
*
2929
* @param array $value
3030
* @return bool
31+
* @throws \Zend_Validate_Exception
3132
*/
3233
public function isValid($value)
3334
{

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Export/AdvancedPricingTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ protected function tearDown()
347347
* @param $object
348348
* @param $property
349349
* @return mixed
350+
* @throws \ReflectionException
350351
*/
351352
protected function getPropertyValue($object, $property)
352353
{
@@ -362,6 +363,8 @@ protected function getPropertyValue($object, $property)
362363
* @param $object
363364
* @param $property
364365
* @param $value
366+
* @return mixed
367+
* @throws \ReflectionException
365368
*/
366369
protected function setPropertyValue(&$object, $property, $value)
367370
{

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricing/Validator/TierPriceTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ public function isValidAddMessagesCallDataProvider()
346346
* @param object $object
347347
* @param string $property
348348
* @return mixed
349+
* @throws \ReflectionException
349350
*/
350351
protected function getPropertyValue($object, $property)
351352
{
@@ -363,6 +364,7 @@ protected function getPropertyValue($object, $property)
363364
* @param string $property
364365
* @param mixed $value
365366
* @return object
367+
* @throws \ReflectionException
366368
*/
367369
protected function setPropertyValue(&$object, $property, $value)
368370
{

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Import/AdvancedPricingTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ public function testGetEntityTypeCode()
209209
* Test method validateRow against its result.
210210
*
211211
* @dataProvider validateRowResultDataProvider
212+
* @param array $rowData
213+
* @param string|null $behavior
214+
* @param bool $expectedResult
215+
* @throws \ReflectionException
212216
*/
213217
public function testValidateRowResult($rowData, $behavior, $expectedResult)
214218
{
@@ -234,6 +238,10 @@ public function testValidateRowResult($rowData, $behavior, $expectedResult)
234238
* Test method validateRow whether AddRowError is called.
235239
*
236240
* @dataProvider validateRowAddRowErrorCallDataProvider
241+
* @param array $rowData
242+
* @param string|null $behavior
243+
* @param string $error
244+
* @throws \ReflectionException
237245
*/
238246
public function testValidateRowAddRowErrorCall($rowData, $behavior, $error)
239247
{
@@ -324,6 +332,13 @@ public function testSaveAdvancedPricing()
324332
* Take into consideration different data and check relative internal calls.
325333
*
326334
* @dataProvider saveAndReplaceAdvancedPricesAppendBehaviourDataProvider
335+
* @param array $data
336+
* @param string $tierCustomerGroupId
337+
* @param string $groupCustomerGroupId
338+
* @param string $tierWebsiteId
339+
* @param string $groupWebsiteId
340+
* @param array $expectedTierPrices
341+
* @throws \ReflectionException
327342
*/
328343
public function testSaveAndReplaceAdvancedPricesAppendBehaviourDataAndCalls(
329344
$data,
@@ -956,6 +971,7 @@ public function processCountExistingPricesDataProvider()
956971
* @param $object
957972
* @param $property
958973
* @return mixed
974+
* @throws \ReflectionException
959975
*/
960976
protected function getPropertyValue($object, $property)
961977
{
@@ -972,6 +988,8 @@ protected function getPropertyValue($object, $property)
972988
* @param $object
973989
* @param $property
974990
* @param $value
991+
* @return mixed
992+
* @throws \ReflectionException
975993
*/
976994
protected function setPropertyValue(&$object, $property, $value)
977995
{
@@ -990,7 +1008,8 @@ protected function setPropertyValue(&$object, $property, $value)
9901008
* @param string $method
9911009
* @param array $args
9921010
*
993-
* @return mixed the method result.
1011+
* @return mixed
1012+
* @throws \ReflectionException
9941013
*/
9951014
private function invokeMethod($object, $method, $args = [])
9961015
{
@@ -1007,6 +1026,7 @@ private function invokeMethod($object, $method, $args = [])
10071026
* @param array $methods
10081027
*
10091028
* @return \PHPUnit_Framework_MockObject_MockObject
1029+
* @throws \ReflectionException
10101030
*/
10111031
private function getAdvancedPricingMock($methods = [])
10121032
{

app/code/Magento/Checkout/etc/webapi.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<resource ref="anonymous" />
105105
</resources>
106106
</route>
107-
<!-- Managing My shipping information -->
107+
<!-- Managing My payment information -->
108108
<route url="/V1/carts/mine/set-payment-information" method="POST">
109109
<service class="Magento\Checkout\Api\PaymentInformationManagementInterface" method="savePaymentInformation"/>
110110
<resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<arguments>
121121
<argument name="providers" xsi:type="array">
122122
<item name="default" xsi:type="string">Magento\Sales\Model\ResourceModel\Provider\UpdatedIdListProvider</item>
123+
<item name="updated_at" xsi:type="string">Magento\Sales\Model\ResourceModel\Provider\UpdatedAtListProvider</item>
123124
</argument>
124125
</arguments>
125126
</type>

app/code/Magento/Swatches/Model/Plugin/EavAttribute.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Exception\InputException;
1111
use Magento\Framework\Serialize\Serializer\Json;
1212
use Magento\Swatches\Model\Swatch;
13+
use Magento\Swatches\Model\ResourceModel\Swatch as SwatchResource;
1314

1415
/**
1516
* Plugin model for Catalog Resource Attribute
@@ -18,6 +19,11 @@ class EavAttribute
1819
{
1920
const DEFAULT_STORE_ID = 0;
2021

22+
/**
23+
* @var SwatchResource
24+
*/
25+
private $swatchResource;
26+
2127
/**
2228
* Base option title used for string operations to detect is option already exists or new
2329
*/
@@ -64,17 +70,20 @@ class EavAttribute
6470
* @param \Magento\Swatches\Model\SwatchFactory $swatchFactory
6571
* @param \Magento\Swatches\Helper\Data $swatchHelper
6672
* @param Json|null $serializer
73+
* @param SwatchResource|null $swatchResource
6774
*/
6875
public function __construct(
6976
\Magento\Swatches\Model\ResourceModel\Swatch\CollectionFactory $collectionFactory,
7077
\Magento\Swatches\Model\SwatchFactory $swatchFactory,
7178
\Magento\Swatches\Helper\Data $swatchHelper,
72-
Json $serializer = null
79+
Json $serializer = null,
80+
SwatchResource $swatchResource = null
7381
) {
7482
$this->swatchCollectionFactory = $collectionFactory;
7583
$this->swatchFactory = $swatchFactory;
7684
$this->swatchHelper = $swatchHelper;
7785
$this->serializer = $serializer ?: ObjectManager::getInstance()->create(Json::class);
86+
$this->swatchResource = $swatchResource ?: ObjectManager::getInstance()->create(SwatchResource::class);
7887
}
7988

8089
/**
@@ -148,6 +157,7 @@ protected function setProperOptionsArray(Attribute $attribute)
148157
* Prepare attribute for conversion from any swatch type to dropdown
149158
*
150159
* @param Attribute $attribute
160+
* @throws \Magento\Framework\Exception\LocalizedException
151161
* @return void
152162
*/
153163
protected function convertSwatchToDropdown(Attribute $attribute)
@@ -157,6 +167,7 @@ protected function convertSwatchToDropdown(Attribute $attribute)
157167
if (!empty($additionalData)) {
158168
$additionalData = $this->serializer->unserialize($additionalData);
159169
if (is_array($additionalData) && isset($additionalData[Swatch::SWATCH_INPUT_TYPE_KEY])) {
170+
$this->cleanEavAttributeOptionSwatchValues($attribute->getOption());
160171
unset($additionalData[Swatch::SWATCH_INPUT_TYPE_KEY]);
161172
$attribute->setData('additional_data', $this->serializer->serialize($additionalData));
162173
}
@@ -235,6 +246,7 @@ protected function saveSwatchParams(Attribute $attribute)
235246
{
236247
if ($this->swatchHelper->isVisualSwatch($attribute)) {
237248
$this->processVisualSwatch($attribute);
249+
$this->cleanTextSwatchValuesAfterSwitch($attribute->getOptiontext());
238250
} elseif ($this->swatchHelper->isTextSwatch($attribute)) {
239251
$this->processTextualSwatch($attribute);
240252
}
@@ -267,6 +279,33 @@ protected function processVisualSwatch(Attribute $attribute)
267279
}
268280
}
269281

282+
/**
283+
* Clean swatch option values after switching to the dropdown type.
284+
*
285+
* @param array $attributeOptions
286+
* @param null $swatchType
287+
* @throws \Magento\Framework\Exception\LocalizedException
288+
*/
289+
private function cleanEavAttributeOptionSwatchValues($attributeOptions, $swatchType = null)
290+
{
291+
if (count($attributeOptions) && isset($attributeOptions['value'])) {
292+
$optionsIDs = array_keys($attributeOptions['value']);
293+
294+
$this->swatchResource->clearSwatchOptionByOptionIdAndType($optionsIDs, $swatchType);
295+
}
296+
}
297+
298+
/**
299+
* Cleaning the text type of swatch option values after switching.
300+
*
301+
* @param array $attributeOptions
302+
* @throws \Magento\Framework\Exception\LocalizedException
303+
*/
304+
private function cleanTextSwatchValuesAfterSwitch($attributeOptions)
305+
{
306+
$this->cleanEavAttributeOptionSwatchValues($attributeOptions, Swatch::SWATCH_TYPE_TEXTUAL);
307+
}
308+
270309
/**
271310
* @param string $value
272311
* @return int

app/code/Magento/Swatches/Model/ResourceModel/Swatch.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,24 @@ public function saveDefaultSwatchOption($id, $defaultValue)
3737
$this->getConnection()->update($this->getTable('eav_attribute'), $bind, $where);
3838
}
3939
}
40+
41+
/**
42+
* Cleaned swatch option values when switching to dropdown input type
43+
*
44+
* @param $optionIDs
45+
* @param $type
46+
* @throws \Magento\Framework\Exception\LocalizedException
47+
*/
48+
public function clearSwatchOptionByOptionIdAndType($optionIDs, $type = null)
49+
{
50+
if (count($optionIDs)) {
51+
foreach ($optionIDs as $optionId) {
52+
$where = ['option_id' => $optionId];
53+
if ($type !== null) {
54+
$where['type = ?'] = $type;
55+
}
56+
$this->getConnection()->delete($this->getMainTable(), $where);
57+
}
58+
}
59+
}
4060
}

0 commit comments

Comments
 (0)