Skip to content

Commit 7de6c65

Browse files
Merge pull request #1 from mageplaza/develop
Develop
2 parents 98b988d + 6b9c28a commit 7de6c65

File tree

13 files changed

+540
-1
lines changed

13 files changed

+540
-1
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CHANGELOG: https://www.mageplaza.com/releases/product-labels/

LICENSE

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Copyright © 2016-present Mageplaza Co. Ltd.
2+
3+
This License is entered by Mageplaza to govern the usage or redistribution of Mageplaza software. This is a legal agreement between you (either an individual or a single entity) and Mageplaza for Mageplaza software product(s) which may include extensions, templates and services.
4+
5+
By purchasing, installing, or otherwise using Mageplaza products, you acknowledge that you have read this License and agree to be bound by the terms of this Agreement. If you do not agree to the terms of this License, do not install or use Mageplaza products.
6+
7+
The Agreement becomes effective at the moment when you acquire software from our site or receive it through email or on data medium or by any other means. Mageplaza reserves the right to make reasonable changes to the terms of this license agreement and impose its clauses at any given time.
8+
9+
1. GRANT OF LICENSE: By purchasing a product of Mageplaza:
10+
11+
1. Customer will receive source code open 100%.
12+
13+
2. Customer will obtain a License Certificate which will remain valid until the Customer stops using the Product or until Mageplaza terminates this License because of Customer’s failure to comply with any of its Terms and Conditions. Each License Certificate includes a license serial which is valid for one live Magento installation only and unlimited test Magento installations.
14+
15+
3. You are allowed to customize our products to fit with your using purpose.
16+
17+
4. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS
18+
19+
5. Installation and Use
20+
21+
6. For each new Software installation, you are obliged to purchase a separate License. You are not permitted to use any part of the code in whole or part in any other software or product or website. You are legally bound to preserve the copyright information intact including the text/link at bottom.
22+
23+
2. Distribution: You are not allowed to distribute Mageplaza software to third parties. Any distribution without our permission, including non commercial distribution is considered as violation of this Agreement and entails liability, according to the current law. You may not place the Software onto a server that allows access to the Software via a public network or the Internet for distribution purposes.
24+
25+
3. Rental: You may not give, sell, sub-license, rent, lease or lend any portion of the Software to anyone.
26+
27+
4. Compliance with Applicable Laws: You must comply with all applicable laws regarding use of software products. Mageplaza software and a portion of it are protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. Accordingly, customer is required to treat the software like any other copyrighted material. Any activity violating copyright law will be prosecuted according to the current law. We retain the right to revoke the license of any user holding an invalid license.
28+
29+
5. TERMINATION: Without prejudice to any other rights, Mageplaza may terminate this License at any time if you fail to comply with the terms and conditions of this License. In such event, it constitutes a breach of the agreement, and your license to use the program is revoked and you must destroy all copies of Mageplaza products in your possession. After being notified of termination of your license, if you continue to use Mageplaza software, you hereby agree to accept an injunction to prevent you from its further use and to pay all costs (including but not limited to reasonable attorney fees) to enforce our revocation of your license and any damages suffered by us because of your misuse of the Software. We are not bound to return you the amount spent for purchase of the Software for the termination of this License.
30+
31+
6. LIMITATION OF LIABILITY: In no event shall Mageplaza be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of ‘Authorized Users’ use of or inability to use the Mageplaza products, even if Mageplaza has been advised of the possibility of such damages. In no event will Mageplaza be liable for prosecution arising from use of the Software against law or for any illegal use.
32+
33+
The latest License: https://www.mageplaza.com/LICENSE.txt

