Magento 2: ошибка ScopeConfig, когда я использую его в классе \ Magento \ Contact \ Controller \ Index \ Post - PullRequest
0 голосов
/ 06 июня 2018

Прежде всего, я расширял модуль для связи с нами, и я хотел проверить на бэкэнде, включен ли он или нет, используя ScopeConfig, но я столкнулся с этой проблемой.Я уже пытался удалить сгенерированные файлы и запустить команду установки обновления.

По моему предположению, мне не хватает чего-то в моих кодах

КОД:

<?php
namespace SCI\Form\Controller\Index;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Post extends \Magento\Contact\Controller\Index\Post
{
    protected $scopeConfig;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        ScopeConfigInterface $scopeConfig,
        array $data = []
    ){
        parent::__construct($context,$data);
        $this->_scopeConfig = $scopeConfig;
        $this->_storeManager = $storeManager;

    }

    public function ifEnabled(){
        return $this->_scopeConfig->getValue('extended_contact/config/extended_contact_enabled',ScopeInterface::SCOPE_STORE);
    }

    public function execute()
    {
        die($this->ifEnabled());

        return parent::execute();

    }
}

Примечание:Это работает, когда я изменил форму класса \ Magento \ Contact \ Controller \ Index \ Post на \ Magento \ Framework \ App \ Action \ Action

ОШИБКА:

Неустранимая ошибка: UncaughtОшибка типа: Аргумент 2, передаваемый в Magento \ Contact \ Controller \ Index \ Post :: __ construct () должен реализовывать интерфейс Magento \ Contact \ Model \ ConfigInterface, заданный массив, вызываемый в C: \ xampp \ htdocs \ training \ app \ code \ SCI\ Form \ Controller \ Index \ Post.php в строке 17 и определяется в C: \ xampp \ htdocs \ training \ vendor \ magento \ module-contact \ Controller \ Index \ Post.php: 49 Трассировка стека: # 0 C: \xampp \ htdocs \ training \ app \ code \ SCI \ Form \ Controller \ Index \ Post.php (17): Magento \ Contact \ Controller \ Index \ Post -> __ construct (Объект (Magento \ Framework \ App \ Action \ Context), Array) # 1 C: \ xampp \ htdocs \ training \ generate \ code \ SCI \ Form \ Controller \ Index \ Post \ Interceptor.php (14): SCI \ Form \ Controller \ Index \ Post -> __ construct (Объект (Magento \ Framework \ App \ Action \ Context), Объект (Magento \ Store \ Model \ StoreManager), Объект (Magento \ Framework \App \ Config), Array) # 2 C: \ xampp \ htdocs \ training \ vendor \ magento \ framework \ ObjectManager \ Factory \ AbstractFactory.php (111): SCI \ Form \ Controller \ Index \ Post \ Interceptor -> __ construct (Объект (Magento \ Framework \ App \ Action \ Conte in C: \ xampp \ htdocs \ training \ vendor \ magento \ module-contact \ Controller \ Index \ Post.php в строке 49

1 Ответ

0 голосов
/ 09 июня 2018

Вы можете попробовать изменить свою функцию на приведенный ниже код для исправления ошибки.

public function ifEnabled(){
    $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

    return $this->_scopeConfig->getValue(
        'extended_contact/config/extended_contact_enabled',
        $storeScope
    );
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...