Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
merge magento/2.3-develop into magento-tsg/2.3-develop-com-pr1
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-mts-svc authored Oct 17, 2019
2 parents 68dc933 + e2ac8c8 commit 2903792
Show file tree
Hide file tree
Showing 59 changed files with 3,306 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ $numColumns = $block->getColumns() !== null ? count($block->getColumns()) : 0;
<?php if ($block->getSortableUpdateCallback()) : ?>
<?= $block->escapeJs($block->getJsObjectName()) ?>.sortableUpdateCallback = <?= /* @noEscape */ $block->getSortableUpdateCallback() ?>;
<?php endif; ?>
<?php if ($block->getFilterKeyPressCallback()) : ?>
<?= $block->escapeJs($block->getJsObjectName()) ?>.filterKeyPressCallback = <?= /* @noEscape */ $block->getFilterKeyPressCallback() ?>;
<?php endif; ?>
<?= $block->escapeJs($block->getJsObjectName()) ?>.bindSortable();
<?php if ($block->getRowInitCallback()) : ?>
<?= $block->escapeJs($block->getJsObjectName()) ?>.initRowCallback = <?= /* @noEscape */ $block->getRowInitCallback() ?>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ $numColumns = count($block->getColumns());
<?php if ($block->getCheckboxCheckCallback()) : ?>
<?= $block->escapeJs($block->getJsObjectName()) ?>.checkboxCheckCallback = <?= /* @noEscape */ $block->getCheckboxCheckCallback() ?>;
<?php endif; ?>
<?php if ($block->getFilterKeyPressCallback()) : ?>
<?= $block->escapeJs($block->getJsObjectName()) ?>.filterKeyPressCallback = <?= /* @noEscape */ $block->getFilterKeyPressCallback() ?>;
<?php endif; ?>
<?php if ($block->getRowInitCallback()) : ?>
<?= $block->escapeJs($block->getJsObjectName()) ?>.initRowCallback = <?= /* @noEscape */ $block->getRowInitCallback() ?>;
<?= $block->escapeJs($block->getJsObjectName()) ?>.initGridRows();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Braintree\Error\Validation;
use Braintree\Result\Error;
use Braintree\Result\Successful;
use Braintree\Transaction;

