Skip to content

Commit b378594

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into MC-24170
2 parents 08714a3 + 039cce9 commit b378594

File tree

48 files changed

+4445
-236
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

+4445
-236
lines changed

app/code/Magento/Indexer/Setup/Recurring.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
use Magento\Framework\Setup\InstallSchemaInterface;
1414
use Magento\Framework\Setup\ModuleContextInterface;
1515
use Magento\Framework\Setup\SchemaSetupInterface;
16+
use Magento\Framework\Indexer\IndexerInterfaceFactory;
1617
use Magento\Framework\Indexer\ConfigInterface;
1718
use Magento\Indexer\Model\Indexer\State;
1819
use Magento\Indexer\Model\Indexer\StateFactory;
1920
use Magento\Indexer\Model\ResourceModel\Indexer\State\CollectionFactory;
2021

2122
/**
23+
* Indexer recurring setup
24+
*
2225
* @codeCoverageIgnore
2326
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2427
*/
@@ -51,6 +54,11 @@ class Recurring implements InstallSchemaInterface
5154
*/
5255
private $stateFactory;
5356

57+
/**
58+
* @var IndexerInterfaceFactory
59+
*/
60+
private $indexerFactory;
61+
5462
/**
5563
* Init
5664
*
@@ -59,23 +67,26 @@ class Recurring implements InstallSchemaInterface
5967
* @param ConfigInterface $config
6068
* @param EncryptorInterface $encryptor
6169
* @param EncoderInterface $encoder
70+
* @param IndexerInterfaceFactory $indexerFactory
6271
*/
6372
public function __construct(
6473
CollectionFactory $statesFactory,
6574
StateFactory $stateFactory,
6675
ConfigInterface $config,
6776
EncryptorInterface $encryptor,
68-
EncoderInterface $encoder
77+
EncoderInterface $encoder,
78+
IndexerInterfaceFactory $indexerFactory
6979
) {
7080
$this->statesFactory = $statesFactory;
7181
$this->stateFactory = $stateFactory;
7282
$this->config = $config;
7383
$this->encryptor = $encryptor;
7484
$this->encoder = $encoder;
85+
$this->indexerFactory = $indexerFactory;
7586
}
7687

7788
/**
78-
* {@inheritdoc}
89+
* @inheritdoc
7990
*/
8091
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
8192
{
@@ -107,6 +118,11 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
107118
$state->setStatus(StateInterface::STATUS_INVALID);
108119
$state->save();
109120
}
121+
122+
$indexer = $this->indexerFactory->create()->load($indexerId);
123+
if ($indexer->isScheduled()) {
124+
$indexer->getView()->unsubscribe()->subscribe();
125+
}
110126
}
111127
}
112128
}

app/code/Magento/Indexer/Setup/RecurringData.php

Lines changed: 0 additions & 56 deletions
This file was deleted.
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)