Skip to content

Commit 7ad8863

Browse files
authored
Merge pull request #4908 from magento-honey-badgers/MC-21691
[honey] MC-21691: [Integration Tests] Failing - Magento.Braintree.Model.MultishippingTest.testCreateOrdersWithBraintreePaypal
2 parents c7f071f + d2362cf commit 7ad8863

File tree

18 files changed

+451
-14
lines changed

18 files changed

+451
-14
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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\CatalogCmsGraphQl\Model\Resolver\Category;
9+
10+
use Magento\Catalog\Model\Category;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\Framework\GraphQl\Config\Element\Field;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\CmsGraphQl\Model\Resolver\DataProvider\Block as BlockProvider;
17+
18+
/**
19+
* Resolver category cms content
20+
*/
21+
class Block implements ResolverInterface
22+
{
23+
/**
24+
* @var BlockProvider
25+
*/
26+
private $blockProvider;
27+
28+
/**
29+
* @param BlockProvider $blockProvider
30+
*/
31+
public function __construct(BlockProvider $blockProvider)
32+
{
33+
$this->blockProvider = $blockProvider;
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function resolve(
40+
Field $field,
41+
$context,
42+
ResolveInfo $info,
43+
array $value = null,
44+
array $args = null
45+
) {
46+
if (!isset($value['model'])) {
47+
throw new LocalizedException(__('"model" value should be specified'));
48+
}
49+
/** @var Category $category */
50+
$category = $value['model'];
51+
$blockId = $category->getLandingPage();
52+
53+
if (empty($blockId)) {
54+
return null;
55+
}
56+
57+
try {
58+
$block = $this->blockProvider->getData($blockId);
59+
} catch (NoSuchEntityException $e) {
60+
return null;
61+
}
62+
63+
return $block;
64+
}
65+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CatalogCmsGraphQl
2+
3+
**CatalogCmsGraphQl** provides type and resolver information for GraphQL attributes that have dependencies on the Catalog and Cms modules.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "magento/module-catalog-cms-graph-ql",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.1.3||~7.2.0||~7.3.0",
7+
"magento/framework": "*",
8+
"magento/module-catalog": "*",
9+
"magento/module-cms-graph-ql": "*"
10+
},
11+
"suggest": {
12+
"magento/module-graph-ql": "*",
13+
"magento/module-cms": "*",
14+
"magento/module-catalog-graph-ql": "*"
15+
},
16+
"license": [
17+
"OSL-3.0",
18+
"AFL-3.0"
19+
],
20+
"autoload": {
21+
"files": [
22+
"registration.php"
23+
],
24+
"psr-4": {
25+
"Magento\\CatalogCmsGraphQl\\": ""
26+
}
27+
}
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\CatalogGraphQl\Model\AttributesJoiner">
10+
<arguments>
11+
<argument name="fieldToAttributeMap" xsi:type="array">
12+
<item name="cms_block" xsi:type="array">
13+
<item name="landing_page" xsi:type="string">landing_page</item>
14+
</item>
15+
</argument>
16+
</arguments>
17+
</type>
18+
</config>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_CatalogCmsGraphQl" >
10+
<sequence>
11+
<module name="Magento_CmsGraphQl"/>
12+
<module name="Magento_CatalogGraphQl"/>
13+
</sequence>
14+
</module>
15+
</config>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
interface CategoryInterface {
5+
cms_block: CmsBlock @doc(description: "Category CMS Block.") @resolver(class: "Magento\\CatalogCmsGraphQl\\Model\\Resolver\\Category\\Block")
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_CatalogCmsGraphQl', __DIR__);

app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ class AttributesJoiner
2020
*/
2121
private $queryFields = [];
2222

23+
/**
24+
* Field to attribute mapping
25+
*
26+
* For fields that are not named the same as their attribute, or require extra attributes to resolve
27+
* e.g. ['field' => ['attr1', 'attr2'], 'other_field' => ['other_attr']]
28+
*
29+
* @var array
30+
*/
31+
private $fieldToAttributeMap = [];
32+
33+
/**
34+
* @param array $fieldToAttributeMap
35+
*/
36+
public function __construct(array $fieldToAttributeMap = [])
37+
{
38+
$this->fieldToAttributeMap = $fieldToAttributeMap;
39+
}
40+
2341
/**
2442
* Join fields attached to field node to collection's select.
2543
*
@@ -30,9 +48,7 @@ class AttributesJoiner
3048
public function join(FieldNode $fieldNode, AbstractCollection $collection) : void
3149
{
3250
foreach ($this->getQueryFields($fieldNode) as $field) {
33-
if (!$collection->isAttributeAdded($field)) {
34-
$collection->addAttributeToSelect($field);
35-
}
51+
$this->addFieldToCollection($collection, $field);
3652
}
3753
}
3854

@@ -42,7 +58,7 @@ public function join(FieldNode $fieldNode, AbstractCollection $collection) : voi
4258
* @param FieldNode $fieldNode
4359
* @return string[]
4460
*/
45-
public function getQueryFields(FieldNode $fieldNode)
61+
public function getQueryFields(FieldNode $fieldNode): array
4662
{
4763
if (!isset($this->queryFields[$fieldNode->name->value])) {
4864
$this->queryFields[$fieldNode->name->value] = [];
@@ -58,4 +74,29 @@ public function getQueryFields(FieldNode $fieldNode)
5874

5975
return $this->queryFields[$fieldNode->name->value];
6076
}
77+
78+
/**
79+
* Add field to collection select
80+
*
81+
* Add a query field to the collection, using mapped attribute names if they are set
82+
*
83+
* @param AbstractCollection $collection
84+
* @param string $field
85+
*/
86+
private function addFieldToCollection(AbstractCollection $collection, string $field)
87+
{
88+
$attribute = isset($this->fieldToAttributeMap[$field]) ? $this->fieldToAttributeMap[$field] : $field;
89+
90+
if (is_array($attribute)) {
91+
foreach ($attribute as $attributeName) {
92+
if (!$collection->isAttributeAdded($attributeName)) {
93+
$collection->addAttributeToSelect($attributeName);
94+
}
95+
}
96+
} else {
97+
if (!$collection->isAttributeAdded($attribute)) {
98+
$collection->addAttributeToSelect($attribute);
99+
}
100+
}
101+
}
61102
}

app/code/Magento/CatalogGraphQl/Model/Config/CategoryAttributeReader.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,24 @@ class CategoryAttributeReader implements ReaderInterface
5151
*/
5252
private $collectionFactory;
5353

54+
/**
55+
* @var array
56+
*/
57+
private $categoryAttributeResolvers;
58+
5459
/**
5560
* @param Type $typeLocator
5661
* @param CollectionFactory $collectionFactory
62+
* @param array $categoryAttributeResolvers
5763
*/
5864
public function __construct(
5965
Type $typeLocator,
60-
CollectionFactory $collectionFactory
66+
CollectionFactory $collectionFactory,
67+
array $categoryAttributeResolvers = []
6168
) {
6269
$this->typeLocator = $typeLocator;
6370
$this->collectionFactory = $collectionFactory;
71+
$this->categoryAttributeResolvers = $categoryAttributeResolvers;
6472
}
6573

6674
/**
@@ -93,6 +101,9 @@ public function read($scope = null) : array
93101
$data['fields'][$attributeCode]['name'] = $attributeCode;
94102
$data['fields'][$attributeCode]['type'] = $locatedType;
95103
$data['fields'][$attributeCode]['arguments'] = [];
104+
if (isset($this->categoryAttributeResolvers[$attributeCode])) {
105+
$data['fields'][$attributeCode]['resolver'] = $this->categoryAttributeResolvers[$attributeCode];
106+
}
96107
}
97108

98109
$config['CategoryInterface'] = $data;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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\Model\Resolver\Category;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Query\ResolverInterface;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Store\Api\Data\StoreInterface;
15+
use Magento\Framework\Filesystem\DirectoryList;
16+
17+
/**
18+
* Resolve category image to a fully qualified URL
19+
*/
20+
class Image implements ResolverInterface
21+
{
22+
/** @var DirectoryList */
23+
private $directoryList;
24+
25+
/**
26+
* @param DirectoryList $directoryList
27+
*/
28+
public function __construct(DirectoryList $directoryList)
29+
{
30+
$this->directoryList = $directoryList;
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function resolve(
37+
Field $field,
38+
$context,
39+
ResolveInfo $info,
40+
array $value = null,
41+
array $args = null
42+
) {
43+
if (!isset($value['model'])) {
44+
throw new LocalizedException(__('"model" value should be specified'));
45+
}
46+
/** @var \Magento\Catalog\Model\Category $category */
47+
$category = $value['model'];
48+
$imagePath = $category->getImage();
49+
if (empty($imagePath)) {
50+
return null;
51+
}
52+
/** @var StoreInterface $store */
53+
$store = $context->getExtensionAttributes()->getStore();
54+
$baseUrl = $store->getBaseUrl('media');
55+
56+
$mediaPath = $this->directoryList->getUrlPath('media');
57+
$pos = strpos($imagePath, $mediaPath);
58+
if ($pos !== false) {
59+
$imagePath = substr($imagePath, $pos + strlen($mediaPath), strlen($baseUrl));
60+
}
61+
$imageUrl = rtrim($baseUrl, '/') . '/' . ltrim($imagePath, '/');
62+
63+
return $imageUrl;
64+
}
65+
}

app/code/Magento/CatalogGraphQl/etc/graphql/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,12 @@
141141
<type name="Magento\Catalog\Block\Product\ImageFactory">
142142
<plugin name="designLoader" type="Magento\CatalogGraphQl\Plugin\DesignLoader" />
143143
</type>
144+
145+
<type name="Magento\CatalogGraphQl\Model\Config\CategoryAttributeReader">
146+
<arguments>
147+
<argument name="categoryAttributeResolvers" xsi:type="array">
148+
<item name="image" xsi:type="string">Magento\CatalogGraphQl\Model\Resolver\Category\Image</item>
149+
</argument>
150+
</arguments>
151+
</type>
144152
</config>

app/code/Magento/SalesRule/Model/RulesApplier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected function getDiscountData($item, $rule)
209209
*/
210210
private function setDiscountBreakdown($discountData, $item, $rule)
211211
{
212-
if ($discountData->getAmount() > 0) {
212+
if ($discountData->getAmount() > 0 && $item->getExtensionAttributes()) {
213213
/** @var \Magento\SalesRule\Model\Rule\Action\Discount\Data $discount */
214214
$discount = $this->discountFactory->create();
215215
$discount->setBaseOriginalAmount($discountData->getBaseOriginalAmount());

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
"magento/module-graph-ql": "*",
172172
"magento/module-graph-ql-cache": "*",
173173
"magento/module-catalog-graph-ql": "*",
174+
"magento/module-catalog-cms-graph-ql": "*",
174175
"magento/module-catalog-url-rewrite-graph-ql": "*",
175176
"magento/module-configurable-product-graph-ql": "*",
176177
"magento/module-customer-graph-ql": "*",

composer.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)