7
7
8
8
use Magento \Framework \Serialize \Serializer \Json ;
9
9
use Magento \Framework \Setup \SampleData \Context as SampleDataContext ;
10
+ use \Magento \Framework \App \State ;
10
11
11
12
/**
12
13
* Launches setup of sample data for Widget module
@@ -53,6 +54,11 @@ class CmsBlock
53
54
*/
54
55
private $ serializer ;
55
56
57
+ /**
58
+ * @var State
59
+ */
60
+ private $ appState ;
61
+
56
62
/**
57
63
* @param SampleDataContext $sampleDataContext
58
64
* @param \Magento\Widget\Model\Widget\InstanceFactory $widgetFactory
@@ -61,6 +67,7 @@ class CmsBlock
61
67
* @param \Magento\Widget\Model\ResourceModel\Widget\Instance\CollectionFactory $appCollectionFactory
62
68
* @param \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryFactory
63
69
* @param Json|null $serializer
70
+ * @param State|null $appState
64
71
*/
65
72
public function __construct (
66
73
SampleDataContext $ sampleDataContext ,
@@ -69,7 +76,8 @@ public function __construct(
69
76
\Magento \Cms \Model \BlockFactory $ cmsBlockFactory ,
70
77
\Magento \Widget \Model \ResourceModel \Widget \Instance \CollectionFactory $ appCollectionFactory ,
71
78
\Magento \Catalog \Model \ResourceModel \Category \CollectionFactory $ categoryFactory ,
72
- Json $ serializer = null
79
+ Json $ serializer = null ,
80
+ State $ appState = null
73
81
) {
74
82
$ this ->fixtureManager = $ sampleDataContext ->getFixtureManager ();
75
83
$ this ->csvReader = $ sampleDataContext ->getCsvReader ();
@@ -79,6 +87,7 @@ public function __construct(
79
87
$ this ->appCollectionFactory = $ appCollectionFactory ;
80
88
$ this ->categoryFactory = $ categoryFactory ;
81
89
$ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (Json::class);
90
+ $ this ->appState = $ appState ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (State::class);
82
91
}
83
92
84
93
/**
@@ -163,7 +172,10 @@ public function install(array $fixtures)
163
172
->setStoreIds ([\Magento \Store \Model \Store::DEFAULT_STORE_ID ])
164
173
->setWidgetParameters (['block_id ' => $ block ->getId ()])
165
174
->setPageGroups ([$ pageGroup ]);
166
- $ widgetInstance ->save ();
175
+ $ this ->appState ->emulateAreaCode (
176
+ 'frontend ' ,
177
+ [$ widgetInstance , 'save ' ]
178
+ );
167
179
}
168
180
}
169
181
}
0 commit comments