/**
* Processes errors codes from Braintree response.
Expand Down Expand Up @@ -38,12 +39,14 @@ public function getErrorCodes($response): array
$result[] = $error->code;
}

if (isset($response->transaction) && $response->transaction->status === 'gateway_rejected') {
$result[] = $response->transaction->gatewayRejectionReason;
}
if (isset($response->transaction) && $response->transaction) {
if ($response->transaction->status === Transaction::GATEWAY_REJECTED) {
$result[] = $response->transaction->gatewayRejectionReason;
}

if (isset($response->transaction) && $response->transaction->status === 'processor_declined') {
$result[] = $response->transaction->processorResponseCode;
if ($response->transaction->status === Transaction::PROCESSOR_DECLINED) {
$result[] = $response->transaction->processorResponseCode;
}
}

return $result;
Expand Down
39 changes: 39 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Hydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Product;

use Magento\Framework\EntityManager\HydratorInterface;

/**
* Class is used to extract data and populate entity with data
*/
class Hydrator implements HydratorInterface
{
/**
* @inheritdoc
*/
public function extract($entity)
{
return $entity->getData();
}

/**
* @inheritdoc
*/
public function hydrate($entity, array $data)
{
$lockedAttributes = $entity->getLockedAttributes();
$entity->unlockAttributes();
$entity->setData(array_merge($entity->getData(), $data));
foreach ($lockedAttributes as $attribute) {
$entity->lockAttribute($attribute);
}

return $entity;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@
<argument name="hydrators" xsi:type="array">
<item name="Magento\Catalog\Api\Data\CategoryInterface" xsi:type="string">Magento\Framework\EntityManager\AbstractModelHydrator</item>
<item name="Magento\Catalog\Api\Data\CategoryTreeInterface" xsi:type="string">Magento\Framework\EntityManager\AbstractModelHydrator</item>
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="string">Magento\Framework\EntityManager\AbstractModelHydrator</item>
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="string">Magento\Catalog\Model\Product\Hydrator</item>
</argument>
</arguments>
</type>
Expand Down
102 changes: 102 additions & 0 deletions app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Category;

use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Catalog\Model\ResourceModel\Category\Collection;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\InputException;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Search\Model\Query;

/**
* Category filter allows to filter collection using 'id, url_key, name' from search criteria.
*/
class CategoryFilter
{
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

/**
* Filter for filtering the requested categories id's based on url_key, ids, name in the result.
*
* @param array $args
* @param Collection $categoryCollection
* @param StoreInterface $store
* @throws InputException
*/
public function applyFilters(array $args, Collection $categoryCollection, StoreInterface $store)
{
$categoryCollection->addAttributeToFilter(CategoryInterface::KEY_IS_ACTIVE, ['eq' => 1]);
foreach ($args['filters'] as $field => $cond) {
foreach ($cond as $condType => $value) {
if ($field === 'ids') {
$categoryCollection->addIdFilter($value);
} else {
$this->addAttributeFilter($categoryCollection, $field, $condType, $value, $store);
}
}
}
}

/**
* Add filter to category collection
*
* @param Collection $categoryCollection
* @param string $field
* @param string $condType
* @param string|array $value
* @param StoreInterface $store
* @throws InputException
*/
private function addAttributeFilter($categoryCollection, $field, $condType, $value, $store)
{
if ($condType === 'match') {
$this->addMatchFilter($categoryCollection, $field, $value, $store);
return;
}
$categoryCollection->addAttributeToFilter($field, [$condType => $value]);
}

/**
* Add match filter to collection
*
* @param Collection $categoryCollection
* @param string $field
* @param string $value
* @param StoreInterface $store
* @throws InputException
*/
private function addMatchFilter($categoryCollection, $field, $value, $store)
{
$minQueryLength = $this->scopeConfig->getValue(
Query::XML_PATH_MIN_QUERY_LENGTH,
ScopeInterface::SCOPE_STORE,
$store
);
$searchValue = str_replace('%', '', $value);
$matchLength = strlen($searchValue);
if ($matchLength < $minQueryLength) {
throw new InputException(__('Invalid match filter'));
}

$categoryCollection->addAttributeToFilter($field, ['like' => "%{$searchValue}%"]);
}
}
114 changes: 114 additions & 0 deletions app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver;

use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ExtractDataFromCategoryTree;
use Magento\Framework\Exception\InputException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree;
use Magento\CatalogGraphQl\Model\Category\CategoryFilter;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;

/**
* Category List resolver, used for GraphQL category data request processing.
*/
class CategoryList implements ResolverInterface
{
/**
* @var CategoryTree
*/
private $categoryTree;

/**
* @var CollectionFactory
*/
private $collectionFactory;

/**
* @var CategoryFilter
*/
private $categoryFilter;

/**
* @var ExtractDataFromCategoryTree
*/
private $extractDataFromCategoryTree;

/**
* @param CategoryTree $categoryTree
* @param ExtractDataFromCategoryTree $extractDataFromCategoryTree
* @param CategoryFilter $categoryFilter
* @param CollectionFactory $collectionFactory
*/
public function __construct(
CategoryTree $categoryTree,
ExtractDataFromCategoryTree $extractDataFromCategoryTree,
CategoryFilter $categoryFilter,
CollectionFactory $collectionFactory
) {
$this->categoryTree = $categoryTree;
$this->extractDataFromCategoryTree = $extractDataFromCategoryTree;
$this->categoryFilter = $categoryFilter;
$this->collectionFactory = $collectionFactory;
}

/**
* @inheritdoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (isset($value[$field->getName()])) {
return $value[$field->getName()];
}
$store = $context->getExtensionAttributes()->getStore();

$rootCategoryIds = [];
if (!isset($args['filters'])) {
$rootCategoryIds[] = (int)$store->getRootCategoryId();
} else {
$categoryCollection = $this->collectionFactory->create();
try {
$this->categoryFilter->applyFilters($args, $categoryCollection, $store);
} catch (InputException $e) {
return [];
}

foreach ($categoryCollection as $category) {
$rootCategoryIds[] = (int)$category->getId();
}
}

$result = $this->fetchCategories($rootCategoryIds, $info);
return $result;
}

/**
* Fetch category tree data
*
* @param array $categoryIds
* @param ResolveInfo $info
* @return array
* @throws GraphQlNoSuchEntityException
*/
private function fetchCategories(array $categoryIds, ResolveInfo $info)
{
$fetchedCategories = [];
foreach ($categoryIds as $categoryId) {
$categoryTree = $this->categoryTree->getTree($info, $categoryId);
if (empty($categoryTree)) {
continue;
}
$fetchedCategories[] = current($this->extractDataFromCategoryTree->execute($categoryTree));
}

return $fetchedCategories;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ private function getProductFields(ResolveInfo $info): array
$fieldNames[] = $this->collectProductFieldNames($selection, $fieldNames);
}
}

$fieldNames = array_merge(...$fieldNames);

if (!empty($fieldNames)) {
$fieldNames = array_merge(...$fieldNames);
}
return $fieldNames;
}

Expand Down
14 changes: 12 additions & 2 deletions app/code/Magento/CatalogGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ type Query {
): Products
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Products") @doc(description: "The products query searches for products that match the criteria specified in the search and filter attributes.") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Identity")
category (
id: Int @doc(description: "Id of the category.")
id: Int @doc(description: "Id of the category.")
): CategoryTree
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryTree") @doc(description: "The category query searches for categories that match the criteria specified in the search and filter attributes.") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoryTreeIdentity")
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryTree") @doc(description: "The category query searches for categories that match the criteria specified in the search and filter attributes.") @deprecated(reason: "Use 'categoryList' query instead of 'category' query") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoryTreeIdentity")
categoryList(
filters: CategoryFilterInput @doc(description: "Identifies which Category filter inputs to search for and return.")
): [CategoryTree] @doc(description: "Returns an array of categories based on the specified filters.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryList") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoriesIdentity")
}

