Skip to content

Commit 0a4a7c8

Browse files
committed
check enable module
1 parent 903a537 commit 0a4a7c8

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

Model/Resolver/LabelDataProvider.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Magento\Framework\GraphQl\Query\ResolverInterface;
3030
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
3131
use Mageplaza\ProductLabels\Block\Label;
32+
use Mageplaza\ProductLabels\Helper\Data;
3233
use Mageplaza\ProductLabels\Model\LabelRepository;
3334
use Mageplaza\ProductLabels\Model\Rule;
3435

@@ -48,31 +49,43 @@ class LabelDataProvider implements ResolverInterface
4849
*/
4950
protected $label;
5051

52+
/**
53+
* @var Data
54+
*/
55+
protected $helperData;
56+
5157
/**
5258
* LabelDataProvider constructor.
5359
*
5460
* @param LabelRepository $labelRepository
5561
* @param Label $label
62+
* @param Data $helperData
5663
*/
5764
public function __construct(
5865
LabelRepository $labelRepository,
59-
Label $label
66+
Label $label,
67+
Data $helperData
6068
) {
6169
$this->labelRepository = $labelRepository;
6270
$this->label = $label;
71+
$this->helperData = $helperData;
6372
}
6473

6574
/**
6675
* @inheritdoc
6776
*/
6877
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
6978
{
79+
if (!$this->helperData->isEnabled()) {
80+
return [];
81+
}
82+
7083
if (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) {
7184
throw new LocalizedException(__('"model" value should be specified'));
7285
}
7386

7487
/* @var $product ProductInterface */
75-
$product = $value['model'];
88+
$product = $value['model'];
7689
$labelData = [];
7790

7891
/** @var Rule $rule */

Model/Resolver/LabelRules.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@
2929
use Magento\Framework\GraphQl\Query\ResolverInterface;
3030
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
3131
use Mageplaza\ProductLabels\Api\LabelRepositoryInterface;
32+
use Mageplaza\ProductLabels\Helper\Data;
3233

3334
/**
3435
* Class LabelRules
3536
* @package Mageplaza\ProductLabelsGraphQl\Model\Resolver
3637
*/
3738
class LabelRules implements ResolverInterface
3839
{
40+
/**
41+
* @var Data
42+
*/
43+
protected $helperData;
44+
3945
/**
4046
* @var SearchCriteriaBuilder
4147
*/
@@ -47,15 +53,18 @@ class LabelRules implements ResolverInterface
4753
protected $labelRuleRepository;
4854

4955
/**
50-
* Post constructor.
56+
* LabelRules constructor.
5157
*
58+
* @param Data $helperData
5259
* @param SearchCriteriaBuilder $searchCriteriaBuilder
5360
* @param LabelRepositoryInterface $labelRuleRepository
5461
*/
5562
public function __construct(
63+
Data $helperData,
5664
SearchCriteriaBuilder $searchCriteriaBuilder,
5765
LabelRepositoryInterface $labelRuleRepository
5866
) {
67+
$this->helperData = $helperData;
5968
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
6069
$this->labelRuleRepository = $labelRuleRepository;
6170
}
@@ -65,6 +74,10 @@ public function __construct(
6574
*/
6675
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
6776
{
77+
if (!$this->helperData->isEnabled()) {
78+
return [];
79+
}
80+
6881
$this->vailidateArgs($args);
6982
$searchCriteria = $this->searchCriteriaBuilder->build('label_rules', $args);
7083
$searchCriteria->setCurrentPage($args['currentPage']);

0 commit comments

Comments
 (0)