Skip to content

Commit cfb73e5

Browse files
committed
Featured image added to import from wordpress process
1 parent 67f7ef9 commit cfb73e5

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Block/Adminhtml/Import/Wordpress/Form.php

+10
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ protected function _prepareForm()
7676
]
7777
);
7878

79+
$fieldset->addField(
80+
'notice',
81+
'label',
82+
[
83+
'label' => __('NOTICE'),
84+
'name' => 'prefix',
85+
'after_element_html' => 'When the import is completed successfully, please copy image files from WordPress <strong style="color:#bd1616;">wp-content/uploads</strong> directory to Magento <strong style="color:#105610;">pub/media/magefan_blog</strong> directory.',
86+
]
87+
);
88+
7989
$fieldset->addField(
8090
'dbname',
8191
'text',

Model/Import/Wordpress.php

+33-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ public function execute()
7979
$ct->setPath(
8080
$parentId = $oldCategories[$oldParentId]->getId()
8181
);
82-
83-
echo 'set path: '.$parentId.'<br/>';
8482
}
8583
}
8684
}
@@ -130,6 +128,38 @@ public function execute()
130128
}
131129
}
132130

131+
$data['featured_img'] = '';
132+
133+
$sql = 'SELECT wm2.meta_value as featured_img
134+
FROM
135+
'.$_pref.'posts p1
136+
LEFT JOIN
137+
'.$_pref.'postmeta wm1
138+
ON (
139+
wm1.post_id = p1.id
140+
AND wm1.meta_value IS NOT NULL
141+
AND wm1.meta_key = "_thumbnail_id"
142+
)
143+
LEFT JOIN
144+
wp_postmeta wm2
145+
ON (
146+
wm1.meta_value = wm2.post_id
147+
AND wm2.meta_key = "_wp_attached_file"
148+
AND wm2.meta_value IS NOT NULL
149+
)
150+
WHERE
151+
p1.ID="'.$data['ID'].'"
152+
AND p1.post_type="post"
153+
ORDER BY
154+
p1.post_date DESC';
155+
156+
$result2 = $this->_mysqliQuery($sql);
157+
if ($data2 = mysqli_fetch_assoc($result2)) {
158+
if ($data2['featured_img']) {
159+
$data['featured_img'] = \Magefan\Blog\Model\Post::BASE_MEDIA_PATH . '/' . $data2['featured_img'];
160+
}
161+
}
162+
133163
/* Prepare post data */
134164
foreach (['post_title', 'post_name', 'post_content'] as $key) {
135165
$data[$key] = utf8_encode($data[$key]);
@@ -149,6 +179,7 @@ public function execute()
149179
'publish_time' => $creationTime,
150180
'is_active' => (int)($data['post_status'] == 'publish'),
151181
'categories' => $postCategories,
182+
'featured_img' => $data['featured_img'],
152183
];
153184
$data['identifier'] = trim(strtolower($data['identifier']));
154185
if (strlen($data['identifier']) == 1) {

0 commit comments

Comments
 (0)