Skip to content

Commit 0516c8b

Browse files
authored
Merge pull request #5879 from magento-tsg-csl3/2.4-develop-pr34
[TSG-CSL3] For 2.4|2.4 (pr34)
2 parents 1ee7e1f + e9e8ea5 commit 0516c8b

File tree

44 files changed

+1786
-559
lines changed

Some content is hidden

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

44 files changed

+1786
-559
lines changed

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Bundle\Model\Product\Type;
1212
use Magento\Bundle\Model\ResourceModel\BundleFactory;
1313
use Magento\Bundle\Model\ResourceModel\Option\Collection;
14+
use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor;
1415
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
1516
use Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory;
1617
use Magento\Bundle\Model\Selection;
@@ -42,6 +43,8 @@
4243
use PHPUnit\Framework\TestCase;
4344

4445
/**
46+
* Test for bundle product type
47+
*
4548
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
4649
*/
4750
class TypeTest extends TestCase
@@ -116,6 +119,11 @@ class TypeTest extends TestCase
116119
*/
117120
private $arrayUtility;
118121

122+
/**
123+
* @var CollectionProcessor|MockObject
124+
*/
125+
private $catalogRuleProcessor;
126+
119127
/**
120128
* @return void
121129
*/
@@ -172,20 +180,20 @@ protected function setUp(): void
172180
->setMethods(['create'])
173181
->disableOriginalConstructor()
174182
->getMock();
175-
176183
$this->serializer = $this->getMockBuilder(Json::class)
177184
->setMethods(null)
178185
->disableOriginalConstructor()
179186
->getMock();
180-
181187
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)
182188
->disableOriginalConstructor()
183189
->getMock();
184-
185190
$this->arrayUtility = $this->getMockBuilder(ArrayUtils::class)
186191
->setMethods(['flatten'])
187192
->disableOriginalConstructor()
188193
->getMock();
194+
$this->catalogRuleProcessor = $this->getMockBuilder(CollectionProcessor::class)
195+
->disableOriginalConstructor()
196+
->getMock();
189197

