Skip to content

Commit 5435952

Browse files
author
Jan Gantzert
committed
fix update of deleted templates
1 parent 1f1cc32 commit 5435952

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Model/Content.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace TemplateProvider\EMailTemplatesImportExport\Model;
44

5+
use Magento\Framework\App\ObjectManager;
56
use Magento\Store\Api\StoreRepositoryInterface;
67
use Magento\Framework\Json\DecoderInterface;
78
use Magento\Framework\Json\EncoderInterface;
@@ -65,7 +66,13 @@ class Content implements ContentInterface
6566
*/
6667
private CollectionFactory $collectionFactory;
6768

69+
/**
70+
* @var \Magento\Framework\ObjectManagerInterface
71+
*/
72+
protected $objectManager;
73+
6874
public function __construct(
75+
\Magento\Framework\ObjectManagerInterface $objectManager,
6976
StoreRepositoryInterface $storeRepositoryInterface,
7077
EncoderInterface $encoderInterface,
7178
DecoderInterface $decoderInterface,
@@ -75,6 +82,7 @@ public function __construct(
7582
DateTime $dateTime
7683
)
7784
{
85+
$this->objectManager = $objectManager;
7886
$this->storeRepositoryInterface = $storeRepositoryInterface;
7987
$this->encoderInterface = $encoderInterface;
8088
$this->decoderInterface = $decoderInterface;
@@ -307,14 +315,16 @@ private function importEMailTemplatesFromArray(array $eMailTemplateSource): bool
307315
/** @var \Magento\Email\Model\Template $eMailTemplate */
308316
$eMailTemplate = $this->collectionFactory->create()->getItemById($eMailTemplateSource['emailtemplate']['id']);
309317

310-
if ($this->mode == ContentInterface::EMAIL_TEMPLATES_MODE_SKIP) {
318+
if ($eMailTemplate !== null && $this->mode == ContentInterface::EMAIL_TEMPLATES_MODE_SKIP) {
311319
return false;
312320
}
321+
if ($eMailTemplate === null) {
322+
$eMailTemplate = $this->objectManager->create(\Magento\Email\Model\Template::class);
323+
}
313324

314325
$eMailTemplateContent = $eMailTemplateSource['emailtemplate'];
315326

316327
$eMailTemplate
317-
->setId($eMailTemplateContent['id'])
318328
->setTemplateCode($eMailTemplateContent['template_code'])
319329
->setTemplateText($eMailTemplateContent['template_text'])
320330
->setTemplateStyles($eMailTemplateContent['template_styles'])

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "Jan Gantzert"
99
}
1010
],
11-
"version": "1.0.1",
11+
"version": "1.0.2",
1212
"license": [
1313
"OSL-3.0",
1414
"AFL-3.0"

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" ?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4-
<module name="TemplateProvider_EMailTemplatesImportExport" setup_version="1.0.0"/>
4+
<module name="TemplateProvider_EMailTemplatesImportExport" setup_version="1.0.2"/>
55
</config>

0 commit comments

Comments
 (0)