Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.3-develop' into ip-ranges
Browse files Browse the repository at this point in the history
* upstream/2.3-develop: (37 commits)
  MAGETWO-81033: Create GraphQL single product fetch endpoint  - Address static failure
  MAGETWO-81033: Remove unnecessary classes
  MAGETWO-81033: Create GraphQL endpoint for fetching single product  - Adds functional tests, fixtures, and client  - Adds support for simple and configurable product
  magento#11524: Fix Filter Customer Report Review  - Integration test updated
  MAGETWO-82561: [TASK] Moved Customer Groups Menu Item from Other settings to Customers magento#11652
  MQE-478: Deliver Pangolins Sprint 11
  MQE-478: Deliver Pangolins Sprint 11
  MQE-478: Deliver Pangolins Sprint 11
  magento#11522: Fix Filter Customer Report Review  - Integration test updated
  magento#11524: Fix Filter Customer Report Review  - Integration test added
  Fix Magento/Backend/Block/Media/Uploader.php getConfigJson() method, using undefined class property _coreData
  MAGETWO-77673: <![CDATA[]]>in system.xml translate phrase not work, if comment starts from new line[port from 2.2-develop].
  MQE-478: Deliver Pangolins Sprint 11
  MQE-440: metadata changes for path parameters bug fix.
  MQE-237: [Generator] Add before and after logic to suites
  MQE-394: Pre-Install Script
  MQE-440: Added configurable product related metadata, data, and a sample test.
  MQE-429: Added a sample test to perform api PUT request.
  MQE-453: [DevOps] Add optional arg for consolidated test run
  MQE-345: [DevOps] [Customizability] Create suite schema declaration and supporting interpretation
  ...
  • Loading branch information
Anton Evers committed Oct 26, 2017
2 parents 9457972 + fef1485 commit 3a4c2b4
Show file tree
Hide file tree
Showing 116 changed files with 4,376 additions and 696 deletions.
15 changes: 13 additions & 2 deletions app/code/Magento/Backend/Block/Media/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\Backend\Block\Media;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;

/**
* Adminhtml media library uploader
* @api
Expand All @@ -27,17 +30,25 @@ class Uploader extends \Magento\Backend\Block\Widget
*/
protected $_fileSizeService;

