Skip to content

Commit 31aef0b

Browse files
committed
GraphQl
1 parent c6ba0b1 commit 31aef0b

File tree

10 files changed

+400
-2
lines changed

10 files changed

+400
-2
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/custom-stock-status/

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
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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_StockStatusGraphQl
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\StockStatusGraphQl\Model\Resolver\Product;
25+
26+
use Magento\Catalog\Model\Product;
27+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
28+
use Magento\Framework\Exception\LocalizedException;
29+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
30+
use Magento\Framework\GraphQl\Config\Element\Field;
31+
use Magento\Framework\GraphQl\Query\ResolverInterface;
32+
use Mageplaza\StockStatus\Helper\Data;
33+
use Mageplaza\StockStatus\Model\Config\Source\StatusFormat;
34+
35+
/**
36+
* Class StockStatus
37+
* @package Mageplaza\StockStatusGraphQl\Model\Resolver\Product
38+
*/
39+
class StockStatus implements ResolverInterface
40+
{
41+
42+
/**
43+
* @var Data
44+
*/
45+
protected $helperData;
46+
47+
/**
48+
* QuoteRepository constructor.
49+
* @param Data $helperData
50+
*/
51+
public function __construct(Data $helperData)
52+
{
53+
$this->helperData = $helperData;
54+
}
55+
56+
/**
57+
* @inheritdoc
58+
*/
59+
public function resolve(
60+
Field $field,
61+
$context,
62+
ResolveInfo $info,
63+
array $value = null,
64+
array $args = null
65+
): array {
66+
67+
if (!$this->helperData->isEnabled()) {
68+
return [];
69+
}
70+
71+
if (!isset($value['model'])) {
72+
throw new LocalizedException(__('"model" value should be specified'));
73+
}
74+
75+
$result = [];
76+
77+
/** @var Product $product */
78+
$product = $this->helperData->getProductData($value['model']);
79+
80+
$stockStatus = $this->helperData->getStatus($product, false);
81+
if ($product->getTypeId() === Configurable::TYPE_CODE) {
82+
$result['is_apply_child'] = $this->helperData->isDisplayChildProduct();
83+
}
84+
85+
$format = (int)$this->helperData->getStatusFormat();
86+
$status = [StatusFormat::LABEL_IMAGE, StatusFormat::IMAGE_LABEL];
87+
if ($stockStatus['image'] && in_array($format, array_merge($status, [StatusFormat::ONLY_IMAGE]), true)) {
88+
$result['image'] = $stockStatus['image'];
89+
}
90+
91+
if ($stockStatus['label'] && in_array($format, array_merge($status, [StatusFormat::ONLY_LABEL]), true)) {
92+
$result['label'] = $stockStatus['label'];
93+
}
94+
95+
return $result;
96+
}
97+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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_StockStatusGraphQl
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\StockStatusGraphQl\Model\Resolver\QuoteItem;
25+
26+
use Magento\Framework\Exception\LocalizedException;
27+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
28+
use Magento\Framework\GraphQl\Config\Element\Field;
29+
use Magento\Framework\GraphQl\Query\ResolverInterface;
30+
use Mageplaza\StockStatus\Helper\Data;
31+
use Mageplaza\StockStatus\Model\Config\Source\PageType;
32+
use Mageplaza\StockStatus\Model\Config\Source\StatusFormat;
33+
use Magento\Quote\Model\Quote\Item as QuoteItem;
34+
35+
/**
36+
* Class StockStatus
37+
* @package Mageplaza\StockStatusGraphQl\Model\Resolver\QuoteItem
38+
*/
39+
class StockStatus implements ResolverInterface
40+
{
41+
/**
42+
* @var Data
43+
*/
44+
protected $helperData;
45+
46+
/**
47+
* StockStatus constructor.
48+
* @param Data $helperData
49+
*/
50+
public function __construct(Data $helperData)
51+
{
52+
$this->helperData = $helperData;
53+
}
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
public function resolve(
59+
Field $field,
60+
$context,
61+
ResolveInfo $info,
62+
array $value = null,
63+
array $args = null
64+
) {
65+
if (!$this->helperData->isEnabled()) {
66+
return [];
67+
}
68+
69+
if (!isset($value['model'])) {
70+
throw new LocalizedException(__('"model" value should be specified'));
71+
}
72+
73+
/** @var QuoteItem $quoteItem */
74+
$quoteItem = $value['model'];
75+
76+
$status = [StatusFormat::LABEL_IMAGE, StatusFormat::IMAGE_LABEL];
77+
$imageAvailable = array_merge($status, [StatusFormat::ONLY_IMAGE]);
78+
$textAvailable = array_merge($status, [StatusFormat::ONLY_LABEL]);
79+
$format = (int)$this->helperData->getStatusFormat();
80+
81+
$product = $this->helperData->getProductData($quoteItem->getProduct());
82+
$isDisplay = $this->helperData->isDisplayStatus(
83+
$product->isAvailable(),
84+
PageType::SHOPPING_CART
85+
);
86+
$result = [];
87+
if ($isDisplay) {
88+
$stockStatus = $this->helperData->getStatus($product, false);
89+
90+
if ($stockStatus['image'] && in_array($format, $imageAvailable, true)) {
91+
$result['image'] = $stockStatus['image'];
92+
}
93+
94+
if ($stockStatus['label'] && in_array($format, $textAvailable, true)) {
95+
$result['label'] = $stockStatus['label'];
96+
}
97+
}
98+
99+
return $result;
100+
}
101+
}

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
# Custom Stock Status GraphQl
2-
1+
# Stock Status GraphQL
2+
Mageplaza Stock Status Extension supports getting and pushing data on the website with GraphQl.
3+
4+
## How to install
5+
Run the following command in Magento 2 root folder:
6+
7+
```
8+
composer require mageplaza/module-custom-stock-status-graphql
9+
php bin/magento setup:upgrade
10+
php bin/magento setup:static-content:deploy
11+
```
12+
````

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/custom-stock-status/
5+
- Product page: https://www.mageplaza.com/magento-2-custom-stock-status/
6+
- FAQs: https://www.mageplaza.com/faqs/
7+
- Get Support: https://www.mageplaza.com/contact.html or support@mageplaza.com
8+
- Changelog: https://www.mageplaza.com/releases/custom-stock-status/
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 StockStatus 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/StockStatus` folder. In this step, you can copy override StockStatus 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://www.mageplaza.com/contact.html
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-custom-stock-status-graphql",
3+
"description": "Magento 2 Custom Stock Status GraphQl Extension",
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\\StockStatusGraphQl\\": ""
21+
}
22+
}
23+
}

etc/module.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Mageplaza
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Mageplaza.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.mageplaza.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category Mageplaza
18+
* @package Mageplaza_StockStatusGraphQl
19+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
20+
* @license https://www.mageplaza.com/LICENSE.txt
21+
*/
22+
-->
23+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
24+
<module name="Mageplaza_StockStatusGraphQl" setup_version="1.0.0">
25+
<sequence>
26+
<module name="Mageplaza_Core"/>
27+
<module name="Mageplaza_StockStatus"/>
28+
</sequence>
29+
</module>
30+
</config>

etc/schema.graphqls

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
interface CartItemInterface {
3+
mp_stock_status: MpStockStatusCartItem @resolver(class: "Mageplaza\\StockStatusGraphQl\\Model\\Resolver\\QuoteItem\\StockStatus") @doc(description: "Stock status apply cart")
4+
}
5+
6+
interface ProductInterface {
7+
mp_stock_status : MpStockStatus @resolver(class: "Mageplaza\\StockStatusGraphQl\\Model\\Resolver\\Product\\StockStatus") @doc(description: "Stock status attributes")
8+
}
9+
10+
type MpStockStatus {
11+
label: String @doc(description: "Stock status label")
12+
image: String @doc(description: "Stock status image")
13+
is_apply_child: Boolean @doc(description: "Is Apply Child")
14+
15+
}
16+
17+
type MpStockStatusCartItem {
18+
label: String @doc(description: "Stock status label")
19+
image: String @doc(description: "Stock status image")
20+
21+
}

0 commit comments

Comments
 (0)