Skip to content

Commit fd5cf3a

Browse files
Merge pull request #9300 from adobe-commerce-tier-4/Tier4-Kings-PR-10-14-2024
[Support Tier-4-Kings glo28218] 10.14.2024 Regular delivery of bugfixes and improvements
2 parents 3ea2662 + c82c7b8 commit fd5cf3a

File tree

11 files changed

+560
-468
lines changed

11 files changed

+560
-468
lines changed

app/code/Magento/Catalog/view/frontend/web/js/related-products.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ define([
4747
* @return {Boolean} - Prevent default event action and event propagation.
4848
*/
4949
_selectAllRelated: function (e) {
50-
var innerHTML = this.options.relatedProductsCheckFlag ?
51-
this.options.selectAllMessage : this.options.unselectAllMessage;
50+
let isChecked = this.options.relatedProductsCheckFlag;
5251

53-
$(e.target).html(innerHTML);
54-
$(this.options.relatedCheckbox + ':visible').attr(
55-
'checked',
56-
this.options.relatedProductsCheckFlag = !this.options.relatedProductsCheckFlag
57-
);
52+
$(e.target).html(isChecked ? this.options.selectAllMessage : this.options.unselectAllMessage);
53+
this.options.relatedProductsCheckFlag = !isChecked;
54+
55+
$(this.options.relatedCheckbox + ':visible').prop('checked', this.options.relatedProductsCheckFlag);
5856
this._addRelatedToProduct();
5957

6058
return false;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Directory\Test\Fixture;
9+
10+
use Magento\Directory\Model\Currency;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\Locale\FormatInterface;
14+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
15+
16+
/**
17+
* Data fixture for currency rate.
18+
*/
19+
class CurrencyRate implements RevertibleDataFixtureInterface
20+
{
21+
/**
22+
* @var FormatInterface
23+
*/
24+
private $format;
25+
26+
/**
27+
* @var Currency
28+
*/
29+
private $currency;
30+
31+
/**
32+
* @var ResourceConnection
33+
*/
34+
private $resourceConnection;
35+
36+
public function __construct(
37+
FormatInterface $format,
38+
Currency $currency,
39+
ResourceConnection $resourceConnection
40+
) {
41+
$this->format = $format;
42+
$this->currency = $currency;
43+
$this->resourceConnection = $resourceConnection;
44+
}
45+
46+
public function apply(array $data = []): ?DataObject
47+
{
48+
foreach ($data as $currencyCode => $rate) {
49+
foreach ($rate as $currencyTo => $value) {
50+
$value = abs((float) $this->format->getNumber($value));
51+
$data[$currencyCode][$currencyTo] = $value;
52+
}
53+
}
54+
55+
return $this->currency->saveRates($data);
56+
}
57+
58+
public function revert(DataObject $data): void
59+
{
60+
$connection = $this->resourceConnection->getConnection();
61+
$currencyTable = $this->resourceConnection->getTableName('directory_currency_rate');
62+
63+
foreach ($data as $currencyCode => $rate) {
64+
foreach ($rate as $currencyTo) {
65+
$connection->delete(
66+
$currencyTable,
67+
[
68+
'currency_from = ?' => $currencyCode,
69+
'currency_to = ?' => $currencyTo,
70+
]
71+
);
72+
}
73+
}
74+
}
75+
}

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,14 @@ protected function _prepareCustomerQuote($quote)
694694
$hasDefaultBilling = true;
695695
}
696696
}
697-
//save here new customer address
698-
$shippingAddress->setCustomerId($quote->getCustomerId());
699-
$this->addressRepository->save($shippingAddress);
700-
$quote->addCustomerAddress($shippingAddress);
697+
if (!$shippingAddress->getId()) {
698+
//save here new customer address
699+
$shippingAddress->setCustomerId($quote->getCustomerId());
700+
$this->addressRepository->save($shippingAddress);
701+
$quote->addCustomerAddress($shippingAddress);
702+
$this->addressesToSync[] = $shippingAddress->getId();
703+
}
701704
$shipping->setCustomerAddressData($shippingAddress);
702-
$this->addressesToSync[] = $shippingAddress->getId();
703705
$shipping->setCustomerAddressId($shippingAddress->getId());
704706
}
705707
}
@@ -727,11 +729,13 @@ protected function _prepareCustomerQuote($quote)
727729
}
728730
$billingAddress->setIsDefaultBilling(true);
729731
}
730-
$billingAddress->setCustomerId($quote->getCustomerId());
731-
$this->addressRepository->save($billingAddress);
732-
$quote->addCustomerAddress($billingAddress);
732+
if (!$billingAddress->getId()) {
733+
$billingAddress->setCustomerId($quote->getCustomerId());
734+
$this->addressRepository->save($billingAddress);
735+
$quote->addCustomerAddress($billingAddress);
736+
$this->addressesToSync[] = $billingAddress->getId();
737+
}
733738
$billing->setCustomerAddressData($billingAddress);
734-
$this->addressesToSync[] = $billingAddress->getId();
735739
$billing->setCustomerAddressId($billingAddress->getId());
736740

737741
// Admin order: `Same As Billing Address`- when new billing address saved in address book

app/code/Magento/Reports/Block/Adminhtml/Grid/Column/Renderer/Currency.php

Lines changed: 4 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -7,157 +7,37 @@
77

88
namespace Magento\Reports\Block\Adminhtml\Grid\Column\Renderer;
99

