سؤال

I am unable to apply a new theme in a clean install of 2.2.4. Upading to 2.2.5 does not fix the problem.

هل كانت مفيدة؟

المحلول

Note : This is a know issue in Magento 2.2.4 (see GitHub issue) and below fix is just a temp fix. You should not directly change the Magento core file (override or create a plugin)

Change in Magento\Email\Model\AbstractTemplate.php this:

public function setForcedArea($templateId)
{
    if ($this->area) {
        throw new \LogicException(__('Area is already set'));
    }
    $this->area = $this->emailConfig->getTemplateArea($templateId);
    return $this;
}

For this:

public function setForcedArea($templateId)
{
    if (!isset($this->area)) {
        $this->area = $this->emailConfig->getTemplateArea($templateId);
    }
    return $this;
}

It should fix the issue

Update : can also be fixed by applying this Patch

نصائح أخرى

For fixed error Something went wrong while saving this configuration: Area is already set while saving theme configuration. You want create plugin for override Magento\Email\Model\AbstractTemplate.php file in custom module. And update setForcedArea() function.

File path: magento/app/code/Vendor/AreaConfigFix/registration.php

<?php
use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Vendor_AreaConfigFix', __DIR__);

File path: magento/app/code/Vendor/AreaConfigFix/etc/module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_AreaConfigFix" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Email"/>
        </sequence>
    </module>
</config>

File path: magento/app/code/Vendor/AreaConfigFix/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Email\Model\AbstractTemplate">
        <plugin name="email_setforced_area" type="Vendor\AreaConfigFix\Plugin\Email\Model\AbstractTemplate" />
    </type>
</config>

File path: magento/app/code/Vendor/AreaConfigFix/Plugin/Email/Model/AbstractTemplate.php

<?php
namespace Vendor\AreaConfigFix\Plugin\Email\Model;

class AbstractTemplate
{
    private $emailConfig;

    public function __construct(\Magento\Email\Model\Template\Config $emailConfig)
    {
        $this->emailConfig = $emailConfig;
    }

    public function aroundSetForcedArea(\Magento\Email\Model\AbstractTemplate $subject, \Closure $proceed, $templateId)
    {
        if (!isset($this->area)) {
            $this->area = $this->emailConfig->getTemplateArea($templateId);
        }
        return $this;
    }
}

Instead of installing the patch given by magento or changing the core files directly here is how I did it:

"File path: magento/app/code/Vendor/ThemeErrorFix/registration.php"

<?php
use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Vendor_ThemeErrorFix', __DIR__);

"File path: magento/app/code/Vendor/ThemeErrorFix/etc/module.xml"

    <?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_ThemeErrorFix" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Email"/>
        </sequence>
    </module>
</config>

"File path: magento/app/code/Vendor/ThemeErrorFix/etc/di.xml"

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Email\Model\Template">
        type="email_setforced_area" type="Vendor\ThemeErrorFix\Model\Template" />

</config>

"File path: magento/app/code/Vendor/ThemeErrorFix/Model/Template.php"

<?php

namespace Vendor\ThemeErrorFix\Model;

use Magento\Email\Model\Template as coreTemplate;

class Template extends coreTemplate

{
   public function setForcedArea($templateId)
{
    if (!isset($this->area)) {
        $this->area = $this->emailConfig->getTemplateArea($templateId);
    }
    return $this;
}
}

I corrected your code by removing the duplicated type attribute.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Email\Model\Template"
        type="Vendor\ThemeErrorFix\Model\Template" />

</config>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top