-
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.
Implementing the ID_V2 for entered options, bundle and downloadable p…
…roducts
- Loading branch information
Showing
7 changed files
with
208 additions
and
28 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
app/code/Magento/BundleGraphQl/Model/Resolver/Options/BundleEnteredOptionValueIdV2.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\BundleGraphQl\Model\Resolver\Options; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Format new option id_v2 in base64 encode for entered bundle options | ||
*/ | ||
class BundleEnteredOptionValueIdV2 implements ResolverInterface | ||
{ | ||
/** | ||
* Option type name | ||
*/ | ||
private const OPTION_TYPE = 'bundle'; | ||
|
||
/** | ||
* Create a option id_v2 for entered option in "<option-type>/<option-id>/<option-value-id>/<quantity>" format | ||
* | ||
* @param Field $field | ||
* @param ContextInterface $context | ||
* @param ResolveInfo $info | ||
* @param array|null $value | ||
* @param array|null $args | ||
* | ||
* @return string | ||
* | ||
* @throws GraphQlInputException | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!isset($value['option_id']) || empty($value['option_id'])) { | ||
throw new GraphQlInputException(__('Wrong format option data: option_id should not be empty.')); | ||
} | ||
|
||
if (!isset($value['selection_id']) || empty($value['selection_id'])) { | ||
throw new GraphQlInputException(__('Wrong format option data: selection_id should not be empty.')); | ||
} | ||
|
||
$optionDetails = [ | ||
self::OPTION_TYPE, | ||
$value['option_id'], | ||
$value['selection_id'], | ||
(int) $value['selection_qty'] | ||
]; | ||
|
||
$content = implode('/', $optionDetails); | ||
|
||
// phpcs:ignore Magento2.Functions.DiscouragedFunction | ||
return base64_encode($content); | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
...code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableEnteredOptionValueIdV2.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,62 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Product; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Format new option id_v2 in base64 encode for entered custom options | ||
*/ | ||
class CustomizableEnteredOptionValueIdV2 implements ResolverInterface | ||
{ | ||
/** | ||
* Option type name | ||
*/ | ||
private const OPTION_TYPE = 'custom-option'; | ||
|
||
/** | ||
* Create a option id_v2 for entered option in "<option-type>/<option-id>" format | ||
* | ||
* @param Field $field | ||
* @param ContextInterface $context | ||
* @param ResolveInfo $info | ||
* @param array|null $value | ||
* @param array|null $args | ||
* | ||
* @return string | ||
* | ||
* @throws GraphQlInputException | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!isset($value['option_id']) || empty($value['option_id'])) { | ||
throw new GraphQlInputException(__('Wrong format option data: option_id should not be empty.')); | ||
} | ||
|
||
$optionDetails = [ | ||
self::OPTION_TYPE, | ||
$value['option_id'] | ||
]; | ||
|
||
$content = implode('/', $optionDetails); | ||
|
||
// phpcs:ignore Magento2.Functions.DiscouragedFunction | ||
return base64_encode($content); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
app/code/Magento/DownloadableGraphQl/Resolver/Product/DownloadableLinksValueIdV2.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,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\DownloadableGraphQl\Resolver\Product; | ||
|
||
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; | ||
|
||
/** | ||
* Formatting the id_v2 for downloadable link | ||
*/ | ||
class DownloadableLinksValueIdV2 implements ResolverInterface | ||
{ | ||
private const OPTION_TYPE = 'downloadable'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!isset($value['id']) || empty($value['id'])) { | ||
throw new GraphQlInputException(__('Wrong format option data: `id` should not be empty.')); | ||
} | ||
|
||
$optionDetails = [ | ||
self::OPTION_TYPE, | ||
$value['id'] | ||
]; | ||
|
||
$content = implode('/', $optionDetails); | ||
|
||
// phpcs:ignore Magento2.Functions.DiscouragedFunction | ||
return base64_encode($content); | ||
} | ||
} |
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