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

Commit

Permalink
Merge branch '2.3-develop' into graphQl-200
Browse files Browse the repository at this point in the history
  • Loading branch information
kisroman committed Feb 22, 2019
2 parents 0e6c6ab + dfe0dfe commit 53c7a26
Show file tree
Hide file tree
Showing 14 changed files with 598 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\ImageFactory;
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image\Placeholder as PlaceholderProvider;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
Expand All @@ -23,14 +24,21 @@ class Url implements ResolverInterface
* @var ImageFactory
*/
private $productImageFactory;
/**
* @var PlaceholderProvider
*/
private $placeholderProvider;

/**
* @param ImageFactory $productImageFactory
* @param PlaceholderProvider $placeholderProvider
*/
public function __construct(
ImageFactory $productImageFactory
ImageFactory $productImageFactory,
PlaceholderProvider $placeholderProvider
) {
$this->productImageFactory = $productImageFactory;
$this->placeholderProvider = $placeholderProvider;
}

/**
Expand All @@ -55,23 +63,27 @@ public function resolve(
$product = $value['model'];
$imagePath = $product->getData($value['image_type']);

$imageUrl = $this->getImageUrl($value['image_type'], $imagePath);
return $imageUrl;
return $this->getImageUrl($value['image_type'], $imagePath);
}

/**
* Get image url
* Get image URL
*
* @param string $imageType
* @param string|null $imagePath Null if image is not set
* @param string|null $imagePath
* @return string
* @throws \Exception
*/
private function getImageUrl(string $imageType, ?string $imagePath): string
{
$image = $this->productImageFactory->create();
$image->setDestinationSubdir($imageType)
->setBaseFile($imagePath);
$imageUrl = $image->getUrl();
return $imageUrl;

if ($image->isBaseFilePlaceholder()) {
return $this->placeholderProvider->getPlaceholder($imageType);
}

return $image->getUrl();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image;

use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
use Magento\Framework\View\Asset\Repository as AssetRepository;

/**
* Image Placeholder provider
*/
class Placeholder
{
/**
* @var PlaceholderFactory
*/
private $placeholderFactory;

/**
* @var AssetRepository
*/
private $assetRepository;

/**
* @param PlaceholderFactory $placeholderFactory
* @param AssetRepository $assetRepository
*/
public function __construct(
PlaceholderFactory $placeholderFactory,
AssetRepository $assetRepository
) {
$this->placeholderFactory = $placeholderFactory;
$this->assetRepository = $assetRepository;
}

/**
* Get placeholder
*
* @param string $imageType
* @return string
*/
public function getPlaceholder(string $imageType): string
{
$imageAsset = $this->placeholderFactory->create(['type' => $imageType]);

// check if placeholder defined in config
if ($imageAsset->getFilePath()) {
return $imageAsset->getUrl();
}

return $this->assetRepository->getUrl(
"Magento_Catalog::images/product/placeholder/{$imageType}.jpg"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image\Placeholder;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Theme provider
*/
class Theme
{
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var ThemeProviderInterface
*/
private $themeProvider;

/**
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
* @param ThemeProviderInterface $themeProvider
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
ThemeProviderInterface $themeProvider
) {
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
$this->themeProvider = $themeProvider;
}

/**
* Get theme model
*
* @return array
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getThemeData(): array
{
$themeId = $this->scopeConfig->getValue(
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->storeManager->getStore()->getId()
);

/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
$theme = $this->themeProvider->getThemeById($themeId);

$data = $theme->getData();
$data['themeModel'] = $theme;

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type AddConfigurableProductsToCartOutput {
}

input ConfigurableProductCartItemInput {
data: CartItemDetailsInput!
data: CartItemInput!
variant_sku: String!
customizable_options:[CustomizableOptionInput!]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CustomerGraphQl\Model\Resolver;

use Magento\Customer\Api\AccountManagementInterface;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Is Customer Email Available
*/
class IsEmailAvailable implements ResolverInterface
{
/**
* @var AccountManagementInterface
*/
private $accountManagement;

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

/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
$email = $args['email'] ?? null;
if (!$email) {
throw new GraphQlInputException(__('"Email should be specified'));
}
$isEmailAvailable = $this->accountManagement->isEmailAvailable($email);

return [
'is_email_available' => $isEmailAvailable
];
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/CustomerGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

type Query {
customer: Customer @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\Customer") @doc(description: "The customer query returns information about a customer account")
isEmailAvailable (
email: String! @doc(description: "The new customer email")
): IsEmailAvailableOutput @resolver(class: "Magento\\CustomerGraphQl\\Model\\Resolver\\IsEmailAvailable")
}

type Mutation {
Expand Down Expand Up @@ -126,6 +129,10 @@ type CustomerAddressAttribute {
value: String @doc(description: "Attribute value")
}

type IsEmailAvailableOutput {
is_email_available: Boolean @doc(description: "Is email availabel value")
}

enum CountryCodeEnum @doc(description: "The list of countries codes") {
AF @doc(description: "Afghanistan")
AX @doc(description: "Åland Islands")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\QuoteGraphQl\Model\Resolver;

use Magento\Checkout\Api\PaymentInformationManagementInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Api\Data\CartInterface;

/**
* Get list of active payment methods resolver.
*/
class AvailablePaymentMethods implements ResolverInterface
{
/**
* @var PaymentInformationManagementInterface
*/
private $informationManagement;

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

/**
* @inheritdoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($value['model'])) {
throw new LocalizedException(__('"model" value should be specified'));
}

$cart = $value['model'];
return $this->getPaymentMethodsData($cart);
}

/**
* Collect and return information about available payment methods
*
* @param CartInterface $cart
* @return array
*/
private function getPaymentMethodsData(CartInterface $cart): array
{
$paymentInformation = $this->informationManagement->getPaymentInformation($cart->getId());
$paymentMethods = $paymentInformation->getPaymentMethods();

$paymentMethodsData = [];
foreach ($paymentMethods as $paymentMethod) {
$paymentMethodsData[] = [
'title' => $paymentMethod->getTitle(),
'code' => $paymentMethod->getCode(),
];
}
return $paymentMethodsData;
}
}
10 changes: 2 additions & 8 deletions app/code/Magento/QuoteGraphQl/Model/Resolver/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
$currentUserId = $context->getUserId();
$cart = $this->getCartForUser->execute($maskedCartId, $currentUserId);

$data = array_merge(
[
'cart_id' => $maskedCartId,
'model' => $cart
],
$this->extractDataFromCart->execute($cart)
);

$data = $this->extractDataFromCart->execute($cart);
$data['model'] = $cart;
return $data;
}
}
1 change: 1 addition & 0 deletions app/code/Magento/QuoteGraphQl/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<argument name="supportedTypes" xsi:type="array">
<item name="simple" xsi:type="string">SimpleCartItem</item>
<item name="virtual" xsi:type="string">VirtualCartItem</item>
<item name="configurable" xsi:type="string">ConfigurableCartItem</item>
</argument>
</arguments>
</type>
Expand Down
Loading

0 comments on commit 53c7a26

Please sign in to comment.