Skip to content

Commit 610f7f5

Browse files
authored
Merge pull request #7593 from magento-amigos/2.4-develop-prs
[Amigos] Community Contributions - 2.4-develop
2 parents ef0ffcd + d329ac7 commit 610f7f5

File tree

20 files changed

+443
-142
lines changed

20 files changed

+443
-142
lines changed

app/code/Magento/Catalog/Model/Product/Price/BasePriceStorage.php

Lines changed: 84 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@
66

77
namespace Magento\Catalog\Model\Product\Price;
88

9+
use Magento\Catalog\Api\BasePriceStorageInterface;
10+
use Magento\Catalog\Api\Data\BasePriceInterface;
11+
use Magento\Catalog\Api\Data\BasePriceInterfaceFactory;
12+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
13+
use Magento\Catalog\Api\ProductRepositoryInterface;
14+
use Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor;
15+
use Magento\Catalog\Model\Product\Price\Validation\Result;
16+
use Magento\Catalog\Model\ProductIdLocatorInterface;
17+
use Magento\Framework\App\ObjectManager;
18+
use Magento\Framework\Exception\NoSuchEntityException;
19+
use Magento\Store\Api\StoreRepositoryInterface;
20+
use Magento\Store\Model\Store;
21+
922
/**
1023
* Base prices storage.
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1125
*/
12-
class BasePriceStorage implements \Magento\Catalog\Api\BasePriceStorageInterface
26+
class BasePriceStorage implements BasePriceStorageInterface
1327
{
1428
/**
15-
* Attribute code.
29+
* Price attribute code.
1630
*
1731
* @var string
1832
*/
@@ -24,27 +38,27 @@ class BasePriceStorage implements \Magento\Catalog\Api\BasePriceStorageInterface
2438
private $pricePersistence;
2539

2640
/**
27-
* @var \Magento\Catalog\Api\Data\BasePriceInterfaceFactory
41+
* @var BasePriceInterfaceFactory
2842
*/
2943
private $basePriceInterfaceFactory;
3044

3145
/**
32-
* @var \Magento\Catalog\Model\ProductIdLocatorInterface
46+
* @var ProductIdLocatorInterface
3347
*/
3448
private $productIdLocator;
3549

3650
/**
37-
* @var \Magento\Store\Api\StoreRepositoryInterface
51+
* @var StoreRepositoryInterface
3852
*/
3953
private $storeRepository;
4054

4155
/**
42-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
56+
* @var ProductRepositoryInterface
4357
*/
4458
private $productRepository;
4559

4660
/**
47-
* @var \Magento\Catalog\Model\Product\Price\Validation\Result
61+
* @var Result
4862
*/
4963
private $validationResult;
5064

@@ -54,43 +68,50 @@ class BasePriceStorage implements \Magento\Catalog\Api\BasePriceStorageInterface
5468
private $pricePersistenceFactory;
5569

5670
/**
57-
* @var \Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor
71+
* @var InvalidSkuProcessor
5872
*/
5973
private $invalidSkuProcessor;
6074

6175
/**
62-
* Price type allowed.
76+
* @var ProductAttributeRepositoryInterface
77+
*/
78+
private $productAttributeRepository;
79+
80+
/**
81+
* Is price type allowed
6382
*
6483
* @var int
6584
*/
6685
private $priceTypeAllowed = 1;
6786

6887
/**
69-
* Allowed product types.
88+
* Array of allowed product types.
7089
*
7190
* @var array
7291
*/
7392
private $allowedProductTypes = [];
7493

7594
/**
7695
* @param PricePersistenceFactory $pricePersistenceFactory
77-
* @param \Magento\Catalog\Api\Data\BasePriceInterfaceFactory $basePriceInterfaceFactory
78-
* @param \Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator
79-
* @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
80-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
81-
* @param \Magento\Catalog\Model\Product\Price\Validation\Result $validationResult
82-
* @param \Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor $invalidSkuProcessor
96+
* @param BasePriceInterfaceFactory $basePriceInterfaceFactory
97+
* @param ProductIdLocatorInterface $productIdLocator
98+
* @param StoreRepositoryInterface $storeRepository
99+
* @param ProductRepositoryInterface $productRepository
100+
* @param Result $validationResult
101+
* @param InvalidSkuProcessor $invalidSkuProcessor
83102
* @param array $allowedProductTypes [optional]
103+
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
84104
*/
85105
public function __construct(
86106
PricePersistenceFactory $pricePersistenceFactory,
87-
\Magento\Catalog\Api\Data\BasePriceInterfaceFactory $basePriceInterfaceFactory,
88-
\Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator,
89-
\Magento\Store\Api\StoreRepositoryInterface $storeRepository,
90-
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
91-
\Magento\Catalog\Model\Product\Price\Validation\Result $validationResult,
92-
\Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor $invalidSkuProcessor,
93-
array $allowedProductTypes = []
107+
BasePriceInterfaceFactory $basePriceInterfaceFactory,
108+
ProductIdLocatorInterface $productIdLocator,
109+
StoreRepositoryInterface $storeRepository,
110+
ProductRepositoryInterface $productRepository,
111+
Result $validationResult,
112+
InvalidSkuProcessor $invalidSkuProcessor,
113+
array $allowedProductTypes = [],
114+
ProductAttributeRepositoryInterface $productAttributeRepository = null
94115
) {
95116
$this->pricePersistenceFactory = $pricePersistenceFactory;
96117
$this->basePriceInterfaceFactory = $basePriceInterfaceFactory;
@@ -100,10 +121,12 @@ public function __construct(
100121
$this->validationResult = $validationResult;
101122
$this->allowedProductTypes = $allowedProductTypes;
102123
$this->invalidSkuProcessor = $invalidSkuProcessor;
124+
$this->productAttributeRepository = $productAttributeRepository ?: ObjectManager::getInstance()
125+
->get(ProductAttributeRepositoryInterface::class);
103126
}
104127

105128
/**
106-
* {@inheritdoc}
129+
* @inheritdoc
107130
*/
108131
public function get(array $skus)
109132
{
@@ -128,7 +151,7 @@ public function get(array $skus)
128151
}
129152

130153
/**
131-
* {@inheritdoc}
154+
* @inheritdoc
132155
*/
133156
public function update(array $prices)
134157
{
@@ -146,6 +169,12 @@ public function update(array $prices)
146169
}
147170
}
148171

172+
$priceAttribute = $this->productAttributeRepository->get($this->attributeCode);
173+
174+
if ($priceAttribute !== null && $priceAttribute->isScopeWebsite()) {
175+
$formattedPrices = $this->applyWebsitePrices($formattedPrices);
176+
}
177+
149178
$this->getPricePersistence()->update($formattedPrices);
150179

151180
return $this->validationResult->getFailedItems();
@@ -168,7 +197,7 @@ private function getPricePersistence()
168197
/**
169198
* Retrieve valid prices that do not contain any errors.
170199
*
171-
* @param \Magento\Catalog\Api\Data\BasePriceInterface[] $prices
200+
* @param BasePriceInterface[] $prices
172201
* @return array
173202
*/
174203
private function retrieveValidPrices(array $prices)
@@ -207,7 +236,7 @@ private function retrieveValidPrices(array $prices)
207236
}
208237
try {
209238
$this->storeRepository->getById($price->getStoreId());
210-
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
239+
} catch (NoSuchEntityException $e) {
211240
$this->validationResult->addFailedItem(
212241
$id,
213242
__(
@@ -225,4 +254,32 @@ private function retrieveValidPrices(array $prices)
225254

226255
return $prices;
227256
}
257+
258+
/**
259+
* If Catalog Price Mode is Website, price needs to be applied to all Store Views in this website.
260+
*
261+
* @param array $formattedPrices
262+
* @return array
263+
* @throws NoSuchEntityException
264+
*/
265+
private function applyWebsitePrices($formattedPrices): array
266+
{
267+
foreach ($formattedPrices as $price) {
268+
if ($price['store_id'] == Store::DEFAULT_STORE_ID) {
269+
continue;
270+
}
271+
272+
$storeIds = $this->storeRepository->getById($price['store_id'])->getWebsite()->getStoreIds();
273+
274+
// Unset origin store view to get rid of duplicate
275+
unset($storeIds[$price['store_id']]);
276+
277+
foreach ($storeIds as $storeId) {
278+
$price['store_id'] = (int)$storeId;
279+
$formattedPrices[] = $price;
280+
}
281+
}
282+
283+
return $formattedPrices;
284+
}
228285
}

app/code/Magento/NewRelicReporting/Console/Command/DeployMarker.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DeployMarker extends Command
2929
*
3030
* @param DeploymentsFactory $deploymentsFactory
3131
* @param ServiceShellUser $serviceShellUser
32-
* @param null $name
32+
* @param ?string $name
3333
*/
3434
public function __construct(
3535
DeploymentsFactory $deploymentsFactory,
@@ -42,7 +42,7 @@ public function __construct(
4242
}
4343

4444
/**
45-
* {@inheritdoc}
45+
* @inheritdoc
4646
*/
4747
protected function configure()
4848
{
@@ -62,20 +62,27 @@ protected function configure()
6262
'user',
6363
InputArgument::OPTIONAL,
6464
'Deployment User'
65+
)->addArgument(
66+
'revision',
67+
InputArgument::OPTIONAL,
68+
'Revision'
6569
);
6670
parent::configure();
6771
}
6872

6973
/**
70-
* {@inheritdoc}
74+
* @inheritdoc
7175
*/
7276
protected function execute(InputInterface $input, OutputInterface $output)
7377
{
7478
$this->deploymentsFactory->create()->setDeployment(
7579
$input->getArgument('message'),
7680
$input->getArgument('change_log'),
77-
$this->serviceShellUser->get($input->getArgument('user'))
81+
$this->serviceShellUser->get($input->getArgument('user')),
82+
$input->getArgument('revision')
7883
);
7984
$output->writeln('<info>NewRelic deployment information sent</info>');
85+
86+
return 0;
8087
}
8188
}

