Skip to content

Commit 7c6ccbf

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/2.3-develop' into MC-20181
2 parents cced20b + 502abab commit 7c6ccbf

File tree

60 files changed

+3712
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3712
-253
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Welcome to Magento 2 installation! We're glad you chose to install Magento 2, a
1111

1212
* [Installation Guide](https://devdocs.magento.com/guides/v2.3/install-gde/bk-install-guide.html).
1313

14+
## Learn More About GraphQL in Magento 2
15+
16+
* [GraphQL Developer Guide](https://devdocs.magento.com/guides/v2.3/graphql/index.html)
17+
1418
<h2>Contributing to the Magento 2 Code Base</h2>
1519
Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes, optimizations, or just good suggestions.
1620

app/code/Magento/BraintreeGraphQl/etc/schema.graphqls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ input PaymentMethodInput {
1111
}
1212

1313
input BraintreeInput {
14-
payment_method_nonce: String!
15-
is_active_payment_token_enabler: Boolean!
16-
device_data: String
14+
payment_method_nonce: String! @doc(description:"The one-time payment token generated by Braintree payment gateway based on card details. Required field to make sale transaction.")
15+
is_active_payment_token_enabler: Boolean! @doc(description:"States whether an entered by a customer credit/debit card should be tokenized for later usage. Required only if Vault is enabled for Braintree payment integration.")
16+
device_data: String @doc(description:"Contains a fingerprint provided by Braintree JS SDK and should be sent with sale transaction details to the Braintree payment gateway. Should be specified only in a case if Kount (advanced fraud protection) is enabled for Braintree payment integration.")
1717
}
1818

1919
input BraintreeCcVaultInput {
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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\CatalogCustomerGraphQl\Model\Resolver;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
12+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
13+
use Magento\Customer\Api\CustomerRepositoryInterface;
14+
use Magento\Customer\Model\GroupManagement;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17+
use Magento\Framework\GraphQl\Config\Element\Field;
18+
use Magento\Framework\GraphQl\Query\ResolverInterface;
19+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
20+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
21+
use Magento\Framework\Exception\NoSuchEntityException;
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
class TierPrices implements ResolverInterface
27+
{
28+
/**
29+
* @var Collection
30+
*/
31+
private $collection;
32+
33+
/**
34+
* @var CustomerRepositoryInterface
35+
*/
36+
private $customerRepository;
37+
38+
/**
39+
* @var ValueFactory
40+
*/
41+
private $valueFactory;
42+
43+
/**
44+
* @var int
45+
*/
46+
private $customerGroupId = null;
47+
48+
/**
49+
* @var array
50+
*/
51+
private $productIds = [];
52+
53+
/**
54+
* @param CollectionFactory $collectionFactory
55+
* @param ValueFactory $valueFactory
56+
* @param CustomerRepositoryInterface $customerRepository
57+
*/
58+
public function __construct(
59+
CollectionFactory $collectionFactory,
60+
ValueFactory $valueFactory,
61+
CustomerRepositoryInterface $customerRepository
62+
) {
63+
$this->collection = $collectionFactory->create();
64+
$this->valueFactory = $valueFactory;
65+
$this->customerRepository = $customerRepository;
66+
}
67+
68+
/**
69+
* @inheritdoc
70+
*/
71+
public function resolve(
72+
Field $field,
73+
$context,
74+
ResolveInfo $info,
75+
array $value = null,
76+
array $args = null
77+
) {
78+
if (!isset($value['model'])) {
79+
throw new LocalizedException(__('"model" value should be specified'));
80+
}
81+
82+
if (null === $this->customerGroupId) {
83+
$this->customerGroupId = $this->getCustomerGroupId($context);
84+
}
85+
86+
/** @var Product $product */
87+
$product = $value['model'];
88+
$productId = $product->getId();
89+
$this->productIds[] = $productId;
90+
$that = $this;
91+
92+
return $this->valueFactory->create(
93+
function () use ($that, $productId, $context) {
94+
$tierPrices = [];
95+
if (empty($that->productIds)) {
96+
return [];
97+
}
98+
if (!$that->collection->isLoaded()) {
99+
$that->collection->addIdFilter($that->productIds);
100+
$that->collection->addTierPriceDataByGroupId($that->customerGroupId);
101+
}
102+
/** @var \Magento\Catalog\Model\Product $item */
103+
foreach ($that->collection as $item) {
104+
if ($item->getId() === $productId) {
105+
// Try to extract all requested fields from the loaded collection data
106+
foreach ($item->getTierPrices() as $tierPrice) {
107+
$tierPrices[] = $tierPrice->getData();
108+
}
109+
}
110+
}
111+
return $tierPrices;
112+
}
113+
);
114+
}
115+
116+
/**
117+
* Get the customer group Id.
118+
*
119+
* @param \Magento\GraphQl\Model\Query\ContextInterface $context
120+
*
121+
* @return int
122+
*/
123+
private function getCustomerGroupId(\Magento\GraphQl\Model\Query\ContextInterface $context)
124+
{
125+
$currentUserId = $context->getUserId();
126+
if (!$currentUserId) {
127+
$customerGroupId = GroupManagement::NOT_LOGGED_IN_ID;
128+
} else {
129+
try {
130+
$customer = $this->customerRepository->getById($currentUserId);
131+
} catch (NoSuchEntityException $e) {
132+
throw new GraphQlNoSuchEntityException(
133+
__('Customer with id "%customer_id" does not exist.', ['customer_id' => $currentUserId]),
134+
$e
135+
);
136+
}
137+
$customerGroupId = $customer->getGroupId();
138+
}
139+
return $customerGroupId;
140+
}
141+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CatalogCustomerGraphQl
2+
3+
**CatalogCustomerGraphQl** provides type and resolver information for GraphQL attributes that have dependences on the Catalog and Customer modules.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "magento/module-catalog-customer-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/module-catalog": "*",
8+
"magento/module-customer": "*",
9+
"magento/framework": "*",
10+
"magento/module-graph-ql": "*"
11+
},
12+
"license": [
13+
"OSL-3.0",
14+
"AFL-3.0"
15+
],
16+
"autoload": {
17+
"files": [
18+
"registration.php"
19+
],
20+
"psr-4": {
21+
"Magento\\CatalogCustomerGraphQl\\": ""
22+
}
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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_CatalogCustomerGraphQl" >
10+
<sequence>
11+
<module name="Magento_Catalog"/>
12+
<module name="Magento_Customer"/>
13+
<module name="Magento_GraphQl"/>
14+
</sequence>
15+
</module>
16+
</config>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
interface ProductInterface {
5+
tier_prices: [ProductTierPrices] @doc(description: "An array of ProductTierPrices objects.") @resolver(class: "Magento\\CatalogCustomerGraphQl\\Model\\Resolver\\TierPrices")
6+
}
7+
8+
type ProductTierPrices @doc(description: "The ProductTierPrices object defines a tier price, which is a quantity discount offered to a specific customer group.") {
9+
customer_group_id: String @doc(description: "The ID of the customer group.")
10+
qty: Float @doc(description: "The number of items that must be purchased to qualify for tier pricing.")
11+
value: Float @doc(description: "The price of the fixed price item.")
12+
percentage_value: Float @doc(description: "The percentage discount of the item.")
13+
website_id: Float @doc(description: "The ID assigned to the website.")
14+
}
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_CatalogCustomerGraphQl', __DIR__);

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/TierPrices.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ interface ProductLinksInterface @typeResolver(class: "Magento\\CatalogGraphQl\\M
5858
position: Int @doc(description: "The position within the list of product links.")
5959
}
6060

61-
type ProductTierPrices @doc(description: "The ProductTierPrices object defines a tier price, which is a quantity discount offered to a specific customer group.") {
62-
customer_group_id: String @doc(description: "The ID of the customer group.")
63-
qty: Float @doc(description: "The number of items that must be purchased to qualify for tier pricing.")
64-
value: Float @doc(description: "The price of the fixed price item.")
65-
percentage_value: Float @doc(description: "The percentage discount of the item.")
66-
website_id: Float @doc(description: "The ID assigned to the website.")
67-
}
6861

6962
interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\ProductInterfaceTypeResolverComposite") @doc(description: "The ProductInterface contains attributes that are common to all types of products. Note that descriptions may not be available for custom and EAV attributes.") {
7063
id: Int @doc(description: "The ID number assigned to the product.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\EntityIdToId")
@@ -93,7 +86,6 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
9386
websites: [Website] @doc(description: "An array of websites in which the product is available.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Websites")
9487
product_links: [ProductLinksInterface] @doc(description: "An array of ProductLinks objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductLinks")
9588
media_gallery_entries: [MediaGalleryEntry] @deprecated(reason: "Use product's `media_gallery` instead") @doc(description: "An array of MediaGalleryEntry objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGalleryEntries")
96-
tier_prices: [ProductTierPrices] @doc(description: "An array of ProductTierPrices objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\TierPrices")
9789
price: ProductPrices @doc(description: "A ProductPrices object, indicating the price of an item.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Price")
9890
gift_message_available: String @doc(description: "Indicates whether a gift message is available.")
9991
manufacturer: Int @doc(description: "A number representing the product's manufacturer.")

0 commit comments

Comments
 (0)