-
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 #4400 from magento-engcom/graphql-develop-prs
[Magento Community Engineering] Community Contributions - GraphQL
- Loading branch information
Showing
25 changed files
with
1,095 additions
and
264 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.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,67 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Category; | ||
|
||
use Magento\Catalog\Api\Data\CategoryInterface; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Framework\EntityManager\MetadataPool; | ||
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; | ||
|
||
/** | ||
* Check if category is active. | ||
*/ | ||
class CheckCategoryIsActive | ||
{ | ||
/** | ||
* @var CollectionFactory | ||
*/ | ||
private $collectionFactory; | ||
|
||
/** | ||
* @var MetadataPool | ||
*/ | ||
private $metadata; | ||
|
||
/** | ||
* @param CollectionFactory $collectionFactory | ||
* @param MetadataPool $metadata | ||
*/ | ||
public function __construct( | ||
CollectionFactory $collectionFactory, | ||
MetadataPool $metadata | ||
) { | ||
$this->collectionFactory = $collectionFactory; | ||
$this->metadata = $metadata; | ||
} | ||
|
||
/** | ||
* Check if category is active. | ||
* | ||
* @param int $categoryId | ||
* @throws GraphQlNoSuchEntityException | ||
*/ | ||
public function execute(int $categoryId): void | ||
{ | ||
$collection = $this->collectionFactory->create(); | ||
$collection->addAttributeToFilter(CategoryInterface::KEY_IS_ACTIVE, ['eq' => 1]) | ||
->getSelect() | ||
->where( | ||
$collection->getSelect() | ||
->getConnection() | ||
->quoteIdentifier( | ||
'e.' . | ||
$this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() | ||
) . ' = ?', | ||
$categoryId | ||
); | ||
|
||
if ($collection->count() === 0) { | ||
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); | ||
} | ||
} | ||
} |
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
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
75 changes: 75 additions & 0 deletions
75
app/code/Magento/QuoteGraphQl/Model/Cart/CreateBuyRequest.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,75 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart; | ||
|
||
use Magento\Framework\DataObject; | ||
use Magento\Framework\DataObjectFactory; | ||
|
||
/** | ||
* Creates buy request that can be used for working with cart items | ||
*/ | ||
class CreateBuyRequest | ||
{ | ||
/** | ||
* @var DataObjectFactory | ||
*/ | ||
private $dataObjectFactory; | ||
|
||
/** | ||
* @param DataObjectFactory $dataObjectFactory | ||
*/ | ||
public function __construct( | ||
DataObjectFactory $dataObjectFactory | ||
) { | ||
$this->dataObjectFactory = $dataObjectFactory; | ||
} | ||
|
||
/** | ||
* Returns buy request for working with cart items | ||
* | ||
* @param float $qty | ||
* @param array $customizableOptionsData | ||
* @return DataObject | ||
*/ | ||
public function execute(float $qty, array $customizableOptionsData): DataObject | ||
{ | ||
$customizableOptions = []; | ||
foreach ($customizableOptionsData as $customizableOption) { | ||
if (isset($customizableOption['value_string'])) { | ||
$customizableOptions[$customizableOption['id']] = $this->convertCustomOptionValue( | ||
$customizableOption['value_string'] | ||
); | ||
} | ||
} | ||
|
||
return $this->dataObjectFactory->create( | ||
[ | ||
'data' => [ | ||
'qty' => $qty, | ||
'options' => $customizableOptions, | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Convert custom options value | ||
* | ||
* @param string $value | ||
* @return string|array | ||
*/ | ||
private function convertCustomOptionValue(string $value) | ||
{ | ||
$value = trim($value); | ||
if (substr($value, 0, 1) === "[" && | ||
substr($value, strlen($value) - 1, 1) === "]") { | ||
return explode(',', substr($value, 1, -1)); | ||
} | ||
return $value; | ||
} | ||
} |
Oops, something went wrong.