diff --git a/Block/Post/Info.php b/Block/Post/Info.php index ad238d19..b29614fe 100755 --- a/Block/Post/Info.php +++ b/Block/Post/Info.php @@ -78,4 +78,30 @@ public function viewsCountEnabled() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } + + /** + * Get blog post vote action + * + * @return string + */ + public function getAction() + { + return $this->getUrl( + 'blogextra/post/vote', + [ + '_secure' => $this->getRequest()->isSecure(), + 'id' => $this->getPostId(), + ] + ); + } + + /** + * Get vote post id + * + * @return int + */ + protected function getPostId() + { + return $this->getRequest()->getParam('id', false); + } } diff --git a/Controller/Adminhtml/Post/Save.php b/Controller/Adminhtml/Post/Save.php index a72c2ace..426601c7 100755 --- a/Controller/Adminhtml/Post/Save.php +++ b/Controller/Adminhtml/Post/Save.php @@ -28,6 +28,13 @@ class Save extends \Magefan\Blog\Controller\Adminhtml\Post */ protected function _beforeSave($model, $request) { + $postRepository = $this->_objectManager->get(\Magefan\Blog\Api\PostRepositoryInterface::class); + $post = $postRepository->getById($model->getId()); + + if ($post->getSummaryRating() && $post->getSummaryRating() !== $request->getPost('summary_rating')) { + $model->setData('votes_count', 1); + } + /* Prepare author */ if (!$model->getAuthorId()) { $authSession = $this->_objectManager->get(\Magento\Backend\Model\Auth\Session::class); diff --git a/Controller/Comment/Post.php b/Controller/Comment/Post.php index 881811ee..83de9d8f 100755 --- a/Controller/Comment/Post.php +++ b/Controller/Comment/Post.php @@ -92,7 +92,7 @@ public function execute() $this->customerSession->getCustomerId() )->setAuthorNickname( $this->customerSession->getCustomer()->getName() - )->setAauthorEmail( + )->setAuthorEmail( $this->customerSession->getCustomer()->getEmail() )->setAuthorType( \Magefan\Blog\Model\Config\Source\AuthorType::CUSTOMER @@ -109,7 +109,7 @@ public function execute() ])); return; } - + $comment->setCustomerId(0)->setAuthorType( \Magefan\Blog\Model\Config\Source\AuthorType::GUEST ); diff --git a/view/frontend/templates/post/info.phtml b/view/frontend/templates/post/info.phtml index c8d27160..a82d46b4 100755 --- a/view/frontend/templates/post/info.phtml +++ b/view/frontend/templates/post/info.phtml @@ -15,6 +15,7 @@ ?> getPost() ?> +
isPublishDateEnabled()) { ?> @@ -92,4 +93,77 @@ + + getSummaryRating()) { ?> +
+ +
+ escapeHtml(__('Rating')) ?>: +
+ + + escapeHtml($rating); ?> + % of 100 + + +
+ renderStyleAsTag( + 'width:' . $block->escapeHtmlAttr($rating) . '%', + '#rating-result_' . $_post->getId() . ' span' + ) ?> +
+ +
+ escapeHtml($_post->getVotesCount()) ?>  + getVotesCount() == 1) ? $block->escapeHtml(__('Vote')) : + $block->escapeHtml(__('Votes')) ?> + +
+
+
+
+ getBlockHtml('formkey') ?> +
+ +
+ Your Rating
+
+
+
+
+ + + + +
+
+
+
+
+
+
+ + +
diff --git a/view/frontend/templates/post/view.phtml b/view/frontend/templates/post/view.phtml index fd5ddce3..5b475a49 100644 --- a/view/frontend/templates/post/view.phtml +++ b/view/frontend/templates/post/view.phtml @@ -58,4 +58,4 @@ $_postName = $block->escapeHtml($_post->getTitle(), null); getChildHtml('blog.post.bottom') ?> - \ No newline at end of file +