-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1 from mageplaza/develop
Develop
- Loading branch information
Showing
14 changed files
with
587 additions
and
2 deletions.
There are no files selected for viewing
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 @@ | ||
CHANGELOG: https://www.mageplaza.com/releases/sales-pop/ |
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,33 @@ | ||
Copyright © 2016-present Mageplaza Co. Ltd. | ||
|
||
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. | ||
|
||
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. | ||
|
||
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. | ||
|
||
1. GRANT OF LICENSE: By purchasing a product of Mageplaza: | ||
|
||
1. Customer will receive source code open 100%. | ||
|
||
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. | ||
|
||
3. You are allowed to customize our products to fit with your using purpose. | ||
|
||
4. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS | ||
|
||
5. Installation and Use | ||
|
||
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. | ||
|
||
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. | ||
|
||
3. Rental: You may not give, sell, sub-license, rent, lease or lend any portion of the Software to anyone. | ||
|
||
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. | ||
|
||
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. | ||
|
||
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. | ||
|
||
The latest License: https://www.mageplaza.com/LICENSE.txt |
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,127 @@ | ||
<?php | ||
/** | ||
* Mageplaza | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Mageplaza.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://www.mageplaza.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Mageplaza | ||
* @package Mageplaza_SalesPopGraphQl | ||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | ||
* @license https://www.mageplaza.com/LICENSE.txt | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\SalesPopGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder as SearchCriteriaBuilder; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Mageplaza\SalesPop\Helper\Data; | ||
use Mageplaza\SalesPopGraphQl\Model\Resolver\SalesPop\DataProvider; | ||
|
||
/** | ||
* Class SalesPop | ||
* @package Mageplaza\SalesPopGraphQl\Model\Resolver | ||
*/ | ||
class SalesPop implements ResolverInterface | ||
{ | ||
/** | ||
* @var DataProvider | ||
*/ | ||
protected $dataProvider; | ||
|
||
/** | ||
* @var Data | ||
*/ | ||
protected $helperData; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
protected $searchCriteriaBuilder; | ||
|
||
/** | ||
* SalesPop constructor. | ||
* | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @param DataProvider $dataProvider | ||
* @param Data $helperData | ||
*/ | ||
public function __construct( | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
DataProvider $dataProvider, | ||
Data $helperData | ||
) { | ||
$this->dataProvider = $dataProvider; | ||
$this->helperData = $helperData; | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!$this->helperData->isEnabled()) { | ||
throw new GraphQlInputException(__('The module is disabled')); | ||
} | ||
|
||
if ($args['currentPage'] < 1) { | ||
throw new GraphQlInputException(__('currentPage value must be greater than 0.')); | ||
} | ||
if ($args['pageSize'] < 1) { | ||
throw new GraphQlInputException(__('pageSize value must be greater than 0.')); | ||
} | ||
if (!isset($args['filter'])) { | ||
throw new GraphQlInputException(__("'filter' input argument is required.")); | ||
} | ||
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args); | ||
$searchCriteria->setCurrentPage($args['currentPage']); | ||
$searchCriteria->setPageSize($args['pageSize']); | ||
$collection = $this->dataProvider->getData($searchCriteria); | ||
$collectionSize = $collection->getSize(); | ||
//possible division by 0 | ||
$pageSize = $collection->getPageSize(); | ||
if ($pageSize) { | ||
$maxPages = ceil($collectionSize / $searchCriteria->getPageSize()); | ||
} else { | ||
$maxPages = 0; | ||
} | ||
|
||
$currentPage = $collection->getCurPage(); | ||
if ($collectionSize > 0 && $searchCriteria->getCurrentPage() > $maxPages) { | ||
throw new GraphQlInputException( | ||
__( | ||
'currentPage value %1 specified is greater than the %2 page(s) available.', | ||
[$currentPage, $maxPages] | ||
) | ||
); | ||
} | ||
|
||
return [ | ||
'total_count' => $collection->getSize(), | ||
'items' => $collection->getItems(), | ||
'page_info' => [ | ||
'page_size' => $pageSize, | ||
'current_page' => $currentPage, | ||
'total_pages' => $maxPages | ||
] | ||
]; | ||
} | ||
} |
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,73 @@ | ||
<?php | ||
/** | ||
* Mageplaza | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Mageplaza.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://www.mageplaza.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Mageplaza | ||
* @package Mageplaza_SalesPopGraphQl | ||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | ||
* @license https://www.mageplaza.com/LICENSE.txt | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\SalesPopGraphQl\Model\Resolver\SalesPop; | ||
|
||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; | ||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
use Mageplaza\SalesPop\Model\ResourceModel\SalesPop\Collection; | ||
use Mageplaza\SalesPop\Model\ResourceModel\SalesPop\CollectionFactory; | ||
|
||
/** | ||
* Class DataProvider | ||
* @package Mageplaza\SalesPopGraphQl\Model\Resolver\SalesPop | ||
*/ | ||
class DataProvider | ||
{ | ||
/** | ||
* @var CollectionProcessorInterface | ||
*/ | ||
protected $collectionProcessor; | ||
|
||
/** | ||
* @var CollectionFactory | ||
*/ | ||
protected $collectionFactory; | ||
|
||
/** | ||
* DataProvider constructor. | ||
* | ||
* @param CollectionProcessorInterface $collectionProcessor | ||
* @param CollectionFactory $collectionFactory | ||
*/ | ||
public function __construct( | ||
CollectionProcessorInterface $collectionProcessor, | ||
CollectionFactory $collectionFactory | ||
) { | ||
$this->collectionProcessor = $collectionProcessor; | ||
$this->collectionFactory = $collectionFactory; | ||
} | ||
|
||
/** | ||
* @param SearchCriteriaInterface $searchCriteria | ||
* | ||
* @return Collection | ||
*/ | ||
public function getData( | ||
SearchCriteriaInterface $searchCriteria | ||
): Collection { | ||
$collection = $this->collectionFactory->create(); | ||
$this->collectionProcessor->process($searchCriteria, $collection); | ||
|
||
return $collection; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Model/Resolver/SalesPop/FilterArgument/EntityAttributesForAst.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,60 @@ | ||
<?php | ||
/** | ||
* Mageplaza | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Mageplaza.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://www.mageplaza.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Mageplaza | ||
* @package Mageplaza_SalesPopGraphQl | ||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | ||
* @license https://www.mageplaza.com/LICENSE.txt | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\SalesPopGraphQl\Model\Resolver\SalesPop\FilterArgument; | ||
|
||
use Magento\Framework\GraphQl\Query\Resolver\Argument\FieldEntityAttributesInterface; | ||
|
||
/** | ||
* Class EntityAttributesForAst | ||
* @package Mageplaza\SalesPopGraphQl\Model\Resolver\SalesPop\FilterArgument | ||
*/ | ||
class EntityAttributesForAst implements FieldEntityAttributesInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $additionalAttributes = ['pop_id', 'name', 'status', 'pop_type', 'position']; | ||
|
||
/** | ||
* EntityAttributesForAst constructor. | ||
* | ||
* @param array $additionalAttributes | ||
*/ | ||
public function __construct(array $additionalAttributes = []) | ||
{ | ||
$this->additionalAttributes = array_merge($this->additionalAttributes, $additionalAttributes); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getEntityAttributes(): array | ||
{ | ||
$fields = []; | ||
foreach ($this->additionalAttributes as $attribute) { | ||
$fields[$attribute] = 'String'; | ||
} | ||
|
||
return array_keys($fields); | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
/** | ||
* Mageplaza | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Mageplaza.com license that is | ||
* available through the world-wide-web at this URL: | ||
* https://www.mageplaza.com/LICENSE.txt | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade this extension to newer | ||
* version in the future. | ||
* | ||
* @category Mageplaza | ||
* @package Mageplaza_SalesPopGraphQl | ||
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | ||
* @license https://www.mageplaza.com/LICENSE.txt | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Mageplaza\SalesPopGraphQl\Model\Resolver\SalesPop; | ||
|
||
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface; | ||
|
||
/** | ||
* Class Identity | ||
* @package Mageplaza\SalesPopGraphQl\Model\Resolver\SalesPop | ||
*/ | ||
class Identity implements IdentityInterface | ||
{ | ||
/** @var string */ | ||
private $cacheTag = 'salespop_'; | ||
|
||
/** | ||
* Get page ID from resolved data | ||
* | ||
* @param array $resolvedData | ||
* | ||
* @return string[] | ||
*/ | ||
public function getIdentities(array $resolvedData): array | ||
{ | ||
return empty($resolvedData['pop_id']) ? | ||
[] : [$this->cacheTag, sprintf('%s_%s', $this->cacheTag, $resolvedData['pop_id'])]; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,20 @@ | ||
# Sales Pop GraphQl | ||
|
||
# Sales Pop GraphQl | ||
|
||
## How to install | ||
Run the following command in Magento 2 root folder: | ||
|
||
``` | ||
composer require mageplaza/module-sales-pop-graphql | ||
php bin/magento setup:upgrade | ||
php bin/magento setup:static-content:deploy | ||
``` | ||
|
||
## How to use | ||
|
||
To start working with Sales Pop GraphQl in Magento, you need the following: | ||
- Use Magento 2.3.x. Returns site to developer mode | ||
- Install [chrome extension](https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=en) (currently does not support other browsers) | ||
- Set **GraphQL endpoint** as `http://<magento2-3-server>/graphql` in url box, click **Set endpoint**. (e.g. http://develop.mageplaza.com/graphql/ce232/graphql) | ||
- Mageplaza-supported queries are fully written in the **Description** section of `Query.LabelRules.Products` | ||
|
||
![](https://i.imgur.com/8OW0Y2G.png) |
Oops, something went wrong.