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

Commit

Permalink
Merge remote-tracking branch 'upstream/2.3-develop' into feature/brai…
Browse files Browse the repository at this point in the history
…ntree-payment
  • Loading branch information
pmclain committed Jul 24, 2019
2 parents fe23996 + 72f72dd commit 2448894
Show file tree
Hide file tree
Showing 63 changed files with 933 additions and 227 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/AuthorizenetGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.

input PaymentMethodAdditionalDataInput {
input PaymentMethodInput {
authorizenet_acceptjs: AuthorizenetInput @doc(description: "Defines the required attributes for Authorize.Net payments")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Magento\CatalogGraphQl\Model\Resolver\Category;

use Magento\Catalog\Model\Category\Attribute\Source\Sortby;
use Magento\Catalog\Model\Config;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
Expand All @@ -17,32 +19,24 @@
class SortFields implements ResolverInterface
{
/**
* @var \Magento\Catalog\Model\Config
* @var Config
*/
private $catalogConfig;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;


/**
* @var \Magento\Catalog\Model\Category\Attribute\Source\Sortby
* @var Sortby
*/
private $sortbyAttributeSource;

/**
* @param \Magento\Catalog\Model\Config $catalogConfig
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @oaram \Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource
* @param Config $catalogConfig
* @param Sortby $sortbyAttributeSource
*/
public function __construct(
\Magento\Catalog\Model\Config $catalogConfig,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource
Config $catalogConfig,
Sortby $sortbyAttributeSource
) {
$this->catalogConfig = $catalogConfig;
$this->storeManager = $storeManager;
$this->sortbyAttributeSource = $sortbyAttributeSource;
}

Expand All @@ -52,17 +46,19 @@ public function __construct(
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$sortFieldsOptions = $this->sortbyAttributeSource->getAllOptions();
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();

array_walk(
$sortFieldsOptions,
function (&$option) {
$option['label'] = (string)$option['label'];
}
);
$data = [
'default' => $this->catalogConfig->getProductListDefaultSortBy($this->storeManager->getStore()->getId()),
'default' => $this->catalogConfig->getProductListDefaultSortBy($storeId),
'options' => $sortFieldsOptions,
];

return $data;
}
}
37 changes: 18 additions & 19 deletions app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,35 @@

namespace Magento\CatalogGraphQl\Model\Resolver\Product;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Catalog\Pricing\Price\RegularPrice;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\Pricing\Adjustment\AdjustmentInterface;
use Magento\Framework\Pricing\Amount\AmountInterface;
use Magento\Framework\Pricing\PriceInfo\Factory as PriceInfoFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;

/**
* Format a product's price information to conform to GraphQL schema representation
*/
class Price implements ResolverInterface
{
/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var PriceInfoFactory
*/
private $priceInfoFactory;

/**
* @param StoreManagerInterface $storeManager
* @param PriceInfoFactory $priceInfoFactory
*/
public function __construct(
StoreManagerInterface $storeManager,
PriceInfoFactory $priceInfoFactory
) {
$this->storeManager = $storeManager;
$this->priceInfoFactory = $priceInfoFactory;
}

Expand Down Expand Up @@ -80,11 +72,20 @@ public function resolve(
$minimalPriceAmount = $finalPrice->getMinimalPrice();
$maximalPriceAmount = $finalPrice->getMaximalPrice();
$regularPriceAmount = $priceInfo->getPrice(RegularPrice::PRICE_CODE)->getAmount();
$store = $context->getExtensionAttributes()->getStore();

$prices = [
'minimalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $minimalPriceAmount),
'regularPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $regularPriceAmount),
'maximalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $maximalPriceAmount)
'minimalPrice' => $this->createAdjustmentsArray(
$priceInfo->getAdjustments(),
$minimalPriceAmount,
$store
),
'regularPrice' => $this->createAdjustmentsArray(
$priceInfo->getAdjustments(),
$regularPriceAmount,
$store
),
'maximalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $maximalPriceAmount, $store)
];

return $prices;
Expand All @@ -95,13 +96,11 @@ public function resolve(
*
* @param AdjustmentInterface[] $adjustments
* @param AmountInterface $amount
* @param StoreInterface $store
* @return array
*/
private function createAdjustmentsArray(array $adjustments, AmountInterface $amount) : array
private function createAdjustmentsArray(array $adjustments, AmountInterface $amount, StoreInterface $store) : array
{
/** @var \Magento\Store\Model\Store $store */
$store = $this->storeManager->getStore();

$priceArray = [
'amount' => [
'value' => $amount->getValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Store\Model\StoreManagerInterface;

/**
* Returns product's image label
Expand All @@ -25,21 +24,13 @@ class Label implements ResolverInterface
*/
private $productResource;

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

/**
* @param ProductResourceModel $productResource
* @param StoreManagerInterface $storeManager
*/
public function __construct(
ProductResourceModel $productResource,
StoreManagerInterface $storeManager
ProductResourceModel $productResource
) {
$this->productResource = $productResource;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -65,15 +56,16 @@ public function resolve(
$imageType = $value['image_type'];
$imagePath = $product->getData($imageType);
$productId = (int)$product->getEntityId();
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();

// null if image is not set
if (null === $imagePath) {
return $this->getAttributeValue($productId, 'name');
return $this->getAttributeValue($productId, 'name', $storeId);
}

$imageLabel = $this->getAttributeValue($productId, $imageType . '_label');
$imageLabel = $this->getAttributeValue($productId, $imageType . '_label', $storeId);
if (null === $imageLabel) {
$imageLabel = $this->getAttributeValue($productId, 'name');
$imageLabel = $this->getAttributeValue($productId, 'name', $storeId);
}

return $imageLabel;
Expand All @@ -84,12 +76,11 @@ public function resolve(
*
* @param int $productId
* @param string $attributeCode
* @param int $storeId
* @return null|string Null if attribute value is not exists
*/
private function getAttributeValue(int $productId, string $attributeCode): ?string
private function getAttributeValue(int $productId, string $attributeCode, int $storeId): ?string
{
$storeId = $this->storeManager->getStore()->getId();

$value = $this->productResource->getAttributeRawValue($productId, $attributeCode, $storeId);
return is_array($value) && empty($value) ? null : $value;
}
Expand Down
15 changes: 3 additions & 12 deletions app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Cms\Api\GetPageByIdentifierInterface;
use Magento\Cms\Api\PageRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Widget\Model\Template\FilterEmulate;

/**
Expand All @@ -29,11 +28,6 @@ class Page
*/
private $pageRepository;

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

/**
* @var FilterEmulate
*/
Expand All @@ -43,19 +37,16 @@ class Page
* @param PageRepositoryInterface $pageRepository
* @param FilterEmulate $widgetFilter
* @param GetPageByIdentifierInterface $getPageByIdentifier
* @param StoreManagerInterface $storeManager
*/
public function __construct(
PageRepositoryInterface $pageRepository,
FilterEmulate $widgetFilter,
GetPageByIdentifierInterface $getPageByIdentifier,
StoreManagerInterface $storeManager
GetPageByIdentifierInterface $getPageByIdentifier
) {

$this->pageRepository = $pageRepository;
$this->widgetFilter = $widgetFilter;
$this->pageByIdentifier = $getPageByIdentifier;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -76,12 +67,12 @@ public function getDataByPageId(int $pageId): array
* Returns page data by page identifier
*
* @param string $pageIdentifier
* @param int $storeId
* @return array
* @throws NoSuchEntityException
*/
public function getDataByPageIdentifier(string $pageIdentifier): array
public function getDataByPageIdentifier(string $pageIdentifier, int $storeId): array
{
$storeId = (int)$this->storeManager->getStore()->getId();
$page = $this->pageByIdentifier->execute($pageIdentifier, $storeId);

return $this->convertPageData($page);
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/CmsGraphQl/Model/Resolver/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public function resolve(
if (isset($args['id'])) {
$pageData = $this->pageDataProvider->getDataByPageId((int)$args['id']);
} elseif (isset($args['identifier'])) {
$pageData = $this->pageDataProvider->getDataByPageIdentifier((string)$args['identifier']);
$pageData = $this->pageDataProvider->getDataByPageIdentifier(
(string)$args['identifier'],
(int)$context->getExtensionAttributes()->getStore()->getId()
);
}
} catch (NoSuchEntityException $e) {
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/CmsGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"php": "~7.1.3||~7.2.0",
"magento/framework": "*",
"magento/module-cms": "*",
"magento/module-store": "*",
"magento/module-widget": "*"
},
"suggest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;

/**
* Create new customer account
Expand All @@ -35,11 +35,6 @@ class CreateCustomerAccount
*/
private $accountManagement;

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

/**
* @var ChangeSubscriptionStatus
*/
Expand All @@ -48,35 +43,33 @@ class CreateCustomerAccount
/**
* @param DataObjectHelper $dataObjectHelper
* @param CustomerInterfaceFactory $customerFactory
* @param StoreManagerInterface $storeManager
* @param AccountManagementInterface $accountManagement
* @param ChangeSubscriptionStatus $changeSubscriptionStatus
*/
public function __construct(
DataObjectHelper $dataObjectHelper,
CustomerInterfaceFactory $customerFactory,
StoreManagerInterface $storeManager,
AccountManagementInterface $accountManagement,
ChangeSubscriptionStatus $changeSubscriptionStatus
) {
$this->dataObjectHelper = $dataObjectHelper;
$this->customerFactory = $customerFactory;
$this->accountManagement = $accountManagement;
$this->storeManager = $storeManager;
$this->changeSubscriptionStatus = $changeSubscriptionStatus;
}

/**
* Creates new customer account
*
* @param array $data
* @param StoreInterface $store
* @return CustomerInterface
* @throws GraphQlInputException
*/
public function execute(array $data): CustomerInterface
public function execute(array $data, StoreInterface $store): CustomerInterface
{
try {
$customer = $this->createAccount($data);
$customer = $this->createAccount($data, $store);
} catch (LocalizedException $e) {
throw new GraphQlInputException(__($e->getMessage()));
}
Expand All @@ -91,18 +84,18 @@ public function execute(array $data): CustomerInterface
* Create account
*
* @param array $data
* @param StoreInterface $store
* @return CustomerInterface
* @throws LocalizedException
*/
private function createAccount(array $data): CustomerInterface
private function createAccount(array $data, StoreInterface $store): CustomerInterface
{
$customerDataObject = $this->customerFactory->create();
$this->dataObjectHelper->populateWithArray(
$customerDataObject,
$data,
CustomerInterface::class
);
$store = $this->storeManager->getStore();
$customerDataObject->setWebsiteId($store->getWebsiteId());
$customerDataObject->setStoreId($store->getId());

Expand Down
Loading

0 comments on commit 2448894

Please sign in to comment.