190198
$objectHelper = new ObjectManager($this);
191199
$this->model = $objectHelper->getObject(
@@ -1542,7 +1550,7 @@ public function testPrepareForCartAdvancedSpecifyProductOptions()
15421550

15431551
$this->parentClass($group, $option, $buyRequest, $product);
15441552

1545-
$product->expects($this->once())
1553+
$product->expects($this->any())
15461554
->method('getSkipCheckRequiredOption')
15471555
->willReturn(true);
15481556
$buyRequest->expects($this->once())
@@ -2424,9 +2432,6 @@ protected function parentClass($group, $option, $buyRequest, $product)
24242432
$group->expects($this->once())
24252433
->method('setProcessMode')
24262434
->willReturnSelf();
2427-
$group->expects($this->once())
2428-
->method('validateUserValue')
2429-
->willReturnSelf();
24302435
$group->expects($this->once())
24312436
->method('prepareForCart')
24322437
->willReturn('someString');
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Api;
9+
10+
/**
11+
* Interface to update product attribute option
12+
*
13+
* @api
14+
*/
15+
interface ProductAttributeOptionUpdateInterface
16+
{
17+
/**
18+
* Update attribute option
19+
*
20+
* @param string $attributeCode
21+
* @param int $optionId
22+
* @param \Magento\Eav\Api\Data\AttributeOptionInterface $option
23+
* @return bool
24+
* @throws \Magento\Framework\Exception\StateException
25+
* @throws \Magento\Framework\Exception\NoSuchEntityException
26+
* @throws \Magento\Framework\Exception\InputException
27+
*/
28+
public function update(
29+
string $attributeCode,
30+
int $optionId,
31+
\Magento\Eav\Api\Data\AttributeOptionInterface $option
32+
): bool;
33+
}

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,39 @@
66
*/
77
namespace Magento\Catalog\Model\Product\Attribute;
88

9+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
10+
use Magento\Catalog\Api\ProductAttributeOptionManagementInterface;
11+
use Magento\Catalog\Api\ProductAttributeOptionUpdateInterface;
12+
use Magento\Eav\Api\AttributeOptionManagementInterface;
13+
use Magento\Eav\Api\AttributeOptionUpdateInterface;
14+
use Magento\Eav\Api\Data\AttributeOptionInterface;
915
use Magento\Framework\Exception\InputException;
1016

1117
/**
1218
* Option management model for product attribute.
1319
*/
14-
class OptionManagement implements \Magento\Catalog\Api\ProductAttributeOptionManagementInterface
20+
class OptionManagement implements ProductAttributeOptionManagementInterface, ProductAttributeOptionUpdateInterface
1521
{
1622
/**
17-
* @var \Magento\Eav\Api\AttributeOptionManagementInterface
23+
* @var AttributeOptionManagementInterface
1824
*/
1925
protected $eavOptionManagement;
2026

2127
/**
22-
* @param \Magento\Eav\Api\AttributeOptionManagementInterface $eavOptionManagement
28+
* @var AttributeOptionUpdateInterface
29+
*/
30+
private $eavOptionUpdate;
31+
32+
/**
33+
* @param AttributeOptionManagementInterface $eavOptionManagement
34+
* @param AttributeOptionUpdateInterface $eavOptionUpdate
2335
*/
2436
public function __construct(
25-
\Magento\Eav\Api\AttributeOptionManagementInterface $eavOptionManagement
37+
AttributeOptionManagementInterface $eavOptionManagement,
38+
AttributeOptionUpdateInterface $eavOptionUpdate
2639
) {
2740
$this->eavOptionManagement = $eavOptionManagement;
41+
$this->eavOptionUpdate = $eavOptionUpdate;
2842
}
2943

3044
/**
@@ -33,7 +47,7 @@ public function __construct(
3347
public function getItems($attributeCode)
3448
{
3549
return $this->eavOptionManagement->getItems(
36-
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
50+
ProductAttributeInterface::ENTITY_TYPE_CODE,
3751
$attributeCode
3852
);
3953
}
@@ -44,8 +58,21 @@ public function getItems($attributeCode)
4458
public function add($attributeCode, $option)
4559
{
4660
return $this->eavOptionManagement->add(
47-
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
61+
ProductAttributeInterface::ENTITY_TYPE_CODE,
62+
$attributeCode,
63+
$option
64+
);
65+
}
66+
67+
/**
68+
* @inheritdoc
69+
*/
70+
public function update(string $attributeCode, int $optionId, AttributeOptionInterface $option): bool
71+
{
72+
return $this->eavOptionUpdate->update(
73+
ProductAttributeInterface::ENTITY_TYPE_CODE,
4874
$attributeCode,
75+
$optionId,
4976
$option
5077
);
5178
}
@@ -60,7 +87,7 @@ public function delete($attributeCode, $optionId)
6087
}
6188

6289
return $this->eavOptionManagement->delete(
63-
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
90+
ProductAttributeInterface::ENTITY_TYPE_CODE,
6491
$attributeCode,
6592
$optionId
6693
);

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
/**
1717
* Catalog product option file type
1818
*
19-
* @author Magento Core Team <core@magentocommerce.com>
19+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2020
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2122
*/
2223
class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
2324
{
@@ -181,6 +182,7 @@ protected function _getProcessingParams()
181182

182183
/**
183184
* Returns file info array if we need to get file from already existing file.
185+
*
184186
* Or returns null, if we need to get file from uploaded array.
185187
*
186188
* @return null|array
@@ -262,7 +264,6 @@ public function validateUserValue($values)
262264
. "Make sure the options are entered and try again."
263265
)
264266
);
265-
break;
266267
default:
267268
$this->setUserValue(null);
268269
break;
@@ -330,7 +331,11 @@ public function prepareForCart()
330331
public function getFormattedOptionValue($optionValue)
331332
{
332333
if ($this->_formattedOptionValue === null) {
333-
$value = $this->serializer->unserialize($optionValue);
334+
try {
335+
$value = $this->serializer->unserialize($optionValue);
336+
} catch (\InvalidArgumentException $e) {
337+
return $optionValue;
338+
}
334339
if ($value === null) {
335340
return $optionValue;
336341
}
@@ -476,13 +481,13 @@ public function copyQuoteToOrder()
476481
try {
477482
$value = $this->serializer->unserialize($quoteOption->getValue());
478483
if (!isset($value['quote_path'])) {
479-
throw new \Exception();
484+
return $this;
480485
}
481486
$quotePath = $value['quote_path'];
482487
$orderPath = $value['order_path'];
483488

484489
if (!$this->mediaDirectory->isFile($quotePath) || !$this->mediaDirectory->isReadable($quotePath)) {
485-
throw new \Exception();
490+
return $this;
486491
}
487492

488493
if ($this->_coreFileStorageDatabase->checkDbUsage()) {
@@ -524,6 +529,8 @@ protected function _getOptionDownloadUrl($route, $params)
524529
}
525530

526531
/**
532+
* Prepare size
533+
*
527534
* @param array $value
528535
* @return string
529536
*/

0 commit comments

Comments
 (0)