type Price @doc(description: "Price is deprecated, replaced by ProductPrice. The Price object defines the price of a product as well as any tax-related adjustments.") {
Expand Down Expand Up @@ -294,6 +297,13 @@ input ProductAttributeFilterInput @doc(description: "ProductAttributeFilterInput
category_id: FilterEqualTypeInput @doc(description: "Filter product by category id")
}

input CategoryFilterInput @doc(description: "CategoryFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.")
{
ids: FilterEqualTypeInput @doc(description: "Filter by category ID that uniquely identifies the category.")
url_key: FilterEqualTypeInput @doc(description: "Filter by the part of the URL that identifies the category")
name: FilterMatchTypeInput @doc(description: "Filter by the display name of the category.")
}

input ProductFilterInput @doc(description: "ProductFilterInput is deprecated, use @ProductAttributeFilterInput instead. ProductFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") {
name: FilterTypeInput @doc(description: "The product name. Customers use this name to identify the product.")
sku: FilterTypeInput @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ define([
'jquery',
'Magento_Checkout/js/model/new-customer-address',
'Magento_Customer/js/customer-data',
'mage/utils/objects'
], function ($, address, customerData, mageUtils) {
'mage/utils/objects',
'underscore'
], function ($, address, customerData, mageUtils, _) {
'use strict';

var countryData = customerData.get('directory-data');
Expand Down Expand Up @@ -60,13 +61,15 @@ define([
delete addressData['region_id'];

if (addressData['custom_attributes']) {
addressData['custom_attributes'] = Object.entries(addressData['custom_attributes'])
.map(function (customAttribute) {
addressData['custom_attributes'] = _.map(
addressData['custom_attributes'],
function (value, key) {
return {
'attribute_code': customAttribute[0],
'value': customAttribute[1]
'attribute_code': key,
'value': value
};
});
}
);
}

return address(addressData);
Expand Down
Loading

0 comments on commit 2903792

Please sign in to comment.