Skip to content

Commit 04eab75

Browse files
authored
Merge branch 'magento-commerce:2.4-develop' into comm_78764_32435
2 parents fcbf9bb + ffeb0a0 commit 04eab75

File tree

48 files changed

+2128
-523
lines changed

Some content is hidden

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

48 files changed

+2128
-523
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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\AdvancedSearch\Helper;
9+
10+
use Magento\Framework\App\Helper\Context;
11+
use Magento\Framework\Search\EngineResolverInterface;
12+
use Magento\Framework\App\Helper\AbstractHelper;
13+
use OpenSearch\Client;
14+
15+
class Data extends AbstractHelper
16+
{
17+
18+
public const OPENSEARCH = 'opensearch';
19+
public const MAJOR_VERSION = '2';
20+
21+
/**
22+
* @var EngineResolverInterface
23+
*/
24+
public $engineResolver;
25+
26+
/**
27+
* @param Context $context
28+
* @param EngineResolverInterface $engineResolver
29+
*/
30+
public function __construct(
31+
Context $context,
32+
EngineResolverInterface $engineResolver
33+
) {
34+
parent::__construct($context);
35+
$this->engineResolver = $engineResolver;
36+
}
37+
38+
/**
39+
* Check if opensearch v2.x
40+
*
41+
* @return bool
42+
*/
43+
public function isClientOpenSearchV2(): bool
44+
{
45+
$searchEngine = $this->engineResolver->getCurrentSearchEngine();
46+
if (stripos($searchEngine, self::OPENSEARCH) !== false) {
47+
if (substr(Client::VERSION, 0, 1) == self::MAJOR_VERSION) {
48+
return true;
49+
}
50+
}
51+
return false;
52+
}
53+
}

app/code/Magento/AdvancedSearch/Model/Client/ClientFactory.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
namespace Magento\AdvancedSearch\Model\Client;
77

88
use Magento\Framework\ObjectManagerInterface;
9+
use Magento\AdvancedSearch\Helper\Data;
910

