Skip to content

Commit 9af794a

Browse files
Merge pull request #9000 from adobe-commerce-tier-4/Tier4-Kings-PR-06-12-2024
[Support Tier-4-Kings glo23503] 06.12.2024 Regular delivery of bugfixes and improvements
2 parents 3e50ec8 + a12c022 commit 9af794a

File tree

11 files changed

+435
-41
lines changed

11 files changed

+435
-41
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Category/Move.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function afterChangeParent(
7575
$categoryStoreId = $category->getStoreId();
7676
foreach ($category->getStoreIds() as $storeId) {
7777
$category->setStoreId($storeId);
78-
$this->removeObsoleteUrlPathEntries($category);
78+
$this->removeObsoleteUrlPathEntries($category, $categoryStoreId);
7979
$this->updateCategoryUrlKeyForStore($category);
8080
$category->unsUrlPath();
8181
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
@@ -121,9 +121,10 @@ private function updateUrlPathForChildren(Category $category): void
121121
* Clean obsolete entries
122122
*
123123
* @param Category $category
124+
* @param int $categoryStoreId
124125
* @return void
125126
*/
126-
private function removeObsoleteUrlPathEntries(Category $category): void
127+
private function removeObsoleteUrlPathEntries(Category $category, $categoryStoreId): void
127128
{
128129
if ($this->storeManager->hasSingleStore()) {
129130
return;
@@ -132,6 +133,10 @@ private function removeObsoleteUrlPathEntries(Category $category): void
132133
$path = $category->getData('path');
133134
if ($origPath != null && $path != null && $origPath != $path) {
134135
$category->unsUrlPath();
136+
if ($category->getStoreId() !== $categoryStoreId) {
137+
$category->setStoreId($categoryStoreId);
138+
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
139+
}
135140
$category->getResource()->saveAttribute($category, 'url_path');
136141
foreach ($this->childrenCategoriesProvider->getChildren($category, true) as $childCategory) {
137142
$childCategory->unsUrlPath();

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/Plugin/Category/MoveTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ public function testAfterChangeParent()
117117
$storeIds = [0, 1];
118118

119119
$this->storeManagerMock->expects($this->exactly(2))->method('hasSingleStore')->willReturn(false);
120-
$this->categoryMock->expects($this->exactly(4))->method('getStoreId')
121-
->willReturnOnConsecutiveCalls(0, 0, 1, 0);
120+
$this->categoryMock->expects($this->exactly(6))->method('getStoreId')
121+
->willReturnOnConsecutiveCalls(0, 0, 1, 0, 1, 0);
122122
$this->categoryMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds);
123-
$this->categoryMock->expects($this->exactly(4))->method('setStoreId')
124-
->willReturnOnConsecutiveCalls(0, 0, 1, 0);
123+
$this->categoryMock->expects($this->exactly(5))->method('setStoreId')
124+
->willReturnOnConsecutiveCalls(0, 0, 1, 0, 1);
125125

126126
$this->categoryMock->expects($this->exactly(2))->method('getData')
127127
->willReturnOnConsecutiveCalls('1/3/5', '1/3/5');
@@ -146,9 +146,9 @@ public function testAfterChangeParent()
146146
$this->categoryMock->expects($this->exactly(2))->method('setUrlKey')->with('url-key')
147147
->willReturnSelf();
148148

149-
$this->categoryUrlPathGeneratorMock->expects($this->exactly(3))->method('getUrlPath')
149+
$this->categoryUrlPathGeneratorMock->expects($this->exactly(4))->method('getUrlPath')
150150
->with($this->categoryMock)->willReturn($urlPath);
151-
$this->categoryMock->expects($this->exactly(3))->method('setUrlPath')->with($urlPath);
151+
$this->categoryMock->expects($this->exactly(4))->method('setUrlPath')->with($urlPath);
152152

153153
$this->assertSame(
154154
$this->subjectMock,

app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ function (
168168
selectBillingAddress(newBillingAddress);
169169
checkoutData.setSelectedBillingAddress(newBillingAddress.getKey());
170170
checkoutData.setNewCustomerBillingAddress(addressData);
171+
this.updateAddresses(true);
171172
}
172173
}
173-
this.updateAddresses(true);
174174
},
175175

176176
/**

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,16 @@ private function validateDefaultAddress(
577577
CustomerInterface $customer,
578578
string $defaultAddressType
579579
): void {
580-
$addressId = $defaultAddressType === CustomerInterface::DEFAULT_BILLING ? $customer->getDefaultBilling()
581-
: $customer->getDefaultShipping();
580+
$defaultAddressId = $defaultAddressType === CustomerInterface::DEFAULT_BILLING ?
581+
(int) $customer->getDefaultBilling() : (int) $customer->getDefaultShipping();
582+
582583
if ($customer->getAddresses()) {
583584
foreach ($customer->getAddresses() as $address) {
584-
if ((int) $addressId === (int) $address->getId()) {
585+
$addressArray = $address->__toArray();
586+
$addressId = (int) $address->getId();
587+
if (!empty($addressArray[$defaultAddressType])
588+
|| empty($addressId)
589+
|| $defaultAddressId === $addressId) {
585590
return;
586591
}
587592
}

app/code/Magento/Sales/Block/Adminhtml/Items/Column/DefaultColumn.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
use Magento\Sales\Model\Order\Invoice\Item as InvoiceItem;
1010
use Magento\Sales\Model\Order\Item;
1111
use Magento\Quote\Model\Quote\Item\AbstractItem as QuoteItem;
12+
use Magento\Store\Model\Store;
13+
use Magento\Store\Model\ScopeInterface;
14+
use Magento\Tax\Model\Config;
1215

1316
/**
1417
* Adminhtml sales order column renderer
1518
*
1619
* @api
17-
* @author Magento Core Team <core@magentocommerce.com>
1820
* @since 100.0.2
1921
*/
2022
class DefaultColumn extends \Magento\Sales\Block\Adminhtml\Items\AbstractItems
2123
{
2224
/**
23-
* Option factory
24-
*
2525
* @var \Magento\Catalog\Model\Product\OptionFactory
2626
*/
2727
protected $_optionFactory;
@@ -122,7 +122,13 @@ public function getSku()
122122
*/
123123
public function getTotalAmount($item)
124124
{
125-
$totalAmount = $item->getRowTotal() - $item->getDiscountAmount();
125+
$storeId = $item->getStoreId();
126+
$total = $this->displaySalesPricesInclTax($storeId) ? $item->getPriceInclTax()
127+
: $item->getPrice();
128+
129+
$totalAmount = $this->displaySalesPricesInclTax($storeId)
130+
? $total - $item->getDiscountAmount() - $item->getTaxAmount()
131+
: $total - $item->getDiscountAmount();
126132

127133
return $totalAmount;
128134
}
@@ -135,8 +141,29 @@ public function getTotalAmount($item)
135141
*/
136142
public function getBaseTotalAmount($item)
137143
{
138-
$baseTotalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
144+
$storeId = $item->getStoreId();
145+
$baseTotal = $this->displaySalesPricesInclTax($storeId) ? $item->getBasePriceInclTax()
146+
: $item->getBasePrice();
147+
148+
$baseTotalAmount = $this->displaySalesPricesInclTax($storeId)
149+
? $baseTotal - $item->getBaseDiscountAmount() - $item->getBaseTaxAmount()
150+
: $baseTotal - $item->getBaseDiscountAmount();
139151

140152
return $baseTotalAmount;
141153
}
154+
155+
/**
156+
* Return the flag to display sales prices including tax
157+
*
158+
* @param string|bool|int|Store $store
159+
* @return bool
160+
*/
161+
private function displaySalesPricesInclTax($store = null): bool
162+
{
163+
return $this->_scopeConfig->getValue(
164+
Config::XML_PATH_DISPLAY_SALES_PRICE,
165+
ScopeInterface::SCOPE_STORE,
166+
$store
167+
) == Config::DISPLAY_TYPE_INCLUDING_TAX;
168+
}
142169
}

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Items/Column/DefaultColumnTest.php

Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Items\Column;
99

10+
use Magento\Framework\App\Config\ScopeConfigInterface;
1011
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1112
use Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn;
1213
use Magento\Sales\Model\Order\Item;
@@ -28,43 +29,114 @@ class DefaultColumnTest extends TestCase
2829
*/
2930
protected $itemMock;
3031

32+
/**
33+
* @var ScopeConfigInterface|MockObject
34+
*/
35+
protected $scopeConfigMock;
36+
3137
protected function setUp(): void
3238
{
3339
$this->objectManagerHelper = new ObjectManagerHelper($this);
40+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
41+
->disableOriginalConstructor()
42+
->getMockForAbstractClass();
3443
$this->defaultColumn = $this->objectManagerHelper->getObject(
35-
DefaultColumn::class
44+
DefaultColumn::class,
45+
[
46+
'scopeConfig' => $this->scopeConfigMock
47+
]
3648
);
3749
$this->itemMock = $this->getMockBuilder(Item::class)
3850
->disableOriginalConstructor()
39-
->onlyMethods(['getRowTotal', 'getDiscountAmount', 'getBaseRowTotal', 'getBaseDiscountAmount'])
4051
->getMock();
4152
}
4253

43-
public function testGetTotalAmount()
54+
/**
55+
* Verify the total amount based on the price including tax flag
56+
*
57+
* @dataProvider getScopeConfigSalesPriceDataProvider
58+
* @param string $taxIncl
59+
* @param float|null $basePriceInclTax
60+
* @param float $basePrice
61+
* @param float $expectedResult
62+
* @return void
63+
* @throws \ReflectionException
64+
*/
65+
public function testGetTotalAmount(string $taxIncl, $priceInclTax, float $price, float $expectedResult): void
4466
{
45-
$rowTotal = 10;
46-
$discountAmount = 2;
47-
$expectedResult = 8;
67+
$storeId = 1;
68+
$discountAmount = 15.21;
69+
$taxAmount = 0.34;
4870
$this->itemMock->expects($this->once())
49-
->method('getRowTotal')
50-
->willReturn($rowTotal);
71+
->method('getStoreId')
72+
->willReturn($storeId);
73+
$this->itemMock->expects($this->any())
74+
->method('getPriceInclTax')
75+
->willReturn($priceInclTax);
76+
$this->itemMock->expects($this->any())
77+
->method('getPrice')
78+
->willReturn($price);
5179
$this->itemMock->expects($this->once())
5280
->method('getDiscountAmount')
5381
->willReturn($discountAmount);
54-
$this->assertEquals($expectedResult, $this->defaultColumn->getTotalAmount($this->itemMock));
82+
$this->itemMock->expects($this->any())
83+
->method('getTaxAmount')
84+
->willReturn($taxAmount);
85+
$this->scopeConfigMock->expects($this->atLeastOnce())
86+
->method('getValue')
87+
->willReturn($taxIncl);
88+
$this->assertEquals($expectedResult, round($this->defaultColumn->getTotalAmount($this->itemMock), 2));
5589
}
5690

57-
public function testGetBaseTotalAmount()
58-
{
59-
$baseRowTotal = 10;
60-
$baseDiscountAmount = 2;
61-
$expectedResult = 8;
91+
/**
92+
* Verify the total base amount based on the price including tax flag
93+
*
94+
* @dataProvider getScopeConfigSalesPriceDataProvider
95+
* @param string $taxIncl
96+
* @param float|null $basePriceInclTax
97+
* @param float $basePrice
98+
* @param float $expectedResult
99+
* @return void
100+
* @throws \ReflectionException
101+
*/
102+
public function testGetBaseTotalAmount(
103+
string $taxIncl,
104+
$basePriceInclTax,
105+
float $basePrice,
106+
float $expectedResult
107+
): void {
108+
$storeId = 1;
109+
$baseDiscountAmount = 15.21;
110+
$baseTaxAmount = 0.34;
62111
$this->itemMock->expects($this->once())
63-
->method('getBaseRowTotal')
64-
->willReturn($baseRowTotal);
112+
->method('getStoreId')
113+
->willReturn($storeId);
114+
$this->itemMock->expects($this->any())
115+
->method('getBasePriceInclTax')
116+
->willReturn($basePriceInclTax);
117+
$this->itemMock->expects($this->any())
118+
->method('getBasePrice')
119+
->willReturn($basePrice);
65120
$this->itemMock->expects($this->once())
66121
->method('getBaseDiscountAmount')
67122
->willReturn($baseDiscountAmount);
68-
$this->assertEquals($expectedResult, $this->defaultColumn->getBaseTotalAmount($this->itemMock));
123+
$this->itemMock->expects($this->any())
124+
->method('getBaseTaxAmount')
125+
->willReturn($baseTaxAmount);
126+
$this->scopeConfigMock->expects($this->atLeastOnce())
127+
->method('getValue')
128+
->willReturn($taxIncl);
129+
$this->assertEquals($expectedResult, round($this->defaultColumn->getBaseTotalAmount($this->itemMock), 2));
130+
}
131+
132+
/**
133+
* @return array
134+
*/
135+
public function getScopeConfigSalesPriceDataProvider(): array
136+
{
137+
return [
138+
['2', 16.9, 13.52, 1.35],
139+
['1', null, 16.9, 1.69],
140+
];
69141
}
70142
}

0 commit comments

Comments
 (0)