Skip to content

Commit 82cdf42

Browse files
author
msgchinh
committed
update graphql
1 parent 378e693 commit 82cdf42

24 files changed

+840
-125
lines changed

Model/Resolver/Categories.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
222
declare(strict_types=1);
323

424
namespace Lof\FaqGraphQl\Model\Resolver;

Model/Resolver/CategoryImageResolver.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
222
namespace Lof\FaqGraphQl\Model\Resolver;
323

424
use Magento\Framework\Exception\LocalizedException;

Model/Resolver/CategoryQuestionResolver.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
222
namespace Lof\FaqGraphQl\Model\Resolver;
323

424
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;

Model/Resolver/DataProvider/FaqCategory.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver\DataProvider;
523

Model/Resolver/DataProvider/FaqQuestion.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver\DataProvider;
523

Model/Resolver/DataProvider/FaqTag.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver\DataProvider;
523

Model/Resolver/FaqCategory.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver;
523

Model/Resolver/FaqCreateQuestion.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
22+
namespace Lof\FaqGraphQl\Model\Resolver;
23+
24+
use Magento\Framework\DataObject;
25+
use Magento\Framework\GraphQl\Config\Element\Field;
26+
use Magento\Framework\GraphQl\Query\ResolverInterface;
27+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
28+
29+
class FaqCreateQuestion implements ResolverInterface
30+
{
31+
32+
/**
33+
* @var \Magento\Framework\View\LayoutInterface
34+
*/
35+
private $_layout;
36+
/**
37+
* @var \Magento\Store\Model\StoreManager
38+
*/
39+
private $_storeManager;
40+
/**
41+
* @var \Lof\Faq\Model\QuestionFactory
42+
*/
43+
private $questionFactory;
44+
/**
45+
* @var \Magento\Framework\Translate\Inline\StateInterface
46+
*/
47+
private $inlineTranslation;
48+
/**
49+
* @var \Lof\Faq\Helper\Data
50+
*/
51+
private $_faqHelper;
52+
/**
53+
* @var \Magento\Framework\Mail\Template\TransportBuilder
54+
*/
55+
private $_transportBuilder;
56+
57+
public function __construct(
58+
\Magento\Framework\View\LayoutInterface $layout,
59+
\Magento\Store\Model\StoreManager $storeManager,
60+
\Lof\Faq\Model\QuestionFactory $questionFactory,
61+
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
62+
\Lof\Faq\Helper\Data $faqHelper,
63+
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
64+
) {
65+
$this->_layout = $layout;
66+
$this->_storeManager = $storeManager;
67+
$this->questionFactory = $questionFactory;
68+
$this->inlineTranslation = $inlineTranslation;
69+
$this->_faqHelper = $faqHelper;
70+
$this->_transportBuilder = $transportBuilder;
71+
}
72+
73+
/**
74+
* @inheritdoc
75+
*/
76+
public function resolve(
77+
Field $field,
78+
$context,
79+
ResolveInfo $info,
80+
array $value = null,
81+
array $args = null
82+
) {
83+
$data = $args;
84+
$custom_form_data = [
85+
[
86+
'label' => 'Name',
87+
'value' => $data['author_name']
88+
],
89+
[
90+
'label' => 'Email',
91+
'value' => $data['author_email']
92+
],
93+
[
94+
'label' => 'Message',
95+
'value' => $data['title']
96+
]
97+
];
98+
99+
$store = $this->_storeManager->getStore();
100+
$data['is_active'] = 0;
101+
$data['stores'] = [$store->getId()];
102+
$data['question_products'][$data['product_id']] = ['position' => 0];
103+
$model = $this->questionFactory->create();
104+
$model->setData($data);
105+
try {
106+
$model->save();
107+
$res = [
108+
'code' => 0,
109+
'message' => __('Your question has submitted successfully, we will answer that as soon as possible. Thanks you!')
110+
];
111+
} catch (\Exception $e) {
112+
$res = [
113+
'code' => 0,
114+
'message' => $e->getMessage()
115+
];
116+
}
117+
$this->inlineTranslation->suspend();
118+
$enable_testmode = $this->_faqHelper->getConfig('email_settings/enable_testmode');
119+
if (!$enable_testmode && $this->_faqHelper->getConfig('email_settings/email_receive') != '') {
120+
// $data['message'] = $this->_layout->createBlock(\Magento\Framework\View\Element\Template::class)
121+
// ->setTemplate("Lof_Faq::email/items.phtml")
122+
// ->setCustomFormData($custom_form_data)
123+
// ->toHtml();
124+
$emails = $this->_faqHelper->getConfig('email_settings/email_receive');
125+
$emails = explode(',', $emails);
126+
foreach ($emails as $v) {
127+
try {
128+
$postObject = new DataObject();
129+
$data['title'] = __('Send Faq');
130+
$postObject->setData($data);
131+
$transport = $this->_transportBuilder
132+
->setTemplateIdentifier($this->_faqHelper->getConfig('email_settings/email_template'))
133+
->setTemplateOptions(
134+
[
135+
'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
136+
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
137+
]
138+
)
139+
->setTemplateVars(['data' => $postObject])
140+
->setFrom($this->_faqHelper->getConfig('email_settings/sender_email_identity'))
141+
->addTo($v)
142+
->setReplyTo($v)
143+
->getTransport();
144+
$transport->sendMessage();
145+
$this->inlineTranslation->resume();
146+
} catch (\Exception $e) {
147+
$this->inlineTranslation->resume();
148+
}
149+
}
150+
}
151+
return $res;
152+
}
153+
}

Model/Resolver/FaqQuestion.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
<?php
2-
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
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 Landofcoder
17+
* @package Lof_GraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
321

422
namespace Lof\FaqGraphQl\Model\Resolver;
523

Model/Resolver/FaqSubmitQuestion.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)