Skip to content

Commit 94383aa

Browse files
authored
Merge pull request #3791 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
2 parents 310648c + c2dd26d commit 94383aa

File tree

14 files changed

+598
-140
lines changed

14 files changed

+598
-140
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductImage/Url.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\Product\ImageFactory;
12+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image\Placeholder as PlaceholderProvider;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\GraphQl\Config\Element\Field;
1415
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -23,14 +24,21 @@ class Url implements ResolverInterface
2324
* @var ImageFactory
2425
*/
2526
private $productImageFactory;
27+
/**
28+
* @var PlaceholderProvider
29+
*/
30+
private $placeholderProvider;
2631

2732
/**
2833
* @param ImageFactory $productImageFactory
34+
* @param PlaceholderProvider $placeholderProvider
2935
*/
3036
public function __construct(
31-
ImageFactory $productImageFactory
37+
ImageFactory $productImageFactory,
38+
PlaceholderProvider $placeholderProvider
3239
) {
3340
$this->productImageFactory = $productImageFactory;
41+
$this->placeholderProvider = $placeholderProvider;
3442
}
3543

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

58-
$imageUrl = $this->getImageUrl($value['image_type'], $imagePath);
59-
return $imageUrl;
66+
return $this->getImageUrl($value['image_type'], $imagePath);
6067
}
6168