app/code/Magento/NewRelicReporting/Model/Apm/Deployments.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Deployments
1515
/**
1616
* API URL for New Relic deployments
1717
*/
18-
const API_URL = 'https://api.newrelic.com/deployments.xml';
18+
private const API_URL = 'https://api.newrelic.com/v2/applications/%s/deployments.json';
1919

2020
/**
2121
* @var \Magento\NewRelicReporting\Model\Config
@@ -55,31 +55,43 @@ public function __construct(
5555
* @param string $description
5656
* @param bool $change
5757
* @param bool $user
58+
* @param ?string $revision
5859
*
5960
* @return bool|string
6061
*/
61-
public function setDeployment($description, $change = false, $user = false)
62+
public function setDeployment($description, $change = false, $user = false, $revision = null)
6263
{
6364
$apiUrl = $this->config->getNewRelicApiUrl();
64-
6565
if (empty($apiUrl)) {
6666
$this->logger->notice('New Relic API URL is blank, using fallback URL');
6767
$apiUrl = self::API_URL;
6868
}
6969

70+
$apiUrl = sprintf($apiUrl, $this->config->getNewRelicAppId());
71+
7072
/** @var \Magento\Framework\HTTP\ZendClient $client */
7173
$client = $this->clientFactory->create();
7274
$client->setUri($apiUrl);
7375
$client->setMethod(ZendClient::POST);
7476

75-
$client->setHeaders(['x-api-key' => $this->config->getNewRelicApiKey()]);
77+
$client->setHeaders(
78+
[
79+
'Api-Key' => $this->config->getNewRelicApiKey(),
80+
'Content-Type' => 'application/json'
81+
]
82+
);
83+
84+
if (!$revision) {
85+
$revision = hash('sha256', time());
86+
}
7687

7788
$params = [
78-
'deployment[app_name]' => $this->config->getNewRelicAppName(),
79-
'deployment[application_id]' => $this->config->getNewRelicAppId(),
80-
'deployment[description]' => $description,
81-
'deployment[changelog]' => $change,
82-
'deployment[user]' => $user
89+
'deployment' => [
90+
'description' => $description,
91+
'changelog' => $change,
92+
'user' => $user,
93+
'revision' => $revision
94+
]
8395
];
8496

8597
$client->setParameterPost($params);

0 commit comments

Comments
 (0)