10-
use Magento\Backend\Block\Context;
1110
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Currency as BackendCurrency;
12-
use Magento\Directory\Model\Currency\DefaultLocator;
13-
use Magento\Directory\Model\CurrencyFactory;
1411
use Magento\Framework\Currency\Exception\CurrencyException;
1512
use Magento\Framework\DataObject;
16-
use Magento\Framework\Exception\LocalizedException;
17-
use Magento\Framework\Exception\NoSuchEntityException;
18-
use Magento\Framework\Locale\CurrencyInterface;
19-
use Magento\Store\Model\ScopeInterface;
20-
use Magento\Store\Model\Store;
21-
use Magento\Store\Model\StoreManagerInterface;
2213

2314
/**
2415
* Adminhtml grid item renderer currency
2516
*
26-
* @author Magento Core Team <[email protected]>
2717
* @api
2818
* @since 100.0.2
2919
*
30-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3120
*/
3221
class Currency extends BackendCurrency
3322
{
34-
/**
35-
* @var CurrencyFactory
36-
*/
37-
private $currencyFactory;
38-
39-
/**
40-
* @param Context $context
41-
* @param StoreManagerInterface $storeManager
42-
* @param DefaultLocator $currencyLocator
43-
* @param CurrencyFactory $currencyFactory
44-
* @param CurrencyInterface $localeCurrency
45-
* @param array $data
46-
*/
47-
public function __construct(
48-
Context $context,
49-
StoreManagerInterface $storeManager,
50-
DefaultLocator $currencyLocator,
51-
CurrencyFactory $currencyFactory,
52-
CurrencyInterface $localeCurrency,
53-
array $data = []
54-
) {
55-
parent::__construct(
56-
$context,
57-
$storeManager,
58-
$currencyLocator,
59-
$currencyFactory,
60-
$localeCurrency,
61-
$data
62-
);
63-
$this->currencyFactory = $currencyFactory;
64-
}
65-
6623
/**
6724
* Renders grid column
6825
*
6926
* @param DataObject $row
7027
* @return string
71-
* @throws LocalizedException
72-
* @throws NoSuchEntityException
7328
* @throws CurrencyException
7429
*/
7530
public function render(DataObject $row)
7631
{
7732
$data = $row->getData($this->getColumn()->getIndex());
78-
$currencyCode = $this->getStoreCurrencyCode($row);
33+
$currencyCode = $this->_getCurrencyCode($row);
7934

8035
if (!$currencyCode) {
8136
return $data;
8237
}
83-
$rate = $this->getStoreCurrencyRate($currencyCode, $row);
84-
$data = (float) $data * $rate;
38+
$data = (float)$data * $this->_getRate($row);
8539
$data = sprintf('%f', $data);
86-
return $this->_localeCurrency->getCurrency($currencyCode)->toCurrency($data);
87-
}
88-
89-
/**
90-
* Get admin currency code
91-
*
92-
* @return string
93-
* @throws LocalizedException
94-
* @throws NoSuchEntityException
95-
*/
96-
private function getAdminCurrencyCode(): string
97-
{
98-
$adminWebsiteId = (int) $this->_storeManager
99-
->getStore(Store::ADMIN_CODE)
100-
->getWebsiteId();
101-
return (string) $this->_storeManager
102-
->getWebsite($adminWebsiteId)
103-
->getBaseCurrencyCode();
104-
}
105-
106-
/**
107-
* Get store currency code
108-
*
109-
* @param DataObject $row
110-
* @return string
111-
* @throws NoSuchEntityException
112-
*/
113-
private function getStoreCurrencyCode(DataObject $row): string
114-
{
115-
$catalogPriceScope = $this->getCatalogPriceScope();
116-
$storeId = $this->_request->getParam('store_ids');
117-
if ($catalogPriceScope != 0 && !empty($storeId)) {
118-
$currencyCode = $this->_storeManager->getStore($storeId)->getBaseCurrencyCode();
119-
} elseif ($catalogPriceScope != 0) {
120-
$currencyCode = $this->_currencyLocator->getDefaultCurrency($this->_request);
121-
} else {
122-
$currencyCode = $this->_getCurrencyCode($row);
123-
}
124-
return $currencyCode;
125-
}
126-
127-
/**
128-
* Get store currency rate
129-
*
130-
* @param string $currencyCode
131-
* @param DataObject $row
132-
* @return float
133-
* @throws LocalizedException
134-
* @throws NoSuchEntityException
135-
*/
136-
private function getStoreCurrencyRate(string $currencyCode, DataObject $row): float
137-
{
138-
$catalogPriceScope = $this->getCatalogPriceScope();
139-
$adminCurrencyCode = $this->getAdminCurrencyCode();
140-
141-
if (((int)$catalogPriceScope !== 0
142-
&& $adminCurrencyCode !== $currencyCode)) {
143-
$currency = $this->currencyFactory->create()->load($adminCurrencyCode);
144-
$currencyRate = $currency->getAnyRate($currencyCode);
145-
} else {
146-
$currencyRate = $this->_getRate($row);
147-
}
148-
return (float) $currencyRate;
149-
}
150-
151-
/**
152-
* Get catalog price scope from the admin config
153-
*
154-
* @return int
155-
*/
156-
private function getCatalogPriceScope(): int
157-
{
158-
return (int) $this->_scopeConfig->getValue(
159-
Store::XML_PATH_PRICE_SCOPE,
160-
ScopeInterface::SCOPE_WEBSITE
161-
);
40+
$data = $this->_localeCurrency->getCurrency($currencyCode)->toCurrency($data);
41+
return $data;
16242
}
16343
}

0 commit comments

Comments
 (0)