6269
/**
63-
* Get image url
70+
* Get image URL
6471
*
6572
* @param string $imageType
66-
* @param string|null $imagePath Null if image is not set
73+
* @param string|null $imagePath
6774
* @return string
75+
* @throws \Exception
6876
*/
6977
private function getImageUrl(string $imageType, ?string $imagePath): string
7078
{
7179
$image = $this->productImageFactory->create();
7280
$image->setDestinationSubdir($imageType)
7381
->setBaseFile($imagePath);
74-
$imageUrl = $image->getUrl();
75-
return $imageUrl;
82+
83+
if ($image->isBaseFilePlaceholder()) {
84+
return $this->placeholderProvider->getPlaceholder($imageType);
85+
}
86+
87+
return $image->getUrl();
7688
}
7789
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image;
9+
10+
use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
11+
use Magento\Framework\View\Asset\Repository as AssetRepository;
12+
13+
/**
14+
* Image Placeholder provider
15+
*/
16+
class Placeholder
17+
{
18+
/**
19+
* @var PlaceholderFactory
20+
*/
21+
private $placeholderFactory;
22+
23+
/**
24+
* @var AssetRepository
25+
*/
26+
private $assetRepository;
27+
28+
/**
29+
* @param PlaceholderFactory $placeholderFactory
30+
* @param AssetRepository $assetRepository
31+
*/
32+
public function __construct(
33+
PlaceholderFactory $placeholderFactory,
34+
AssetRepository $assetRepository
35+
) {
36+
$this->placeholderFactory = $placeholderFactory;
37+
$this->assetRepository = $assetRepository;
38+
}
39+
40+
/**
41+
* Get placeholder
42+
*
43+
* @param string $imageType
44+
* @return string
45+
*/
46+
public function getPlaceholder(string $imageType): string
47+
{
48+
$imageAsset = $this->placeholderFactory->create(['type' => $imageType]);
49+
50+
// check if placeholder defined in config
51+
if ($imageAsset->getFilePath()) {
52+
return $imageAsset->getUrl();
53+
}
54+
55+
return $this->assetRepository->getUrl(
56+
"Magento_Catalog::images/product/placeholder/{$imageType}.jpg"
57+
);
58+
}
59+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image\Placeholder;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
14+
/**
15+
* Theme provider
16+
*/
17+
class Theme
18+
{
19+
/**
20+
* @var ScopeConfigInterface
21+
*/
22+
private $scopeConfig;
23+
24+
/**
25+
* @var StoreManagerInterface
26+
*/
27+
private $storeManager;
28+
29+
/**
30+
* @var ThemeProviderInterface
31+
*/
32+
private $themeProvider;
33+
34+
/**
35+
* @param ScopeConfigInterface $scopeConfig
36+
* @param StoreManagerInterface $storeManager
37+
* @param ThemeProviderInterface $themeProvider
38+
*/
39+
public function __construct(
40+
ScopeConfigInterface $scopeConfig,
41+
StoreManagerInterface $storeManager,
42+
ThemeProviderInterface $themeProvider
43+
) {
44+
$this->scopeConfig = $scopeConfig;
45+
$this->storeManager = $storeManager;
46+
$this->themeProvider = $themeProvider;
47+
}
48+
49+
/**
50+
* Get theme model
51+
*
52+
* @return array
53+
* @throws \Magento\Framework\Exception\NoSuchEntityException
54+
*/
55+
public function getThemeData(): array
56+
{
57+
$themeId = $this->scopeConfig->getValue(
58+
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
59+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
60+
$this->storeManager->getStore()->getId()
61+
);
62+
63+
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
64+
$theme = $this->themeProvider->getThemeById($themeId);
65+
66+
$data = $theme->getData();
67+
$data['themeModel'] = $theme;
68+
69+
return $data;
70+
}
71+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type AddConfigurableProductsToCartOutput {
4949
}
5050

5151
input ConfigurableProductCartItemInput {
52-
data: CartItemDetailsInput!
52+
data: CartItemInput!
5353
variant_sku: String!
5454
customizable_options:[CustomizableOptionInput!]
5555
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\CustomerGraphQl\Model\Resolver;
9+
10+
use Magento\Customer\Api\AccountManagementInterface;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
16+
/**
17+
* Is Customer Email Available
18+
*/
19+
class IsEmailAvailable implements ResolverInterface
20+
{
21+
/**
22+
* @var AccountManagementInterface
23+
*/
24+
private $accountManagement;
25+
26+
/**
27+
* @param AccountManagementInterface $accountManagement
28+
*/
29+
public function __construct(
30+
AccountManagementInterface $accountManagement
31+
) {
32+
$this->accountManagement = $accountManagement;
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function resolve(
39+
Field $field,
40+
$context,
41+
ResolveInfo $info,
42+
array $value = null,
43+
array $args = null
44+
) {
45+
$email = $args['email'] ?? null;
46+
if (!$email) {
47+
throw new GraphQlInputException(__('"Email should be specified'));
48+
}
49+
$isEmailAvailable = $this->accountManagement->isEmailAvailable($email);
50+
51+
return [
52+
'is_email_available' => $isEmailAvailable
53+
];
54+
}
55+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

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

811
type Mutation {
@@ -126,6 +129,10 @@ type CustomerAddressAttribute {
126129
value: String @doc(description: "Attribute value")
127130
}
128131

132+
type IsEmailAvailableOutput {
133+
is_email_available: Boolean @doc(description: "Is email availabel value")
134+
}
135+
129136
enum CountryCodeEnum @doc(description: "The list of countries codes") {
130137
AF @doc(description: "Afghanistan")
131138
AX @doc(description: "Åland Islands")
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\QuoteGraphQl\Model\Resolver;
9+
10+
use Magento\Checkout\Api\PaymentInformationManagementInterface;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Quote\Api\Data\CartInterface;
16+
17+
/**
18+
* Get list of active payment methods resolver.
19+
*/
20+
class AvailablePaymentMethods implements ResolverInterface
21+
{
22+
/**
23+
* @var PaymentInformationManagementInterface
24+
*/
25+
private $informationManagement;
26+
27+
/**
28+
* @param PaymentInformationManagementInterface $informationManagement
29+
*/
30+
public function __construct(PaymentInformationManagementInterface $informationManagement)
31+
{
32+
$this->informationManagement = $informationManagement;
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
39+
{
40+
if (!isset($value['model'])) {
41+
throw new LocalizedException(__('"model" value should be specified'));
42+
}
43+
44+
$cart = $value['model'];
45+
return $this->getPaymentMethodsData($cart);
46+
}
47+
48+
/**
49+
* Collect and return information about available payment methods
50+
*
51+
* @param CartInterface $cart
52+
* @return array
53+
*/
54+
private function getPaymentMethodsData(CartInterface $cart): array
55+
{
56+
$paymentInformation = $this->informationManagement->getPaymentInformation($cart->getId());
57+
$paymentMethods = $paymentInformation->getPaymentMethods();
58+
59+
$paymentMethodsData = [];
60+
foreach ($paymentMethods as $paymentMethod) {
61+
$paymentMethodsData[] = [
62+
'title' => $paymentMethod->getTitle(),
63+
'code' => $paymentMethod->getCode(),
64+
];
65+
}
66+
return $paymentMethodsData;
67+
}
68+
}

app/code/Magento/QuoteGraphQl/Model/Resolver/Cart.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5454
$currentUserId = $context->getUserId();
5555
$cart = $this->getCartForUser->execute($maskedCartId, $currentUserId);
5656

57-
$data = array_merge(
58-
[
59-
'cart_id' => $maskedCartId,
60-
'model' => $cart
61-
],
62-
$this->extractDataFromCart->execute($cart)
63-
);
64-
57+
$data = $this->extractDataFromCart->execute($cart);
58+
$data['model'] = $cart;
6559
return $data;
6660
}
6761
}

app/code/Magento/QuoteGraphQl/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<argument name="supportedTypes" xsi:type="array">
1313
<item name="simple" xsi:type="string">SimpleCartItem</item>
1414
<item name="virtual" xsi:type="string">VirtualCartItem</item>
15+
<item name="configurable" xsi:type="string">ConfigurableCartItem</item>
1516
</argument>
1617
</arguments>
1718
</type>

0 commit comments

Comments
 (0)