Model/Resolver/FilterArgument.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_ProductLabelsGraphQl
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Mageplaza\ProductLabelsGraphQl\Model\Resolver;
25+
26+
use Magento\Framework\GraphQl\Config\Element\Field;
27+
use Magento\Framework\GraphQl\ConfigInterface;
28+
use Magento\Framework\GraphQl\Query\Resolver\Argument\FieldEntityAttributesInterface;
29+
30+
/**
31+
* Class FilterArgument
32+
* @package Mageplaza\ProductLabelsGraphQl\Model\Resolver
33+
*/
34+
class FilterArgument implements FieldEntityAttributesInterface
35+
{
36+
/**
37+
* @var ConfigInterface
38+
*/
39+
private $config;
40+
41+
/**
42+
* FilterArgument constructor.
43+
*
44+
* @param ConfigInterface $config
45+
*/
46+
public function __construct(ConfigInterface $config)
47+
{
48+
$this->config = $config;
49+
}
50+
51+
/**
52+
* @return array
53+
*/
54+
public function getEntityAttributes(): array
55+
{
56+
$fields = [];
57+
/** @var Field $field */
58+
foreach ($this->config->getConfigElement('LabelRules')->getFields() as $field) {
59+
$fields[$field->getName()] = '';
60+
}
61+
62+
return array_keys($fields);
63+
}
64+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_ProductLabelsGraphQl
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Mageplaza\ProductLabelsGraphQl\Model\Resolver;
25+
26+
use Magento\Catalog\Api\Data\ProductInterface;
27+
use Magento\Framework\Exception\LocalizedException;
28+
use Magento\Framework\GraphQl\Config\Element\Field;
29+
use Magento\Framework\GraphQl\Query\ResolverInterface;
30+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
31+
use Mageplaza\ProductLabels\Block\Label;
32+
use Mageplaza\ProductLabels\Helper\Data;
33+
use Mageplaza\ProductLabels\Model\LabelRepository;
34+
use Mageplaza\ProductLabels\Model\Rule;
35+
36+
/**
37+
* Class LabelDataProvider
38+
* @package Mageplaza\ProductLabelsGraphQl\Model\Resolver
39+
*/
40+
class LabelDataProvider implements ResolverInterface
41+
{
42+
/**
43+
* @var LabelRepository
44+
*/
45+
protected $labelRepository;
46+
47+
/**
48+
* @var Label
49+
*/
50+
protected $label;
51+
52+
/**
53+
* @var Data
54+
*/
55+
protected $helperData;
56+
57+
/**
58+
* LabelDataProvider constructor.
59+
*
60+
* @param LabelRepository $labelRepository
61+
* @param Label $label
62+
* @param Data $helperData
63+
*/
64+
public function __construct(
65+
LabelRepository $labelRepository,
66+
Label $label,
67+
Data $helperData
68+
) {
69+
$this->labelRepository = $labelRepository;
70+
$this->label = $label;
71+
$this->helperData = $helperData;
72+
}
73+
74+
/**
75+
* @inheritdoc
76+
*/
77+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
78+
{
79+
if (!$this->helperData->isEnabled()) {
80+
return [];
81+
}
82+
83+
if (!array_key_exists('model', $value) || !$value['model'] instanceof ProductInterface) {
84+
throw new LocalizedException(__('"model" value should be specified'));
85+
}
86+
87+
/* @var $product ProductInterface */
88+
$product = $value['model'];
89+
$labelData = [];
90+
91+
/** @var Rule $rule */
92+
foreach ($this->label->getRulesApplyProduct($product) as $rule) {
93+
if ($this->label->validateProductInRule($rule, $product->getId())) {
94+
$labelData[] = $this->labelRepository->getById($rule->getId());
95+
}
96+
}
97+
98+
return $labelData;
99+
}
100+
}

Model/Resolver/LabelRules.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_ProductLabelsGraphQl
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace Mageplaza\ProductLabelsGraphQl\Model\Resolver;
25+
26+
use Magento\Framework\GraphQl\Config\Element\Field;
27+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
28+
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder as SearchCriteriaBuilder;
29+
use Magento\Framework\GraphQl\Query\ResolverInterface;
30+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
31+
use Mageplaza\ProductLabels\Api\LabelRepositoryInterface;
32+
use Mageplaza\ProductLabels\Helper\Data;
33+
34+
/**
35+
* Class LabelRules
36+
* @package Mageplaza\ProductLabelsGraphQl\Model\Resolver
37+
*/
38+
class LabelRules implements ResolverInterface
39+
{
40+
/**
41+
* @var Data
42+
*/
43+
protected $helperData;
44+
45+
/**
46+
* @var SearchCriteriaBuilder
47+
*/
48+
private $searchCriteriaBuilder;
49+
50+
/**
51+
* @var LabelRepositoryInterface
52+
*/
53+
protected $labelRuleRepository;
54+
55+
/**
56+
* LabelRules constructor.
57+
*
58+
* @param Data $helperData
59+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
60+
* @param LabelRepositoryInterface $labelRuleRepository
61+
*/
62+
public function __construct(
63+
Data $helperData,
64+
SearchCriteriaBuilder $searchCriteriaBuilder,
65+
LabelRepositoryInterface $labelRuleRepository
66+
) {
67+
$this->helperData = $helperData;
68+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
69+
$this->labelRuleRepository = $labelRuleRepository;
70+
}
71+
72+
/**
73+
* @inheritdoc
74+
*/
75+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
76+
{
77+
if (!$this->helperData->isEnabled()) {
78+
return [];
79+
}
80+
81+
$this->vailidateArgs($args);
82+
$searchCriteria = $this->searchCriteriaBuilder->build('label_rules', $args);
83+
$searchCriteria->setCurrentPage($args['currentPage']);
84+
$searchCriteria->setPageSize($args['pageSize']);
85+
$searchResult = $this->labelRuleRepository->getList($searchCriteria);
86+
87+
return [
88+
'total_count' => $searchResult->getTotalCount(),
89+
'items' => $searchResult->getItems(),
90+
];
91+
}
92+
93+
/**
94+
* @param array $args
95+
*
96+
* @throws GraphQlInputException
97+
*/
98+
private function vailidateArgs(array $args): void
99+
{
100+
if (isset($args['currentPage']) && $args['currentPage'] < 1) {
101+
throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
102+
}
103+
104+
if (isset($args['pageSize']) && $args['pageSize'] < 1) {
105+
throw new GraphQlInputException(__('pageSize value must be greater than 0.'));
106+
}
107+
}
108+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ To start working with GraphQl in Magento, you need the following:
1515
- Use Magento 2.3.x. Returns site to developer mode
1616
- Install [chrome extension](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=en) (currently does not support other browsers)
1717
- Set **GraphQL endpoint** as `http://<magento2-3-server>/graphql` in url box, click **Set endpoint**. (e.g. http://develop.mageplaza.com/graphql/ce232/graphql)
18-
- Mageplaza-supported queries are fully written in the **Description** section of `Query.productlabels.Products`
18+
- Mageplaza-supported queries are fully written in the **Description** section of `Query.LabelRules.Products`
1919

2020
![](https://i.imgur.com/8OW0Y2G.png)

USER-GUIDE.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Documentation
2+
3+
- Installation guide: https://www.mageplaza.com/install-magento-2-extension/#solution-1-ready-to-paste
4+
- User Guide: https://docs.mageplaza.com/product-labels/
5+
- Product page: https://www.mageplaza.com/magento-2-product-labels/
6+
- FAQs: https://www.mageplaza.com/faqs/
7+
- Get Support: https://mageplaza.freshdesk.com/ or support@mageplaza.com
8+
- Changelog: https://www.mageplaza.com/releases/product-labels/
9+
- License agreement: https://www.mageplaza.com/LICENSE.txt
10+
11+
## How to install
12+
13+
### Install ready-to-paste package (Recommended)
14+
15+
- Installation guide: https://www.mageplaza.com/install-magento-2-extension/
16+
17+
## How to upgrade
18+
19+
1. Backup
20+
21+
Backup your Magento code, database before upgrading.
22+
23+
2. Remove ProductLabelsGraphQl folder
24+
25+
In case of customization, you should backup the customized files and modify in newer version.
26+
Now you remove `app/code/Mageplaza/ProductLabelsGraphQl` folder. In this step, you can copy override ProductLabelsGraphQl folder but this may cause of compilation issue. That why you should remove it.
27+
28+
3. Upload new version
29+
Upload this package to Magento root directory
30+
31+
4. Run command line:
32+
33+
```
34+
php bin/magento setup:upgrade
35+
php bin/magento setup:static-content:deploy
36+
```
37+
38+
39+
## FAQs
40+
41+
42+
#### Q: I got error: `Mageplaza_Core has been already defined`
43+
A: Read solution: https://github.com/mageplaza/module-core/issues/3
44+
45+
46+
#### Q: My site is down
47+
A: Please follow this guide: https://www.mageplaza.com/blog/magento-site-down.html
48+
49+
50+
## Support
51+
52+
- FAQs: https://www.mageplaza.com/faqs/
53+
- https://mageplaza.freshdesk.com/
54+
- support@mageplaza.com

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "mageplaza/module-product-labels-graphql",
3+
"description": "Mageplaza Magento 2 Product Labels GraphQl",
4+
"type": "magento2-module",
5+
"version": "1.0.0",
6+
"license": "proprietary",
7+
"authors": [
8+
{
9+
"name": "Mageplaza",
10+
"email": "support@mageplaza.com",
11+
"homepage": "https://www.mageplaza.com",
12+
"role": "Technical Support"
13+
}
14+
],
15+
"autoload": {
16+
"files": [
17+
"registration.php"
18+
],
19+
"psr-4": {
20+
"Mageplaza\\ProductLabelsGraphQl\\": ""
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)