Skip to content

Commit 55ca27d

Browse files
authored
Merge pull request #8258 from magento-gl/comm_voted_v2
[Bluetooth] Community Pull Requests delivery - 2.4.7-beta 1 release
2 parents ab61383 + 0414bb2 commit 55ca27d

File tree

15 files changed

+472
-112
lines changed

15 files changed

+472
-112
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Listing/Collector/Price.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
use Magento\Catalog\Api\Data\ProductRender\PriceInfoInterfaceFactory;
1212
use Magento\Catalog\Api\Data\ProductRenderInterface;
1313
use Magento\Catalog\Model\ProductRender\FormattedPriceInfoBuilder;
14-
use Magento\Catalog\Pricing\Price\FinalPrice;
15-
use Magento\Catalog\Pricing\Price\RegularPrice;
1614
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorInterface;
1715
use Magento\Framework\Pricing\PriceCurrencyInterface;
18-
use Magento\GroupedProduct\Model\Product\Type\Grouped;
1916

2017
/**
2118
* Collect information about base prices of products
@@ -25,6 +22,18 @@
2522
*/
2623
class Price implements ProductRenderCollectorInterface
2724
{
25+
/** FInal Price key */
26+
public const KEY_FINAL_PRICE = "final_price";
27+
28+
/** Minimal Price key */
29+
public const KEY_MINIMAL_PRICE = "minimal_price";
30+
31+
/** Regular Price key */
32+
public const KEY_REGULAR_PRICE = "regular_price";
33+
34+
/** Max Price key */
35+
public const KEY_MAX_PRICE = "max_price";
36+
2837
/**
2938
* @var PriceCurrencyInterface
3039
*/
@@ -75,49 +84,40 @@ public function collect(ProductInterface $product, ProductRenderInterface $produ
7584
$priceInfo = $this->priceInfoFactory->create();
7685
}
7786

78-
if ($product->getTypeId() === Grouped::TYPE_CODE) {
79-
$product = $product
87+
$priceInfo->setFinalPrice(
88+
$product
8089
->getPriceInfo()
81-
->getPrice(FinalPrice::PRICE_CODE)
82-
->getMinProduct();
83-
}
90+
->getPrice('final_price')
91+
->getAmount()
92+
->getValue()
93+
);
94+
$priceInfo->setMinimalPrice(
95+
$product
96+
->getPriceInfo()
97+
->getPrice('final_price')
98+
->getMinimalPrice()
99+
->getValue()
100+
);
101+
$priceInfo->setRegularPrice(
102+
$product
103+
->getPriceInfo()
104+
->getPrice('regular_price')
105+
->getAmount()
106+
->getValue()
107+
);
108+
$priceInfo->setMaxPrice(
109+
$product
110+
->getPriceInfo()
111+
->getPrice('final_price')
112+
->getMaximalPrice()
113+
->getValue()
114+
);
84115

85-
if ($product !== null) {
86-
$priceInfo->setFinalPrice(
87-
$product
88-
->getPriceInfo()
89-
->getPrice(FinalPrice::PRICE_CODE)
90-
->getAmount()
91-
->getValue()
92-
);
93-
$priceInfo->setMinimalPrice(
94-
$product
95-
->getPriceInfo()
96-
->getPrice(FinalPrice::PRICE_CODE)
97-
->getMinimalPrice()
98-
->getValue()
99-
);
100-
$priceInfo->setRegularPrice(
101-
$product
102-
->getPriceInfo()
103-
->getPrice(RegularPrice::PRICE_CODE)
104-
->getAmount()
105-
->getValue()
106-
);
107-
$priceInfo->setMaxPrice(
108-
$product
109-
->getPriceInfo()
110-
->getPrice(FinalPrice::PRICE_CODE)
111-
->getMaximalPrice()
112-
->getValue()
113-
);
114-
115-
$this->formattedPriceInfoBuilder->build(
116-
$priceInfo,
117-
$productRender->getStoreId(),
118-
$productRender->getCurrencyCode()
119-
);
120-
}
116+
$this->formattedPriceInfoBuilder->build(
117+
$priceInfo,
118+
$productRender->getStoreId(),
119+
$productRender->getCurrencyCode()
120+
);
121121

122122
$productRender->setPriceInfo($priceInfo);
123123
}