1011
class ClientFactory implements ClientFactoryInterface
1112
{
1213
/**
13-
* Object manager
14+
* Object var
1415
*
1516
* @var ObjectManagerInterface
1617
*/
@@ -21,14 +22,32 @@ class ClientFactory implements ClientFactoryInterface
2122
*/
2223
private $clientClass;
2324

25+
/**
26+
* @var string
27+
*/
28+
private $openSearch;
29+
30+
/**
31+
* @var Data
32+
*/
33+
protected $helper;
34+
2435
/**
2536
* @param ObjectManagerInterface $objectManager
2637
* @param string $clientClass
38+
* @param Data $helper
39+
* @param string|null $openSearch
2740
*/
28-
public function __construct(ObjectManagerInterface $objectManager, $clientClass)
29-
{
41+
public function __construct(
42+
ObjectManagerInterface $objectManager,
43+
$clientClass,
44+
Data $helper,
45+
$openSearch = null
46+
) {
3047
$this->objectManager = $objectManager;
3148
$this->clientClass = $clientClass;
49+
$this->openSearch = $openSearch;
50+
$this->helper = $helper;
3251
}
3352

3453
/**
@@ -39,8 +58,13 @@ public function __construct(ObjectManagerInterface $objectManager, $clientClass)
3958
*/
4059
public function create(array $options = [])
4160
{
61+
$class = $this->clientClass;
62+
if ($this->helper->isClientOpenSearchV2()) {
63+
$class = $this->openSearch;
64+
}
65+
4266
return $this->objectManager->create(
43-
$this->clientClass,
67+
$class,
4468
['options' => $options]
4569
);
4670
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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\AdvancedSearch\Test\Unit\Helper;
9+
10+
use Magento\AdvancedSearch\Helper\Data;
11+
use Magento\Framework\App\Helper\Context;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
use Magento\Framework\Search\EngineResolverInterface;
16+
17+
/**
18+
* @covers \Magento\AdvancedSearch\Helper\Data
19+
*/
20+
class DataTest extends TestCase
21+
{
22+
23+
/**
24+
* @var Data
25+
*/
26+
private $helper;
27+
28+
/**
29+
* @var Context|MockObject
30+
*/
31+
private $contextMock;
32+
33+
/**
34+
* @var EngineResolverInterface|MockObject
35+
*/
36+
private $engineResolverMock;
37+
38+
/**
39+
* @var ObjectManagerHelper
40+
*/
41+
private $objectManager;
42+
43+
/**
44+
* @return void
45+
*/
46+
protected function setUp(): void
47+
{
48+
$this->contextMock = $this->getMockBuilder(Context::class)
49+
->disableOriginalConstructor()
50+
->getMock();
51+
52+
$this->engineResolverMock = $this->getMockForAbstractClass(EngineResolverInterface::class);
53+
54+
$this->engineResolverMock->expects($this->any())
55+
->method('getCurrentSearchEngine')
56+
->willReturn('');
57+
58+
$this->objectManager = new ObjectManagerHelper($this);
59+
$this->helper = $this->objectManager->getObject(
60+
Data::class,
61+
[
62+
'context' => $this->contextMock,
63+
'engineResolver' => $this->engineResolverMock
64+
]
65+
);
66+
}
67+
68+
public function testIsClientOpenSearchV2()
69+
{
70+
$this->assertIsBool($this->helper->isClientOpenSearchV2());
71+
}
72+
}

app/code/Magento/AsynchronousOperations/Controller/Adminhtml/Notification/Dismiss.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
use Magento\AsynchronousOperations\Model\BulkNotificationManagement;
99
use Magento\Backend\App\Action\Context;
1010
use Magento\Backend\App\Action;
11+
use Magento\Framework\App\Action\HttpGetActionInterface;
1112
use Magento\Framework\Controller\ResultFactory;
1213

1314
/**
1415
* Class Bulk Notification Dismiss Controller
1516
*/
16-
class Dismiss extends Action
17+
class Dismiss extends Action implements HttpGetActionInterface
1718
{
1819
/**
1920
* @var BulkNotificationManagement
@@ -43,7 +44,7 @@ protected function _isAllowed()
4344
}
4445

4546
/**
46-
* {@inheritdoc}
47+
* @inheritdoc
4748
*/
4849
public function execute()
4950
{
@@ -55,7 +56,7 @@ public function execute()
5556
$isAcknowledged = $this->notificationManagement->acknowledgeBulks($bulkUuids);
5657

5758
/** @var \Magento\Framework\Controller\Result\Json $result */
58-
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
59+
$result = $this->resultFactory->create(ResultFactory::TYPE_RAW);
5960
if (!$isAcknowledged) {
6061
$result->setHttpResponseCode(400);
6162
}

app/code/Magento/AsynchronousOperations/Test/Unit/Controller/Adminhtml/Notification/DismissTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\AsynchronousOperations\Model\BulkNotificationManagement;
1212
use Magento\Framework\App\RequestInterface;
1313
use Magento\Framework\Controller\Result\Json;
14+
use Magento\Framework\Controller\Result\Raw;
1415
use Magento\Framework\Controller\ResultFactory;
1516
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1617
use PHPUnit\Framework\MockObject\MockObject;
@@ -43,6 +44,11 @@ class DismissTest extends TestCase
4344
*/
4445
private $jsonResultMock;
4546

47+
/**
48+
* @var MockObject
49+
*/
50+
private $rawResultMock;
51+
4652
protected function setUp(): void
4753
{
4854
$objectManager = new ObjectManager($this);
@@ -78,10 +84,10 @@ public function testExecute()
7884

7985
$this->resultFactoryMock->expects($this->once())
8086
->method('create')
81-
->with(ResultFactory::TYPE_JSON, [])
82-
->willReturn($this->jsonResultMock);
87+
->with(ResultFactory::TYPE_RAW, [])
88+
->willReturn($this->rawResultMock);
8389

84-
$this->assertEquals($this->jsonResultMock, $this->model->execute());
90+
$this->assertEquals($this->rawResultMock, $this->model->execute());
8591
}
8692

8793
public function testExecuteSetsBadRequestResponseStatusIfBulkWasNotAcknowledgedCorrectly()
@@ -95,7 +101,7 @@ public function testExecuteSetsBadRequestResponseStatusIfBulkWasNotAcknowledgedC
95101

96102
$this->resultFactoryMock->expects($this->once())
97103
->method('create')
98-
->with(ResultFactory::TYPE_JSON, [])
104+
->with(ResultFactory::TYPE_RAW, [])
99105
->willReturn($this->jsonResultMock);
100106

101107
$this->notificationManagementMock->expects($this->once())

app/code/Magento/Catalog/Test/Fixture/Product.php

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
1111
use Magento\Catalog\Api\Data\ProductInterface;
1212
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Catalog\Model\Config\Source\ProductPriceOptionsInterface;
1314
use Magento\Catalog\Model\Product\Attribute\Source\Status;
15+
use Magento\Catalog\Model\Product\Option as CustomOption;
16+
use Magento\Catalog\Model\Product\Option\Value as CustomOptionValue;
1417
use Magento\Catalog\Model\Product\Type;
1518
use Magento\Catalog\Model\Product\Visibility;
1619
use Magento\Framework\DataObject;
@@ -198,21 +201,57 @@ private function prepareOptions(array $data): array
198201
{
199202
$options = [];
200203
$default = [
201-
'product_sku' => $data['sku'],
202-
'title' => 'customoption%order%%uniqid%',
203-
'type' => ProductCustomOptionInterface::OPTION_TYPE_FIELD,
204-
'is_require' => true,
205-
'price' => 10.0,
206-
'price_type' => 'fixed',
207-
'sku' => 'customoption%order%%uniqid%',
208-
'max_characters' => null,
204+
CustomOption::KEY_PRODUCT_SKU => $data['sku'],
205+
CustomOption::KEY_TITLE => 'customoption%order%%uniqid%',
206+
CustomOption::KEY_TYPE => ProductCustomOptionInterface::OPTION_TYPE_FIELD,
207+
CustomOption::KEY_IS_REQUIRE => true,
208+
CustomOption::KEY_PRICE => 10.0,
209+
CustomOption::KEY_PRICE_TYPE => ProductPriceOptionsInterface::VALUE_FIXED,
210+
CustomOption::KEY_SKU => 'customoption%order%%uniqid%',
211+
CustomOption::KEY_MAX_CHARACTERS => null,
212+
CustomOption::KEY_SORT_ORDER => 1,
209213
'values' => null,
210214
];
215+
$defaultValue = [
216+
CustomOptionValue::KEY_TITLE => 'customoption%order%_%valueorder%%uniqid%',
217+
CustomOptionValue::KEY_PRICE => 1,
218+
CustomOptionValue::KEY_PRICE_TYPE => ProductPriceOptionsInterface::VALUE_FIXED,
219+
CustomOptionValue::KEY_SKU => 'customoption%order%_%valueorder%%uniqid%',
220+
CustomOptionValue::KEY_SORT_ORDER => 1,
221+
];
211222
$sortOrder = 1;
212223
foreach ($data['options'] as $item) {
213-
$option = $item + ['sort_order' => $sortOrder++] + $default;
214-
$option['title'] = strtr($option['title'], ['%order%' => $option['sort_order']]);
215-
$option['sku'] = strtr($option['sku'], ['%order%' => $option['sort_order']]);
224+
$option = $item + [CustomOption::KEY_SORT_ORDER => $sortOrder++] + $default;
225+
$option[CustomOption::KEY_TITLE] = strtr(
226+
$option[CustomOption::KEY_TITLE],
227+
['%order%' => $option[CustomOption::KEY_SORT_ORDER]]
228+
);
229+
$option[CustomOption::KEY_SKU] = strtr(
230+
$option[CustomOption::KEY_SKU],
231+
['%order%' => $option[CustomOption::KEY_SORT_ORDER]]
232+
);
233+
if (isset($item['values'])) {
234+
$valueSortOrder = 1;
235+
$option['values'] = [];
236+
foreach ($item['values'] as $value) {
237+
$value += [CustomOptionValue::KEY_SORT_ORDER => $valueSortOrder++] + $defaultValue;
238+
$value[CustomOptionValue::KEY_TITLE] = strtr(
239+
$value[CustomOptionValue::KEY_TITLE],
240+
[
241+
'%order%' => $option[CustomOption::KEY_SORT_ORDER],
242+
'%valueorder%' => $value[CustomOptionValue::KEY_SORT_ORDER]
243+
]
244+
);
245+
$value[CustomOptionValue::KEY_SKU] = strtr(
246+
$value[CustomOptionValue::KEY_SKU],
247+
[
248+
'%order%' => $option[CustomOption::KEY_SORT_ORDER],
249+
'%valueorder%' => $value[CustomOptionValue::KEY_SORT_ORDER]
250+
]
251+
);
252+
$option['values'][] = $value;
253+
}
254+
}
216255
$options[] = $option;
217256
}
218257

0 commit comments

Comments
 (0)