Skip to content

Commit 6f3aeec

Browse files
merge magento/2.3-develop into magento-qwerty/MAGETWO-96975
2 parents 661dbff + 267db35 commit 6f3aeec

File tree

87 files changed

+4898
-937
lines changed

Some content is hidden

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

87 files changed

+4898
-937
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/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66
namespace Magento\AdvancedPricingImportExport\Model\Export;
77

8-
use Magento\ImportExport\Model\Export;
9-
use Magento\Store\Model\Store;
10-
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
118
use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing as ImportAdvancedPricing;
129
use Magento\Catalog\Model\Product as CatalogProduct;
10+
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
11+
use Magento\ImportExport\Model\Export;
12+
use Magento\Store\Model\Store;
1313

1414
/**
1515
* Export Advanced Pricing
@@ -150,6 +150,8 @@ public function __construct(
150150
}
151151

152152
/**
153+
* Init type models
154+
*
153155
* @return $this
154156
* @throws \Magento\Framework\Exception\LocalizedException
155157
*/
@@ -172,7 +174,9 @@ protected function initTypeModels()
172174
}
173175
if ($model->isSuitable()) {
174176
$this->_productTypeModels[$productTypeName] = $model;
177+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
175178
$this->_disabledAttrs = array_merge($this->_disabledAttrs, $model->getDisabledAttrs());
179+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
176180
$this->_indexValueAttributes = array_merge(
177181
$this->_indexValueAttributes,
178182
$model->getIndexValueAttributes()
@@ -197,6 +201,7 @@ protected function initTypeModels()
197201
public function export()
198202
{
199203
//Execution time may be very long
204+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
200205
set_time_limit(0);
201206

202207
$writer = $this->getWriter();
@@ -234,16 +239,6 @@ public function filterAttributeCollection(\Magento\Eav\Model\ResourceModel\Entit
234239

235240
foreach ($collection as $attribute) {
236241
if (in_array($attribute->getAttributeCode(), $this->_disabledAttrs)) {
237-
if (isset($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP])) {
238-
if ($attribute->getAttributeCode() == ImportAdvancedPricing::COL_TIER_PRICE
239-
&& in_array(
240-
$attribute->getId(),
241-
$this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP]
242-
)
243-
) {
244-
$this->_passTierPrice = 1;
245-
}
246-
}
247242
$collection->removeItemByKey($attribute->getId());
248243
}
249244
}
@@ -363,6 +358,7 @@ private function prepareExportData(
363358
$linkedTierPricesData = [];
364359
foreach ($tierPricesData as $tierPriceData) {
365360
$sku = $productLinkIdToSkuMap[$tierPriceData['product_link_id']];
361+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
366362
$linkedTierPricesData[] = array_merge(
367363
$tierPriceData,
368364
[ImportAdvancedPricing::COL_SKU => $sku]
@@ -471,7 +467,7 @@ private function fetchTierPrices(array $productIds): array
471467
ImportAdvancedPricing::COL_TIER_PRICE_QTY => 'ap.qty',
472468
ImportAdvancedPricing::COL_TIER_PRICE => 'ap.value',
473469
ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE => 'ap.percentage_value',
474-
'product_link_id' => 'ap.' .$productEntityLinkField,
470+
'product_link_id' => 'ap.' . $productEntityLinkField,
475471
];
476472
if ($exportFilter && array_key_exists('tier_price', $exportFilter)) {
477473
if (!empty($exportFilter['tier_price'][0])) {
@@ -488,7 +484,7 @@ private function fetchTierPrices(array $productIds): array
488484
$selectFields
489485
)
490486
->where(
491-
'ap.'.$productEntityLinkField.' IN (?)',
487+
'ap.' . $productEntityLinkField . ' IN (?)',
492488
$productIds
493489
);
494490

@@ -602,7 +598,7 @@ protected function _getWebsiteCode(int $websiteId): string
602598
}
603599

604600
if ($storeName && $currencyCode) {
605-
$code = $storeName.' ['.$currencyCode.']';
601+
$code = $storeName . ' [' . $currencyCode . ']';
606602
} else {
607603
$code = $storeName;
608604
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See COPYING.txt for license details.
33

44
type Mutation {
5-
createBraintreeClientToken: String! @resolver(class: "\\Magento\\BraintreeGraphQl\\Model\\Resolver\\CreateBraintreeClientToken") @doc(description:"Creates Braintree Client Token for creating client-side nonce.")
5+
createBraintreeClientToken: String! @resolver(class: "\\Magento\\BraintreeGraphQl\\Model\\Resolver\\CreateBraintreeClientToken") @doc(description:"Creates Client Token for Braintree Javascript SDK initialization.")
66
}
77

88
input PaymentMethodInput {
@@ -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__);

0 commit comments

Comments
 (0)