Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show order comments in customer account #4

Merged
merged 2 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
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
49 changes: 49 additions & 0 deletions Block/Order/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Bold\OrderComment\Block\Order;

use Bold\OrderComment\Model\Data\OrderComment;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template\Context as TemplateContext;
use Magento\Sales\Model\Order;

class Comment extends \Magento\Framework\View\Element\Template
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $coreRegistry = null;

public function __construct(
TemplateContext $context,
Registry $registry,
array $data = []
) {
$this->coreRegistry = $registry;
$this->_isScopePrivate = true;
$this->_template = 'order/view/comment.phtml';
parent::__construct($context, $data);
}

public function getOrder() : Order
{
return $this->coreRegistry->registry('current_order');
}

public function getOrderComment(): string
{
return trim($this->getOrder()->getData(OrderComment::COMMENT_FIELD_NAME));
}

public function hasOrderComment() : bool
{
return strlen($this->getOrderComment()) > 0;
}

public function getOrderCommentHtml() : string
{
return nl2br($this->escapeHtml($this->getOrderComment()));
}
}
14 changes: 14 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="sales">
<group id="ordercomments" translate="label" type="text" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Order Comment</label>
<field id="show_in_account" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
<label>Show comments in customer account</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
10 changes: 10 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<sales>
<ordercomments>
<show_in_account>1</show_in_account>
</ordercomments>
</sales>
</default>
</config>
8 changes: 8 additions & 0 deletions view/frontend/layout/sales_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block ifconfig="sales/ordercomments/show_in_account" class="Bold\OrderComment\Block\Order\Comment" as="ordercomment" name="sales.order.comment" after="sales.order.info"/>
</referenceContainer>
</body>
</page>
15 changes: 15 additions & 0 deletions view/frontend/templates/order/view/comment.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/** @var \Bold\OrderComment\Block\Order\Comment $block */
?>
<?php if($comment = $block->getOrderComment()):?>
<div class="block block-order-details-view">
<div class="block-content">
<div class="box box-order-comment">
<strong class="box-title"><span><?php /* @escapeNotVerified */ echo __('Order Comment') ?></span></strong>
<div class="box-content">
<?php echo $block->getOrderCommentHtml();?>
</div>
</div>
</div>
</div>
<?php endif; ?>