/**
* @var Json
*/
private $jsonEncoder;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\File\Size $fileSize
* @param array $data
* @param Json $jsonEncoder
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\File\Size $fileSize,
array $data = []
array $data = [],
Json $jsonEncoder = null
) {
$this->_fileSizeService = $fileSize;
$this->jsonEncoder = $jsonEncoder ?: ObjectManager::getInstance()->get(Json::class);
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -107,7 +118,7 @@ public function getJsObjectName()
*/
public function getConfigJson()
{
return $this->_coreData->jsonEncode($this->getConfig()->getData());
return $this->jsonEncoder->encode($this->getConfig()->getData());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/etc/adminhtml/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<add id="Magento_Customer::customer" title="Customers" translate="title" module="Magento_Customer" sortOrder="30" resource="Magento_Customer::customer"/>
<add id="Magento_Customer::customer_manage" title="All Customers" translate="title" module="Magento_Customer" sortOrder="10" parent="Magento_Customer::customer" action="customer/index/" resource="Magento_Customer::manage"/>
<add id="Magento_Customer::customer_online" title="Now Online" translate="title" module="Magento_Customer" sortOrder="30" parent="Magento_Customer::customer" action="customer/online/" resource="Magento_Customer::online"/>
<add id="Magento_Customer::customer_group" title="Customer Groups" translate="title" module="Magento_Customer" sortOrder="50" parent="Magento_Backend::other_settings" action="customer/group" resource="Magento_Customer::group"/>
<add id="Magento_Customer::customer_group" title="Customer Groups" translate="title" module="Magento_Customer" sortOrder="50" parent="Magento_Customer::customer" action="customer/group" resource="Magento_Customer::group"/>
</menu>
</config>
77 changes: 77 additions & 0 deletions app/code/Magento/GraphQl/Controller/GraphQl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\GraphQl\Controller;

use GraphQL\Error\FormattedError;
use Magento\Framework\App\FrontControllerInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Webapi\Response;
use Magento\GraphQl\Model\SchemaGeneratorInterface;

/**
* Front controller for web API GraphQL area.
*/
class GraphQl implements FrontControllerInterface
{
/**
* @var Response
*/
private $response;

/**
* @var SchemaGeneratorInterface
*/
private $schemaGenerator;

/**
* Initialize dependencies
*
* @param Response $response
* @param SchemaGeneratorInterface $schemaGenerator
*/
public function __construct(
Response $response,
SchemaGeneratorInterface $schemaGenerator
) {
$this->response = $response;
$this->schemaGenerator = $schemaGenerator;
}

/**
* Handle GraphQL request
*
* @param RequestInterface $request
* @return ResponseInterface
*/
public function dispatch(RequestInterface $request)
{
try {
if ($request->getHeader('Content-Type')
&& strpos($request->getHeader('Content-Type'), 'application/json') !== false
) {
$raw = file_get_contents('php://input') ?: '';
$data = json_decode($raw, true);
} else {
$data = $_REQUEST;
}
$schema = $this->schemaGenerator->generate();
$result = \GraphQL\GraphQL::execute(
$schema,
isset($data['query']) ? $data['query'] : '',
null,
null,
isset($data['variables']) ? $data['variables'] : []
);
} catch (\Exception $error) {
$result['extensions']['exception'] = FormattedError::createFromException($error);
$this->response->setStatusCode(500);
}
$this->response->setBody(json_encode($result))->setHeader('Content-Type', 'application/json');
return $this->response;
}
}
77 changes: 77 additions & 0 deletions app/code/Magento/GraphQl/Model/Resolver/MediaGalleryEntries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\GraphQl\Model\Resolver;

use Magento\Catalog\Api\ProductAttributeMediaGalleryManagementInterface;
use Magento\Framework\Api\ExtensibleDataInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Webapi\ServiceOutputProcessor;

/**
* Media gallery field resolver, used for GraphQL request processing.
*/
class MediaGalleryEntries
{
/**
* @var ProductAttributeMediaGalleryManagementInterface
*/
private $mediaGalleryManagement;

/**
* @var ServiceOutputProcessor
*/
private $serviceOutputProcessor;

/**
* MediaGalleryEntries constructor.
*
* @param ProductAttributeMediaGalleryManagementInterface $mediaGalleryManagement
* @param ServiceOutputProcessor $serviceOutputProcessor
*/
public function __construct(
ProductAttributeMediaGalleryManagementInterface $mediaGalleryManagement,
ServiceOutputProcessor $serviceOutputProcessor
) {
$this->mediaGalleryManagement = $mediaGalleryManagement;
$this->serviceOutputProcessor = $serviceOutputProcessor;
}

/**
* Get media gallery entries for the specified product.
*
* @param string $sku
* @return array|null
*/
public function getMediaGalleryEntries(string $sku)
{
try {
$mediaGalleryObjectArray = $this->mediaGalleryManagement->getList($sku);
} catch (NoSuchEntityException $e) {
// No error should be thrown, null result should be returned
return null;
}

$mediaGalleryList = $this->serviceOutputProcessor->process(
$mediaGalleryObjectArray,
ProductAttributeMediaGalleryManagementInterface::class,
'getList'
);

foreach ($mediaGalleryList as $key => $mediaGallery) {
if (isset($mediaGallery[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])
&& isset($mediaGallery[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['video_content'])) {
$mediaGallery = array_merge(
$mediaGallery,
$mediaGallery[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]
);
$mediaGalleryList[$key] = $mediaGallery;
}
}

return $mediaGalleryList;
}
}
149 changes: 149 additions & 0 deletions app/code/Magento/GraphQl/Model/Resolver/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\GraphQl\Model\Resolver;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Webapi\ServiceOutputProcessor;

/**
* Product field resolver, used for GraphQL request processing.
*/
class Product
{
/**
* @var ProductRepositoryInterface
*/
private $productRepository;

/**
* @var ServiceOutputProcessor
*/
private $serviceOutputProcessor;

/**
* @var MediaGalleryEntries
*/
private $mediaGalleryResolver;

/**
* Initialize dependencies
*
* @param ProductRepositoryInterface $productRepository
* @param ServiceOutputProcessor $serviceOutputProcessor
* @param MediaGalleryEntries $mediaGalleryResolver
*/
public function __construct(
ProductRepositoryInterface $productRepository,
ServiceOutputProcessor $serviceOutputProcessor,
MediaGalleryEntries $mediaGalleryResolver
) {
$this->productRepository = $productRepository;
$this->serviceOutputProcessor = $serviceOutputProcessor;
$this->mediaGalleryResolver = $mediaGalleryResolver;
}

/**
* Resolves product by Sku
*
* @param string $sku
* @return array|null
*/
public function getProduct(string $sku)
{
try {
$productObject = $this->productRepository->get($sku);
} catch (NoSuchEntityException $e) {
// No error should be thrown, null result should be returned
return null;
}
return $this->processProduct($productObject);
}

/**
* Resolves product by Id
*
* @param int $productId
* @return array|null
*/
public function getProductById(int $productId)
{
try {
$productObject = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
// No error should be thrown, null result should be returned
return null;
}
return $this->processProduct($productObject);
}

/**
* Retrieve single product data in array format
*
* @param \Magento\Catalog\Api\Data\ProductInterface $productObject
* @return array|null
*/
private function processProduct(\Magento\Catalog\Api\Data\ProductInterface $productObject)
{
$product = $this->serviceOutputProcessor->process(
$productObject,
ProductRepositoryInterface::class,
'get'
);
$product = array_merge($product, $product['extension_attributes']);
if (isset($product['custom_attributes'])) {
$customAttributes = [];
foreach ($product['custom_attributes'] as $attribute) {
$isArray = false;
if (is_array($attribute['value'])) {
$isArray = true;
foreach ($attribute['value'] as $attributeValue) {
if (is_array($attributeValue)) {
$customAttributes[$attribute['attribute_code']] = json_encode($attribute['value']);
continue;
}
$customAttributes[$attribute['attribute_code']] = implode(',', $attribute['value']);
continue;
}
}
if ($isArray) {
continue;
}
$customAttributes[$attribute['attribute_code']] = $attribute['value'];
}
}
$product = array_merge($product, $customAttributes);
$product = array_merge($product, $product['product_links']);
$product['media_gallery_entries'] = $this
->mediaGalleryResolver->getMediaGalleryEntries($productObject->getSku());

if (isset($product['configurable_product_links'])) {
$product['configurable_product_links'] = $this
->resolveConfigurableProductLinks($product['configurable_product_links']);
}

return $product;
}

/**
* Resolve links for configurable product into simple products
*
* @param int[]
* @return array
*/
private function resolveConfigurableProductLinks($configurableProductLinks)
{
if (empty($configurableProductLinks)) {
return [];
}
$result = [];
foreach ($configurableProductLinks as $key => $id) {
$result[$key] = $this->getProductById($id);
}
return $result;
}
}
Loading

0 comments on commit 3a4c2b4

Please sign in to comment.