Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion Model/Import/Aw.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function execute()
continue;
}

$data['title'] = trim($data['title']);
$data['title'] = mb_strtolower(trim($data['title']));

try {
/* Initial saving */
Expand Down Expand Up @@ -167,6 +167,55 @@ public function execute()
$data['store_ids'] = 0;
}

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$moduleManager = $objectManager->get(\Magento\Framework\Module\Manager::class);
if ($moduleManager->isEnabled('Magefan_BlogAuthor')) {
/* Import author */
if (!empty($data['user'])) {
$authorInfo = explode(' ', $data['user']);
$authorData['firstname'] = $authorInfo[0];
$authorData['lastname'] = isset($authorInfo[1]) ? $authorInfo[1] : $authorInfo[0];

$author = $this->_authorFactory->create();
$existingAuthor = $author->getCollection()
->addFieldTofilter('firstname', $authorData['firstname'])
->addFieldTofilter('lastname', $authorData['lastname'])
->setPageSize(1)
->getFirstItem();

if ($existingAuthor->getId()) {
$author = $existingAuthor;
} else {
try {
/* Author saving */
$author->setData($authorData)->save();
$this->_importedAuthorsCount++;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
/* echo $e->getMessage(); */
}
}

if ($author->getId()) {
$data['author_id'] = $author->getId();
}
}
}

/* Find post tags */
$postTags = [];
if (!empty($data['tags'])) {
$t_result = explode(',', mb_strtolower($data['tags']));
foreach ($t_result as $t_data) {
if (!empty($oldTags)) {
foreach ($oldTags as $oldTag) {
if ($oldTag->getTitle() === $t_data) {
$postTags[$oldTag->getId()] = $oldTag->getId();
}
}
}
}
}

/* Prepare post data */
$data = [
'old_id' => $data['post_id'],
Expand All @@ -184,6 +233,8 @@ public function execute()
'is_active' => (int)($data['status'] == 1),
'categories' => $postCategories,
'featured_img' => !empty($data['featured_image']) ? 'magefan_blog/' . $data['featured_image'] : '',
'tags' => $postTags,
'author_id' => !empty($data['author_id']) ? $data['author_id'] : null,
];
$data['identifier'] = trim(strtolower($data['identifier']));

Expand Down