Skip to content

Commit 098b765

Browse files
committed
Update
1 parent 8438cd0 commit 098b765

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

Block/Adminhtml/Theme/Edit/Form.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @Author: nguyen
55
* @Date: 2020-06-09 19:52:46
66
* @Last Modified by: nguyen
7-
* @Last Modified time: 2020-06-12 11:12:39
7+
* @Last Modified time: 2020-06-12 13:31:08
88
*/
99

1010
namespace Magepow\Theme\Block\Adminhtml\Theme\Edit;
@@ -119,7 +119,7 @@ protected function _prepareForm()
119119
]
120120
);
121121

122-
$field = $fieldset->addField('theme_title', 'text',
122+
$fieldset->addField('theme_title', 'text',
123123
[
124124
'name' => 'theme_title',
125125
'label' => __('Theme Title'),
@@ -130,7 +130,7 @@ protected function _prepareForm()
130130
]
131131
);
132132

133-
$field = $fieldset->addField('theme_path', 'text',
133+
$themePath = $fieldset->addField('theme_path', 'text',
134134
[
135135
'name' => 'theme_path',
136136
'label' => __('Theme Path'),
@@ -141,7 +141,24 @@ protected function _prepareForm()
141141
]
142142
);
143143

144-
$field = $fieldset->addField('theme_type', 'select',
144+
if($this->getRequest()->getParam('theme_id')){
145+
$themePath->setAfterElementHtml(
146+
'<p class="nm"><small>' . __('Don\'t change Theme Path') . '</small></p>
147+
<script type="text/javascript">
148+
require([
149+
"jquery",
150+
], function($){
151+
jQuery(document).ready(function($) {
152+
var themePath = "#'.$themePath->getHtmlId().'";
153+
if ($(themePath).val()) {$(themePath).prop("disabled", true); }
154+
})
155+
})
156+
</script>
157+
'
158+
);
159+
}
160+
161+
$fieldset->addField('theme_type', 'select',
145162
[
146163
'name' => 'theme_type',
147164
'label' => __('Theme Type'),

Controller/Adminhtml/Index/Delete.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @Author: nguyen
55
* @Date: 2020-06-04 17:10:47
66
* @Last Modified by: nguyen
7-
* @Last Modified time: 2020-06-12 13:05:39
7+
* @Last Modified time: 2020-06-12 14:57:42
88
*/
99

1010
namespace Magepow\Theme\Controller\Adminhtml\Index;
@@ -39,6 +39,14 @@ public function execute()
3939
$this->messageManager->addSuccess(
4040
__('Theme record delete successfully !')
4141
);
42+
$collection = $this->_objectManager->create('Magento\Config\Model\ResourceModel\Config\Data\Collection');
43+
$config = $collection->addFieldToSelect('*')->addFieldToFilter('path', 'design/theme/theme_id')->addFieldToFilter('value',$id);
44+
$ids = [];
45+
foreach ($config as $cfg) {
46+
$cfg->setValue(2); /* Luma theme */
47+
$cfg->save();
48+
}
49+
// $config->save();
4250

4351
} catch (\Exception $e) {
4452
$this->messageManager->addError($e->getMessage());

Controller/Adminhtml/Index/Save.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @Author: nguyen
55
* @Date: 2020-05-31 14:56:43
66
* @Last Modified by: nguyen
7-
* @Last Modified time: 2020-06-12 11:30:33
7+
* @Last Modified time: 2020-06-12 13:57:13
88
*/
99

1010
namespace Magepow\Theme\Controller\Adminhtml\Index;
@@ -37,7 +37,8 @@ public function execute()
3737

3838
$parentTheme = $data['parent_theme'];
3939
$themeTitle = $data['theme_title'];
40-
$themePath = $data['theme_path'];
40+
$themePath = isset($data['theme_path']) ? $data['theme_path'] : $model->getThemePath();
41+
4142
if($id && in_array($themePath, $this->defaultTheme)){
4243
$this->messageManager->addError(__('You can\'t edit default theme %1.', $themePath));
4344
$this->_getSession()->setFormData($data);
@@ -67,7 +68,7 @@ public function execute()
6768
$this->_getSession()->setFormData($data);
6869
return $resultRedirect->setPath('*/*/edit');
6970
}
70-
if($data['parent_theme'] == $data['theme_path'] || $parent->getId() == $model->getId()){
71+
if($parentTheme == $themePath || $parent->getId() == $model->getId()){
7172
$this->messageManager->addError(__('Error Parent theme and Child theme same value.'));
7273
$this->_getSession()->setFormData($data);
7374
return $resultRedirect->setPath('*/*/edit');
@@ -86,7 +87,7 @@ public function execute()
8687
$data['area'] = 'frontend';
8788
$data['is_featured'] = 0;
8889
$data['type'] = $data['theme_type'];
89-
$data['code'] = $data['theme_path'];
90+
$data['code'] = $themePath;
9091
if(isset($data['overwrite']) && $model->getThemeId()){
9192
$model->addData($data);
9293
}else {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "magepow/theme",
3-
"description": "You Manage create or edit theme via admin.",
3+
"description": "You Manage create or edit theme form admin.",
44
"type": "magento2-module",
55
"license": [
66
"OSL-3.0",

0 commit comments

Comments
 (0)