mageprince /
magento2-FAQ
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * MagePrince |
||||
| 4 | * |
||||
| 5 | * NOTICE OF LICENSE |
||||
| 6 | * |
||||
| 7 | * This source file is subject to the mageprince.com license that is |
||||
| 8 | * available through the world-wide-web at this URL: |
||||
| 9 | * https://mageprince.com/end-user-license-agreement |
||||
| 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 MagePrince |
||||
| 17 | * @package Mageprince_Faq |
||||
| 18 | * @copyright Copyright (c) MagePrince (https://mageprince.com/) |
||||
| 19 | * @license https://mageprince.com/end-user-license-agreement |
||||
| 20 | */ |
||||
| 21 | |||||
| 22 | namespace Mageprince\Faq\Controller\Adminhtml\FaqGroup; |
||||
| 23 | |||||
| 24 | use Magento\Backend\App\Action; |
||||
|
0 ignored issues
–
show
|
|||||
| 25 | use Magento\Backend\Model\View\Result\Redirect; |
||||
|
0 ignored issues
–
show
The type
Magento\Backend\Model\View\Result\Redirect was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 26 | use Magento\Framework\App\Request\DataPersistorInterface; |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\App\Re...\DataPersistorInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 27 | use Magento\Framework\Controller\ResultInterface; |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\Controller\ResultInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 28 | use Magento\Framework\Exception\LocalizedException; |
||||
|
0 ignored issues
–
show
The type
Magento\Framework\Exception\LocalizedException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 29 | use Mageprince\Faq\Model\FaqGroupFactory; |
||||
|
0 ignored issues
–
show
The type
Mageprince\Faq\Model\FaqGroupFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 30 | use Mageprince\Faq\Model\FaqGroupRepository; |
||||
| 31 | use Mageprince\Faq\Model\ImageUploader; |
||||
| 32 | |||||
| 33 | class Save extends FaqGroup |
||||
| 34 | { |
||||
| 35 | /** |
||||
| 36 | * @var DataPersistorInterface |
||||
| 37 | */ |
||||
| 38 | protected $dataPersistor; |
||||
| 39 | |||||
| 40 | /** |
||||
| 41 | * @var ImageUploader |
||||
| 42 | */ |
||||
| 43 | protected $imageUploader; |
||||
| 44 | |||||
| 45 | /** |
||||
| 46 | * @var FaqGroupRepository |
||||
| 47 | */ |
||||
| 48 | protected $faqGroupRepository; |
||||
| 49 | |||||
| 50 | /** |
||||
| 51 | * @var FaqGroupFactory |
||||
| 52 | */ |
||||
| 53 | protected $faqGroupFactory; |
||||
| 54 | |||||
| 55 | /** |
||||
| 56 | * Save constructor. |
||||
| 57 | * @param Action\Context $context |
||||
| 58 | * @param FaqGroupFactory $faqGroupFactory |
||||
| 59 | * @param DataPersistorInterface $dataPersistor |
||||
| 60 | * @param ImageUploader $imageUploader |
||||
| 61 | * @param FaqGroupRepository $faqGroupRepository |
||||
| 62 | */ |
||||
| 63 | public function __construct( |
||||
| 64 | Action\Context $context, |
||||
|
0 ignored issues
–
show
The type
Magento\Backend\App\Action\Context was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 65 | FaqGroupFactory $faqGroupFactory, |
||||
| 66 | DataPersistorInterface $dataPersistor, |
||||
| 67 | ImageUploader $imageUploader, |
||||
| 68 | FaqGroupRepository $faqGroupRepository |
||||
| 69 | ) { |
||||
| 70 | $this->dataPersistor = $dataPersistor; |
||||
| 71 | $this->faqGroupFactory = $faqGroupFactory; |
||||
| 72 | $this->imageUploader = $imageUploader; |
||||
| 73 | $this->faqGroupRepository = $faqGroupRepository; |
||||
| 74 | parent::__construct($context); |
||||
| 75 | } |
||||
| 76 | |||||
| 77 | /** |
||||
| 78 | * Save action |
||||
| 79 | * |
||||
| 80 | * @return ResultInterface |
||||
| 81 | */ |
||||
| 82 | public function execute() |
||||
| 83 | { |
||||
| 84 | /** @var Redirect $resultRedirect */ |
||||
| 85 | $resultRedirect = $this->resultRedirectFactory->create(); |
||||
| 86 | |||||
| 87 | if ($data = $this->getRequest()->getPostValue()) { |
||||
| 88 | $model = $this->faqGroupFactory->create(); |
||||
| 89 | try { |
||||
| 90 | if ($id = (int) $this->getRequest()->getParam('faqgroup_id')) { |
||||
| 91 | $model = $this->faqGroupRepository->getById($id); |
||||
| 92 | if ($id != $model->getId()) { |
||||
|
0 ignored issues
–
show
The method
getId() does not exist on Mageprince\Faq\Api\Data\FaqGroupInterface.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 93 | $this->messageManager->addErrorMessage(__('This FAQ Group no longer exists.')); |
||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 94 | return $resultRedirect->setPath('*/*/'); |
||||
| 95 | } |
||||
| 96 | } |
||||
| 97 | |||||
| 98 | $data = $this->_filterFaqGroupData($data); |
||||
| 99 | $model->addData($data); |
||||
| 100 | $this->faqGroupRepository->save($model); |
||||
| 101 | $this->messageManager->addSuccessMessage(__('You saved the FAQ Group.')); |
||||
| 102 | $this->dataPersistor->clear('prince_faq_faqgroup'); |
||||
| 103 | |||||
| 104 | if ($this->getRequest()->getParam('back')) { |
||||
| 105 | return $resultRedirect->setPath('*/*/edit', ['faqgroup_id' => $model->getId()]); |
||||
| 106 | } |
||||
| 107 | return $resultRedirect->setPath('*/*/'); |
||||
| 108 | } catch (LocalizedException $e) { |
||||
| 109 | $this->messageManager->addErrorMessage($e->getMessage()); |
||||
| 110 | } catch (\Exception $e) { |
||||
| 111 | $this->messageManager->addExceptionMessage( |
||||
| 112 | $e, |
||||
| 113 | __('Something went wrong while saving the Faqgroup.') |
||||
| 114 | ); |
||||
| 115 | } |
||||
| 116 | |||||
| 117 | $this->dataPersistor->set('prince_faq_faqgroup', $data); |
||||
| 118 | return $resultRedirect->setPath( |
||||
| 119 | '*/*/edit', |
||||
| 120 | [ |
||||
| 121 | 'faqgroup_id' => $this->getRequest()->getParam('faqgroup_id') |
||||
| 122 | ] |
||||
| 123 | ); |
||||
| 124 | } |
||||
| 125 | return $resultRedirect->setPath('*/*/'); |
||||
| 126 | } |
||||
| 127 | |||||
| 128 | /** |
||||
| 129 | * Filter faq group data |
||||
| 130 | * |
||||
| 131 | * @param array $rawData |
||||
| 132 | * @return array |
||||
| 133 | */ |
||||
| 134 | protected function _filterFaqGroupData(array $rawData) |
||||
| 135 | { |
||||
| 136 | $data = $rawData; |
||||
| 137 | if (isset($data['icon'][0]['name'])) { |
||||
| 138 | $data['icon'] = $data['icon'][0]['name']; |
||||
| 139 | } else { |
||||
| 140 | $data['icon'] = null; |
||||
| 141 | } |
||||
| 142 | |||||
| 143 | $cGroup = $data['customer_group']; |
||||
| 144 | if (isset($cGroup)) { |
||||
| 145 | $customerGroup = implode(',', $data['customer_group']); |
||||
| 146 | $data['customer_group'] = $customerGroup; |
||||
| 147 | } |
||||
| 148 | |||||
| 149 | $stores = $data['storeview']; |
||||
| 150 | if (isset($stores)) { |
||||
| 151 | $store = implode(',', $data['storeview']); |
||||
| 152 | $data['storeview'] = $store; |
||||
| 153 | } |
||||
| 154 | |||||
| 155 | return $data; |
||||
| 156 | } |
||||
| 157 | } |
||||
| 158 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths