Skip to content

Commit a898dde

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-1682' into PR_6_MAR_2023
2 parents 809f75b + b8f8ed5 commit a898dde

File tree

5 files changed

+304
-107
lines changed

5 files changed

+304
-107
lines changed

app/code/Magento/ProductAlert/Model/Mailing/AlertProcessor.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\ProductAlert\Model\Mailing;
99

10-
use Magento\Framework\App\Area;
1110
use Magento\Catalog\Api\Data\ProductInterface;
1211
use Magento\Catalog\Api\ProductRepositoryInterface;
1312
use Magento\Catalog\Helper\Data;
@@ -25,15 +24,11 @@
2524
use Magento\Store\Api\Data\WebsiteInterface;
2625
use Magento\Store\Model\StoreManagerInterface;
2726
use Magento\Store\Model\Website;
28-
use Magento\Framework\App\ObjectManager;
29-
use Magento\Framework\View\DesignInterface;
3027

3128
/**
3229
* Class for mailing Product Alerts
3330
*
34-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3531
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
36-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
3732
*/
3833
class AlertProcessor
3934
{
@@ -85,11 +80,6 @@ class AlertProcessor
8580
*/
8681
private $errorEmailSender;
8782

88-
/**
89-
* @var DesignInterface
90-
*/
91-
private $design;
92-
9383
/**
9484
* @param EmailFactory $emailFactory
9585
* @param PriceCollectionFactory $priceCollectionFactory
@@ -100,7 +90,6 @@ class AlertProcessor
10090
* @param ProductSalability $productSalability
10191
* @param StoreManagerInterface $storeManager
10292
* @param ErrorEmailSender $errorEmailSender
103-
* @param DesignInterface|null $design
10493
*/
10594
public function __construct(
10695
EmailFactory $emailFactory,
@@ -111,8 +100,7 @@ public function __construct(
111100
Data $catalogData,
112101
ProductSalability $productSalability,
113102
StoreManagerInterface $storeManager,
114-
ErrorEmailSender $errorEmailSender,
115-
DesignInterface $design = null
103+
ErrorEmailSender $errorEmailSender
116104
) {
117105
$this->emailFactory = $emailFactory;
118106
$this->priceCollectionFactory = $priceCollectionFactory;
@@ -123,8 +111,6 @@ public function __construct(
123111
$this->productSalability = $productSalability;
124112
$this->storeManager = $storeManager;
125113
$this->errorEmailSender = $errorEmailSender;
126-
$this->design = $design ?: ObjectManager::getInstance()
127-
->get(DesignInterface::class);
128114
}
129115

130116
/**
@@ -159,12 +145,6 @@ public function process(string $alertType, array $customerIds, int $websiteId):
159145
*/
160146
private function processAlerts(string $alertType, array $customerIds, int $websiteId): array
161147
{
162-
//Set the current design theme
163-
$this->design->setDesignTheme(
164-
$this->design->getConfigurationDesignTheme(Area::AREA_FRONTEND),
165-
Area::AREA_FRONTEND
166-
);
167-
168148
/** @var Email $email */
169149
$email = $this->emailFactory->create();
170150
$email->setType($alertType);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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\ProductAlert\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\ProductAlert\Model\PriceFactory;
12+
use Magento\ProductAlert\Model\ResourceModel\Price;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\TestFramework\Fixture\DataFixtureInterface;
15+
16+
class PriceAlert implements DataFixtureInterface
17+
{
18+
private const DEFAULT_DATA = [
19+
'customer_id' => null,
20+
'product_id' => null,
21+
'store_id' => 1,
22+
'website_id' => null,
23+
'price' => 11,
24+
];
25+
26+
/**
27+
* @var PriceFactory
28+
*/
29+
private PriceFactory $factory;
30+
31+
/**
32+
* @var Price
33+
*/
34+
private Price $resourceModel;
35+
36+
/**
37+
* @var StoreManagerInterface
38+
*/
39+
private StoreManagerInterface $storeManager;
40+
41+
/**
42+
* @param PriceFactory $factory
43+
* @param Price $resourceModel
44+
* @param StoreManagerInterface $storeManager
45+
*/
46+
public function __construct(
47+
PriceFactory $factory,
48+
Price $resourceModel,
49+
StoreManagerInterface $storeManager
50+
) {
51+
$this->factory = $factory;
52+
$this->resourceModel = $resourceModel;
53+
$this->storeManager = $storeManager;
54+
}
55+
56+
/**
57+
* {@inheritdoc}
58+
* @param array $data Parameters
59+
* <pre>
60+
* $data = [
61+
* 'customer_id' => (int) Customer ID. Required.
62+
* 'product_id' => (int) Product ID. Required.
63+
* 'store_id' => (int) Store ID. Optional. Default: default store.
64+
* 'website_id' => (int) Website ID. Optional. Default: default website.
65+
* 'price' => (float) Initial Price. Optional. Default: 11.
66+
* ]
67+
* </pre>
68+
*/
69+
public function apply(array $data = []): ?DataObject
70+
{
71+
$data = array_merge(self::DEFAULT_DATA, $data);
72+
$data['website_id'] ??= $this->storeManager->getStore($data['store_id'])->getWebsiteId();
73+
$model = $this->factory->create();
74+
$model->addData($data);
75+
$this->resourceModel->save($model);
76+
77+
return $model;
78+
}
79+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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\ProductAlert\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\ProductAlert\Model\StockFactory;
12+
use Magento\ProductAlert\Model\ResourceModel\Stock;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\TestFramework\Fixture\DataFixtureInterface;
15+
16+
class StockAlert implements DataFixtureInterface
17+
{
18+
private const DEFAULT_DATA = [
19+
'customer_id' => null,
20+
'product_id' => null,
21+
'store_id' => 1,
22+
'website_id' => null,
23+
'status' => 0,
24+
];
25+
26+
/**
27+
* @var StockFactory
28+
*/
29+
private StockFactory $factory;
30+
31+
/**
32+
* @var Stock
33+
*/
34+
private Stock $resourceModel;
35+
36+
/**
37+
* @var StoreManagerInterface
38+
*/
39+
private StoreManagerInterface $storeManager;
40+
41+
/**
42+
* @param StockFactory $factory
43+
* @param Stock $resourceModel
44+
* @param StoreManagerInterface $storeManager
45+
*/
46+
public function __construct(
47+
StockFactory $factory,
48+
Stock $resourceModel,
49+
StoreManagerInterface $storeManager
50+
) {
51+
$this->factory = $factory;
52+
$this->resourceModel = $resourceModel;
53+
$this->storeManager = $storeManager;
54+
}
55+
56+
/**
57+
* {@inheritdoc}
58+
* @param array $data Parameters
59+
* <pre>
60+
* $data = [
61+
* 'customer_id' => (int) Customer ID. Required.
62+
* 'product_id' => (int) Product ID. Required.
63+
* 'store_id' => (int) Store ID. Optional. Default: default store.
64+
* 'website_id' => (int) Website ID. Optional. Default: default website.
65+
* 'status' => (int) Alert Status. Optional. Default: 0.
66+
* ]
67+
* </pre>
68+
*/
69+
public function apply(array $data = []): ?DataObject
70+
{
71+
$data = array_merge(self::DEFAULT_DATA, $data);
72+
$data['website_id'] ??= $this->storeManager->getStore($data['store_id'])->getWebsiteId();
73+
$model = $this->factory->create();
74+
$model->addData($data);
75+
$this->resourceModel->save($model);
76+
77+
return $model;
78+
}
79+
}

app/code/Magento/Store/Model/App/Emulation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ public function startEnvironmentEmulation(
147147
return;
148148
}
149149

150-
if ($storeId == $this->_storeManager->getStore()->getStoreId() && !$force) {
150+
if (!$force
151+
&& ($storeId == $this->_storeManager->getStore()->getId() && $this->_viewDesign->getArea() === $area)
152+
) {
151153
return;
152154
}
153155
$this->storeCurrentEnvironmentInfo();

0 commit comments

Comments
 (0)