app/code/Magento/Catalog/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
"magento/module-ui": "*",
3232
"magento/module-url-rewrite": "*",
3333
"magento/module-widget": "*",
34-
"magento/module-wishlist": "*",
35-
"magento/module-grouped-product": "*"
34+
"magento/module-wishlist": "*"
3635
},
3736
"suggest": {
3837
"magento/module-cookie": "*",

app/code/Magento/Catalog/view/frontend/templates/product/view/opengraph/general.phtml

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,21 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
use Magento\Catalog\Block\Product\View;
8-
use Magento\Catalog\Model\Product;
9-
use Magento\Catalog\Pricing\Price\FinalPrice;
10-
use Magento\Framework\Escaper;
11-
use Magento\GroupedProduct\Model\Product\Type\Grouped;
12-
13-
/**
14-
* @var View $block
15-
* @var Escaper $escaper
16-
*/
7+
/** @var $block \Magento\Catalog\Block\Product\View */
178
?>
189

1910
<meta property="og:type" content="product" />
2011
<meta property="og:title"
21-
content="<?= $escaper->escapeHtmlAttr($block->stripTags($block->getProduct()->getName())) ?>" />
12+
content="<?= $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getName())) ?>" />
2213
<meta property="og:image"
23-
content="<?= $escaper->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()) ?>"
24-
/>
14+
content="<?= $block->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()) ?>" />
2515
<meta property="og:description"
26-
content="<?= $escaper->escapeHtmlAttr($block->stripTags($block->getProduct()->getShortDescription())) ?>" />
16+
content="<?= $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getShortDescription())) ?>" />
2717
<meta property="og:url" content="<?= $block->escapeUrl($block->getProduct()->getProductUrl()) ?>" />
28-
<?php
29-
if ($block->getProduct()->getTypeId() === Grouped::TYPE_CODE):
30-
/** @var Product $minProduct */
31-
$minProduct = $block->getProduct()
32-
->getPriceInfo()
33-
->getPrice(FinalPrice::PRICE_CODE)
34-
->getMinProduct();
35-
36-
$priceAmount = ($minProduct !== null) ? $minProduct->getPriceInfo()
37-
->getPrice(FinalPrice::PRICE_CODE)
38-
->getAmount() : $minProduct;
39-
else:
40-
$priceAmount = $block->getProduct()
41-
->getPriceInfo()
42-
->getPrice(FinalPrice::PRICE_CODE)
43-
->getAmount();
44-
endif;
45-
?>
46-
47-
<?php if ($priceAmount !== null): ?>
48-
<meta property="product:price:amount" content="<?= $block->escapeHtmlAttr($priceAmount) ?>"/>
49-
<?= $block->getChildHtml('meta.currency') ?>
18+
<?php if ($priceAmount = $block->getProduct()
19+
->getPriceInfo()
20+
->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
21+
->getAmount()):?>
22+
<meta property="product:price:amount" content="<?= $block->escapeHtmlAttr($priceAmount) ?>"/>
23+
<?= $block->getChildHtml('meta.currency') ?>
5024
<?php endif;?>

app/code/Magento/CatalogGraphQl/Model/Category/DepthCalculator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use GraphQL\Language\AST\FieldNode;
1212
use GraphQL\Language\AST\InlineFragmentNode;
1313
use GraphQL\Language\AST\NodeKind;
14+
use GraphQL\Language\AST\SelectionNode;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1516

1617
/**
@@ -66,21 +67,21 @@ private function calculateRecursive(ResolveInfo $resolveInfo, Node $node) : int
6667
* Add inline fragment fields into calculating of category depth
6768
*
6869
* @param ResolveInfo $resolveInfo
69-
* @param InlineFragmentNode $inlineFragmentField
70+
* @param SelectionNode $inlineFragmentField
7071
* @param array $depth
7172
* @return int
7273
*/
7374
private function addInlineFragmentDepth(
7475
ResolveInfo $resolveInfo,
75-
InlineFragmentNode $inlineFragmentField,
76+
SelectionNode $inlineFragmentField,
7677
$depth = []
7778
): int {
7879
$selections = $inlineFragmentField->selectionSet->selections;
7980
/** @var FieldNode $field */
8081
foreach ($selections as $field) {
8182
if ($field->kind === NodeKind::INLINE_FRAGMENT) {
8283
$depth[] = $this->addInlineFragmentDepth($resolveInfo, $field, $depth);
83-
} elseif ($field->selectionSet && $field->selectionSet->selections) {
84+
} elseif (!empty($field->selectionSet) && $field->selectionSet->selections) {
8485
$depth[] = $this->calculate($resolveInfo, $field);
8586
}
8687
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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\CatalogGraphQl\Test\Unit\Model\Resolver\Category;
9+
10+
use GraphQL\Language\AST\FieldNode;
11+
use GraphQL\Language\AST\InlineFragmentNode;
12+
use GraphQL\Language\AST\NodeKind;
13+
use GraphQL\Language\AST\NodeList;
14+
use GraphQL\Language\AST\SelectionSetNode;
15+
use Magento\CatalogGraphQl\Model\Category\DepthCalculator;
16+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
19+
20+
class DepthCalculatorTest extends TestCase
21+
{
22+
/**
23+
* @var DepthCalculator
24+
*/
25+
private DepthCalculator $depthCalculator;
26+
27+
/**
28+
* @var ResolveInfo|MockObject
29+
*/
30+
private $resolveInfoMock;
31+
32+
/**
33+
* @var FieldNode|MockObject
34+
*/
35+
private $fieldNodeMock;
36+
37+
/**
38+
* Await for depth of '1' if selectionSet is null
39+
* @return void
40+
*/
41+
public function testCalculateWithNullAsSelectionSet(): void
42+
{
43+
$this->fieldNodeMock->kind = NodeKind::FIELD;
44+
/** @var SelectionSetNode $selectionSetNode */
45+
$selectionSetNode = new SelectionSetNode([]);
46+
$selectionSetNode->selections = $this->getSelectionsArrayForNullCase();
47+
$this->fieldNodeMock->selectionSet = $selectionSetNode;
48+
$result = $this->depthCalculator->calculate($this->resolveInfoMock, $this->fieldNodeMock);
49+
$this->assertSame(1, $result);
50+
}
51+
52+
/**
53+
* Await for depth of '2' if selectionSet is not null
54+
* @return void
55+
*/
56+
public function testCalculateNonNullAsSelectionSet(): void
57+
{
58+
$this->fieldNodeMock->kind = NodeKind::FIELD;
59+
$selectionSetNode = $this->getSelectionSetNode();
60+
$selectionSetNode->selections = $this->getSelectionsArrayForNonNullCase();
61+
$this->fieldNodeMock->selectionSet = $selectionSetNode;
62+
$result = $this->depthCalculator->calculate($this->resolveInfoMock, $this->fieldNodeMock);
63+
$this->assertEquals(2, $result);
64+
}
65+
66+
/**
67+
* @return NodeList
68+
*/
69+
private function getSelectionsArrayForNullCase()
70+
{
71+
$selectionSetNode = $this->getSelectionSetNode();
72+
$selectionSetNode->selections = $this->getNodeList();
73+
$inlineFragmentNode = $this->getNewInlineFragmentNode();
74+
$inlineFragmentNode->selectionSet = $selectionSetNode;
75+
return new NodeList([
76+
$this->getNewFieldNode(),
77+
$inlineFragmentNode
78+
]);
79+
}
80+
81+
/**
82+
* @return FieldNode
83+
*/
84+
private function getNewFieldNode()
85+
{
86+
return new FieldNode([]);
87+
}
88+
89+
/**
90+
* @return InlineFragmentNode
91+
*/
92+
private function getNewInlineFragmentNode()
93+
{
94+
return new InlineFragmentNode([]);
95+
}
96+
97+
/**
98+
* @return NodeList
99+
*/
100+
private function getSelectionsArrayForNonNullCase()
101+
{
102+
$newFieldNode = $this->getNewFieldNode();
103+
$newFieldNode->selectionSet = $this->getSelectionSetNode();
104+
$newFieldNode->selectionSet->selections = $this->getNodeList();
105+
$newFieldNode->selectionSet->selections[] = $this->getNewFieldNode();
106+
$selectionSetNode = $this->getSelectionSetNode();
107+
$selectionSetNode->selections = new NodeList([$newFieldNode]);
108+
$inlineFragmentNode = $this->getNewInlineFragmentNode();
109+
$inlineFragmentNode->selectionSet = $selectionSetNode;
110+
return new NodeList([
111+
$newFieldNode,
112+
$inlineFragmentNode
113+
]);
114+
}
115+
116+
/**
117+
* @inheritDoc
118+
*/
119+
protected function setUp(): void
120+
{
121+
$this->depthCalculator = new DepthCalculator();
122+
$this->resolveInfoMock = $this->createMock(ResolveInfo::class);
123+
$this->fieldNodeMock = $this->getMockBuilder(FieldNode::class)
124+
->disableOriginalConstructor()
125+
->getMock();
126+
}
127+
128+
/**
129+
* @return \GraphQL\Language\AST\SelectionSetNode
130+
*/
131+
protected function getSelectionSetNode($nodes = []): SelectionSetNode
132+
{
133+
return new SelectionSetNode($nodes);
134+
}
135+
136+
/**
137+
* @return \GraphQL\Language\AST\NodeList
138+
*/
139+
protected function getNodeList(): NodeList
140+
{
141+
return new NodeList([]);
142+
}
143+
}

app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteMovingObserver.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,19 @@ public function execute(\Magento\Framework\Event\Observer $observer)
103103
ScopeInterface::SCOPE_STORE,
104104
$category->getStoreId()
105105
);
106+
$catRewritesEnabled = $this->isCategoryRewritesEnabled();
107+
106108
$category->setData('save_rewrites_history', $saveRewritesHistory);
107109
$categoryUrlRewriteResult = $this->categoryUrlRewriteGenerator->generate($category, true);
110+
111+
if ($catRewritesEnabled) {
112+
$productUrlRewriteResult = $this->urlRewriteHandler->generateProductUrlRewrites($category);
113+
}
114+
108115
$this->urlRewriteHandler->deleteCategoryRewritesForChildren($category);
109116
$this->urlRewriteBunchReplacer->doBunchReplace($categoryUrlRewriteResult);
110117

111-
if ($this->isCategoryRewritesEnabled()) {
112-
$productUrlRewriteResult = $this->urlRewriteHandler->generateProductUrlRewrites($category);
118+
if ($catRewritesEnabled) {
113119
$this->urlRewriteBunchReplacer->doBunchReplace($productUrlRewriteResult);
114120
}
115121

0 commit comments

Comments
 (0)