Skip to content

Commit bc8e51d

Browse files
author
Stanislav Idolov
authored
Merge pull request #6226 from magento-tsg-csl3/2.4-develop-pr43
[TSG-CSL3] For 2.4 (pr43)
2 parents 4527d76 + 359fca1 commit bc8e51d

File tree

12 files changed

+414
-20
lines changed

12 files changed

+414
-20
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/TableResolver.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public function afterGetTableName(
5555
string $result,
5656
$modelEntity
5757
) {
58-
if (!is_array($modelEntity) && $modelEntity === AbstractAction::MAIN_INDEX_TABLE) {
58+
if (!is_array($modelEntity) &&
59+
$modelEntity === AbstractAction::MAIN_INDEX_TABLE &&
60+
$this->storeManager->getStore()->getId()
61+
) {
5962
$catalogCategoryProductDimension = new Dimension(
6063
\Magento\Store\Model\Store::ENTITY,
6164
$this->storeManager->getStore()->getId()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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\Catalog\Test\Unit\Model\Indexer\Category\Product\Plugin;
9+
10+
use Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
13+
use Magento\Store\Model\Store;
14+
use Magento\Store\Model\StoreManagerInterface;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class TableResolverTest extends TestCase
18+
{
19+
/**
20+
* Tests replacing catalog_category_product_index table name
21+
*
22+
* @param int $storeId
23+
* @param string $tableName
24+
* @param string $expected
25+
* @dataProvider afterGetTableNameDataProvider
26+
*/
27+
public function testAfterGetTableName(int $storeId, string $tableName, string $expected): void
28+
{
29+
$storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
30+
31+
$storeMock = $this->getMockBuilder(Store::class)
32+
->onlyMethods(['getId'])
33+
->disableOriginalConstructor()
34+
->getMock();
35+
$storeMock->method('getId')
36+
->willReturn($storeId);
37+
38+
$storeManagerMock->method('getStore')->willReturn($storeMock);
39+
40+
$tableResolverMock = $this->getMockBuilder(IndexScopeResolver::class)
41+
->disableOriginalConstructor()
42+
->getMock();
43+
$tableResolverMock->method('resolve')->willReturn('catalog_category_product_index_store1');
44+
45+
$subjectMock = $this->getMockBuilder(ResourceConnection::class)
46+
->disableOriginalConstructor()
47+
->getMock();
48+
49+
$model = new TableResolver($storeManagerMock, $tableResolverMock);
50+
51+
$this->assertEquals(
52+
$expected,
53+
$model->afterGetTableName($subjectMock, $tableName, 'catalog_category_product_index')
54+
);
55+
}
56+
57+
/**
58+
* Data provider for testAfterGetTableName
59+
*
60+
* @return array
61+
*/
62+
public function afterGetTableNameDataProvider(): array
63+
{
64+
return [
65+
[
66+
'storeId' => 1,
67+
'tableName' => 'catalog_category_product_index',
68+
'expected' => 'catalog_category_product_index_store1'
69+
],
70+
[
71+
'storeId' => 0,
72+
'tableName' => 'catalog_category_product_index',
73+
'expected' => 'catalog_category_product_index'
74+
],
75+
];
76+
}
77+
}

app/code/Magento/Checkout/Test/Mftf/Test/CheckoutDifferentDefaultCountryPerStoreTest.xml

+14-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
</after>
4040
<!-- Open product and add product to cart-->
4141
<actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="openProductPage">
42-
<argument name="productUrlKey" value="$$createProduct.custom_attributes[url_key]$$"/>
42+
<argument name="productUrlKey" value="$createProduct.custom_attributes[url_key]$"/>
4343
</actionGroup>
4444
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
45-
<argument name="product" value="$$createProduct$$"/>
45+
<argument name="product" value="$createProduct$"/>
4646
<argument name="productCount" value="1"/>
4747
</actionGroup>
4848
<!-- Go to cart -->
@@ -59,5 +59,17 @@
5959
<actualResult type="const">$grabCountry</actualResult>
6060
<expectedResult type="string">{{DE_Address_Berlin_Not_Default_Address.country_id}}</expectedResult>
6161
</assertEquals>
62+
<!-- Go to cart -->
63+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="returnToCartPage"/>
64+
<!-- Switch to default store view -->
65+
<actionGroup ref="StorefrontSwitchDefaultStoreViewActionGroup" stepKey="switchToDefaultStoreView"/>
66+
<!-- Go to checkout page -->
67+
<actionGroup ref="OpenStoreFrontCheckoutShippingPageActionGroup" stepKey="proceedToCheckoutWithDefaultStore"/>
68+
<!-- Grab country code from checkout page and assert value with default country for default store view -->
69+
<grabValueFrom selector="{{CheckoutShippingSection.country}}" stepKey="grabDefaultStoreCountry"/>
70+
<assertEquals stepKey="assertDefaultCountryValue">
71+
<actualResult type="const">$grabDefaultStoreCountry</actualResult>
72+
<expectedResult type="string">{{US_Address_TX.country_id}}</expectedResult>
73+
</assertEquals>
6274
</test>
6375
</tests>

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ define([
121121
);
122122
}
123123
checkoutProvider.on('shippingAddress', function (shippingAddrsData) {
124-
checkoutData.setShippingAddressFromData(shippingAddrsData);
124+
if (shippingAddrsData.street && !_.isEmpty(shippingAddrsData.street[0])) {
125+
checkoutData.setShippingAddressFromData(shippingAddrsData);
126+
}
125127
});
126128
shippingRatesValidator.initFields(fieldsetName);
127129
});

app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\ConfigurableProduct\Model\Quote\Item;
77

8+
use Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface;
9+
use Magento\Quote\Api\Data\ProductOptionExtensionInterface;
810
use Magento\Quote\Model\Quote\Item\CartItemProcessorInterface;
911
use Magento\Quote\Api\Data\CartItemInterface;
1012
use Magento\Framework\Serialize\Serializer\Json;
@@ -64,7 +66,7 @@ public function __construct(
6466
public function convertToBuyRequest(CartItemInterface $cartItem)
6567
{
6668
if ($cartItem->getProductOption() && $cartItem->getProductOption()->getExtensionAttributes()) {
67-
/** @var \Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface $options */
69+
/** @var ConfigurableItemOptionValueInterface $options */
6870
$options = $cartItem->getProductOption()->getExtensionAttributes()->getConfigurableItemOptions();
6971
if (is_array($options)) {
7072
$requestData = [];
@@ -82,13 +84,17 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
8284
*/
8385
public function processOptions(CartItemInterface $cartItem)
8486
{
85-
$attributesOption = $cartItem->getProduct()->getCustomOption('attributes');
87+
$attributesOption = $cartItem->getProduct()
88+
->getCustomOption('attributes');
89+
if (!$attributesOption) {
90+
return $cartItem;
91+
}
8692
$selectedConfigurableOptions = $this->serializer->unserialize($attributesOption->getValue());
8793

8894
if (is_array($selectedConfigurableOptions)) {
8995
$configurableOptions = [];
9096
foreach ($selectedConfigurableOptions as $optionId => $optionValue) {
91-
/** @var \Magento\ConfigurableProduct\Api\Data\ConfigurableItemOptionValueInterface $option */
97+
/** @var ConfigurableItemOptionValueInterface $option */
9298
$option = $this->itemOptionValueFactory->create();
9399
$option->setOptionId($optionId);
94100
$option->setOptionValue($optionValue);
@@ -99,15 +105,16 @@ public function processOptions(CartItemInterface $cartItem)
99105
? $cartItem->getProductOption()
100106
: $this->productOptionFactory->create();
101107

102-
/** @var \Magento\Quote\Api\Data\ProductOptionExtensionInterface $extensibleAttribute */
103-
$extensibleAttribute = $productOption->getExtensionAttributes()
108+
/** @var ProductOptionExtensionInterface $extensibleAttribute */
109+
$extensibleAttribute = $productOption->getExtensionAttributes()
104110
? $productOption->getExtensionAttributes()
105111
: $this->extensionFactory->create();
106112

107113
$extensibleAttribute->setConfigurableItemOptions($configurableOptions);
108114
$productOption->setExtensionAttributes($extensibleAttribute);
109115
$cartItem->setProductOption($productOption);
110116
}
117+
111118
return $cartItem;
112119
}
113120
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CartItemProcessorTest extends TestCase
5959
*/
6060
private $productOptionExtensionAttributes;
6161

62-
/** @var \PHPUnit\Framework\MockObject\MockObject */
62+
/** @var MockObject */
6363
private $serializer;
6464

6565
protected function setUp(): void
@@ -263,4 +263,25 @@ public function testProcessProductOptionsIfOptionsExist()
263263

264264
$this->assertEquals($cartItemMock, $this->model->processOptions($cartItemMock));
265265
}
266+
267+
/**
268+
* Checks processOptions method with the empty custom option
269+
*
270+
* @return void
271+
*/
272+
public function testProcessProductWithEmptyOption(): void
273+
{
274+
$customOption = $this->createMock(Option::class);
275+
$productMock = $this->createMock(Product::class);
276+
$productMock->method('getCustomOption')
277+
->with('attributes')
278+
->willReturn(null);
279+
$customOption->expects($this->never())
280+
->method('getValue');
281+
$cartItemMock = $this->createPartialMock(Item::class, ['getProduct']);
282+
$cartItemMock->expects($this->once())
283+
->method('getProduct')
284+
->willReturn($productMock);
285+
$this->assertEquals($cartItemMock, $this->model->processOptions($cartItemMock));
286+
}
266287
}

app/code/Magento/Customer/Block/Widget/Dob.php

+50-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

88
use Magento\Customer\Api\CustomerMetadataInterface;
99
use Magento\Framework\Api\ArrayObjectSearch;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Json\EncoderInterface;
12+
use Magento\Framework\Locale\Bundle\DataBundle;
13+
use Magento\Framework\Locale\ResolverInterface;
1014

1115
/**
1216
* Customer date of birth attribute block
1317
*
1418
* @SuppressWarnings(PHPMD.DepthOfInheritance)
19+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1520
*/
1621
class Dob extends AbstractWidget
1722
{
@@ -39,24 +44,42 @@ class Dob extends AbstractWidget
3944
*/
4045
protected $filterFactory;
4146

47+
/**
48+
* JSON Encoder
49+
*
50+
* @var EncoderInterface
51+
*/
52+
private $encoder;
53+
54+
/**
55+
* @var ResolverInterface
56+
*/
57+
private $localeResolver;
58+
4259
/**
4360
* @param \Magento\Framework\View\Element\Template\Context $context
4461
* @param \Magento\Customer\Helper\Address $addressHelper
4562
* @param CustomerMetadataInterface $customerMetadata
4663
* @param \Magento\Framework\View\Element\Html\Date $dateElement
4764
* @param \Magento\Framework\Data\Form\FilterFactory $filterFactory
4865
* @param array $data
66+
* @param EncoderInterface|null $encoder
67+
* @param ResolverInterface|null $localeResolver
4968
*/
5069
public function __construct(
5170
\Magento\Framework\View\Element\Template\Context $context,
5271
\Magento\Customer\Helper\Address $addressHelper,
5372
CustomerMetadataInterface $customerMetadata,
5473
\Magento\Framework\View\Element\Html\Date $dateElement,
5574
\Magento\Framework\Data\Form\FilterFactory $filterFactory,
56-
array $data = []
75+
array $data = [],
76+
?EncoderInterface $encoder = null,
77+
?ResolverInterface $localeResolver = null
5778
) {
5879
$this->dateElement = $dateElement;
5980
$this->filterFactory = $filterFactory;
81+
$this->encoder = $encoder ?? ObjectManager::getInstance()->get(EncoderInterface::class);
82+
$this->localeResolver = $localeResolver ?? ObjectManager::getInstance()->get(ResolverInterface::class);
6083
parent::__construct($context, $addressHelper, $customerMetadata, $data);
6184
}
6285

@@ -378,6 +401,32 @@ public function getFirstDay()
378401
);
379402
}
380403

404+
/**
405+
* Get translated calendar config json formatted
406+
*
407+
* @return string
408+
*/
409+
public function getTranslatedCalendarConfigJson(): string
410+
{
411+
$localeData = (new DataBundle())->get($this->localeResolver->getLocale());
412+
$monthsData = $localeData['calendar']['gregorian']['monthNames'];
413+
$daysData = $localeData['calendar']['gregorian']['dayNames'];
414+
415+
return $this->encoder->encode(
416+
[
417+
'closeText' => __('Done'),
418+
'prevText' => __('Prev'),
419+
'nextText' => __('Next'),
420+
'currentText' => __('Today'),
421+
'monthNames' => array_values(iterator_to_array($monthsData['format']['wide'])),
422+
'monthNamesShort' => array_values(iterator_to_array($monthsData['format']['abbreviated'])),
423+
'dayNames' => array_values(iterator_to_array($daysData['format']['wide'])),
424+
'dayNamesShort' => array_values(iterator_to_array($daysData['format']['abbreviated'])),
425+
'dayNamesMin' => array_values(iterator_to_array($daysData['format']['short'])),
426+
]
427+
);
428+
}
429+
381430
/**
382431
* Set 2 places for day value in format string
383432
*

0 commit comments

Comments
 (0)