Skip to content

Commit 039cce9

Browse files
authored
Merge pull request #5219 from magento-tsg/2.4-develop-com-pr3
[TSG-Commerce] Tests for 2.4 (pr3) (2.4-develop)
2 parents 3e4db87 + e9f5d9d commit 039cce9

File tree

46 files changed

+4427
-178
lines changed

Some content is hidden

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

46 files changed

+4427
-178
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\TestFramework\Catalog\Model\Layer;
9+
10+
use Magento\Catalog\Model\Layer\SearchFactory;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
12+
13+
/**
14+
* Quick search products by query.
15+
*/
16+
class QuickSearchByQuery
17+
{
18+
/**
19+
* @var SearchFactory
20+
*/
21+
private $searchFactory;
22+
23+
/**
24+
* @param SearchFactory $searchFactory
25+
*/
26+
public function __construct(
27+
SearchFactory $searchFactory
28+
) {
29+
$this->searchFactory = $searchFactory;
30+
}
31+
32+
/**
33+
* Flush search instances cache and find products by search query.
34+
*
35+
* @param string $query
36+
* @param string $sortedField
37+
* @param string $sortOrder
38+
* @return Collection
39+
*/
40+
public function execute(
41+
string $query,
42+
string $sortedField = 'relevance',
43+
string $sortOrder = 'desc'
44+
): Collection {
45+
$productCollection = $this->searchFactory->create()->getProductCollection();
46+
$productCollection->addSearchFilter($query);
47+
$productCollection->setOrder($sortedField, $sortOrder);
48+
49+
return $productCollection;
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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\TestFramework\ConfigurableProduct\Model;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\Framework\Registry;
14+
15+
/**
16+
* Delete configurable product with linked products
17+
*/
18+
class DeleteConfigurableProduct
19+
{
20+
/** @var ProductRepositoryInterface */
21+
private $productRepository;
22+
23+
/** @var ProductResource */
24+
private $productResource;
25+
26+
/** @var Registry */
27+
private $registry;
28+
29+
/**
30+
* @param ProductRepositoryInterface $productRepository
31+
* @param ProductResource $productResource
32+
* @param Registry $registry
33+
*/
34+
public function __construct(
35+
ProductRepositoryInterface $productRepository,
36+
ProductResource $productResource,
37+
Registry $registry
38+
) {
39+
$this->productRepository = $productRepository;
40+
$this->productResource = $productResource;
41+
$this->registry = $registry;
42+
}
43+
44+
/**
45+
* Delete configurable product and linked products
46+
*
47+
* @param string $sku
48+
* @return void
49+
*/
50+
public function execute(string $sku): void
51+
{
52+
$configurableProduct = $this->productRepository->get($sku, false, null, true);
53+
$childrenIds = $configurableProduct->getExtensionAttributes()->getConfigurableProductLinks();
54+
$childrenSkus = array_column($this->productResource->getProductsSku($childrenIds), 'sku');
55+
$childrenSkus[] = $sku;
56+
$this->registry->unregister('isSecureArea');
57+
$this->registry->register('isSecureArea', true);
58+
59+
foreach ($childrenSkus as $childSku) {
60+
try {
61+
$this->productRepository->deleteById($childSku);
62+
} catch (NoSuchEntityException $e) {
63+
//product already removed
64+
}
65+
}
66+
67+
$this->registry->unregister('isSecureArea');
68+
$this->registry->register('isSecureArea', false);
69+
}
70+
}

0 commit comments

Comments
 (0)