-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3791 from magento-engcom/graphql-develop-prs
[EngCom] Public Pull Requests - GraphQL
- Loading branch information
Showing
14 changed files
with
598 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Image/Placeholder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...e/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Image/Placeholder/Theme.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/code/Magento/CustomerGraphQl/Model/Resolver/IsEmailAvailable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/code/Magento/QuoteGraphQl/Model/Resolver/AvailablePaymentMethods.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.