Merge pull request #3013 from jitendra-webkul/1.0

Order comment feature added
This commit is contained in:
Jitendra Singh 2020-05-06 22:52:09 +05:30 committed by GitHub
commit 45e61682cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 292 additions and 58 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/admin.js": "/js/admin.js?id=2701b1627d73faa941d6",
"/css/admin.css": "/css/admin.css?id=bbb1e500385b8d7ade13"
"/css/admin.css": "/css/admin.css?id=1676f6fcbbb2a7b25767"
}

View File

@ -2,8 +2,10 @@
namespace Webkul\Admin\Http\Controllers\Sales;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Sales\Repositories\OrderRepository;
use \Webkul\Sales\Repositories\OrderCommentRepository;
class OrderController extends Controller
{
@ -21,19 +23,32 @@ class OrderController extends Controller
*/
protected $orderRepository;
/**
* OrderCommentRepository object
*
* @var \Webkul\Sales\Repositories\OrderCommentRepository
*/
protected $orderCommentRepository;
/**
* Create a new controller instance.
*
* @param \Webkul\Sales\Repositories\OrderRepository $orderRepository
* @param \Webkul\Sales\Repositories\OrderCommentRepository $orderCommentRepository
* @return void
*/
public function __construct(OrderRepository $orderRepository)
public function __construct(
OrderRepository $orderRepository,
OrderCommentRepository $orderCommentRepository
)
{
$this->middleware('admin');
$this->_config = request('_config');
$this->orderRepository = $orderRepository;
$this->orderCommentRepository = $orderCommentRepository;
}
/**
@ -77,4 +92,29 @@ class OrderController extends Controller
return redirect()->back();
}
/**
* Add comment to the order
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function comment($id)
{
$data = array_merge(request()->all(), [
'order_id' => $id,
]);
$data['customer_notified'] = isset($data['customer_notified']) ? 1 : 0;
Event::dispatch('sales.order.comment.create.before', $data);
$comment = $this->orderCommentRepository->create($data);
Event::dispatch('sales.order.comment.create.after', $comment);
session()->flash('success', trans('admin::app.sales.orders.comment-added-success'));
return redirect()->back();
}
}

View File

@ -187,6 +187,8 @@ Route::group(['middleware' => ['web']], function () {
'view' => 'admin::sales.orders.cancel'
])->name('admin.sales.orders.cancel');
Route::post('/orders/create/{order_id}', 'Webkul\Admin\Http\Controllers\Sales\OrderController@comment')->name('admin.sales.orders.comment');
// Sales Invoices Routes
Route::get('/invoices', 'Webkul\Admin\Http\Controllers\Sales\InvoiceController@index')->defaults('_config', [

View File

@ -48,8 +48,33 @@
}
}
.summary-comment-container {
.comment-container {
margin-top: 20px;
float: left;
.comment-list {
margin-top: 40px;
li {
margin-bottom: 20px;
&:last-child {
margin-bottom: 0;
}
p {
margin: 0;
margin-top: 5px;
color: #8e8e8e;
}
}
}
}
}
.sale-summary {
margin-top: 2%;
margin-top: 20px;
height: 130px;
float: right;

View File

@ -370,7 +370,11 @@ return [
'total-due' => 'المجموع المستحق',
'cancel-confirm-msg' => 'هل أنت متأكد من أنك تريد إلغاء هذا الطلب ؟',
'refunds' => 'المبالغ المستردة',
'refunded' => 'تم رد الأموال'
'refunded' => 'تم رد الأموال',
'comment-added-success' => 'Comment addded successfully.',
'comment' => 'Comment',
'submit-comment' => 'Submit Comment',
'notify-customer' => 'Notify Customer',
],
'invoices' => [

View File

@ -370,7 +370,13 @@ return [
'total-due' => 'Total Due',
'cancel-confirm-msg' => 'Are you sure you want to cancel this order ?',
'refund-btn-title' => 'Refund',
'refunds' => 'Refunds'
'refunds' => 'Refunds',
'comment-added-success' => 'Comment addded successfully.',
'comment' => 'Comment',
'submit-comment' => 'Submit Comment',
'notify-customer' => 'Notify Customer',
'customer-notified' => ':date | Customer <b>Notified</b>',
'customer-not-notified' => ':date | Customer <b>Not Notified</b>'
],
'invoices' => [

View File

@ -370,7 +370,11 @@ return [
'cancel-confirm-msg' => 'مطمئن هستید که می خواهید این سفارش را لغو کنید ؟',
'refunds' => 'بازپرداخت',
'refund-btn-title' => 'بازپرداخت',
'refunded' => 'بازپرداخت'
'refunded' => 'بازپرداخت',
'comment-added-success' => 'Comment addded successfully.',
'comment' => 'Comment',
'submit-comment' => 'Submit Comment',
'notify-customer' => 'Notify Customer',
],
'invoices' => [

View File

@ -370,7 +370,11 @@ return [
'total-due' => 'Total Due',
'cancel-confirm-msg' => 'Weet u zeker dat u deze bestelling wilt annuleren ?',
'refund-btn-title' => 'Terugbetaling',
'refunds' => 'Terugbetalingen'
'refunds' => 'Terugbetalingen',
'comment-added-success' => 'Comment addded successfully.',
'comment' => 'Comment',
'submit-comment' => 'Submit Comment',
'notify-customer' => 'Notify Customer',
],
'invoices' => [

View File

@ -370,7 +370,11 @@ return [
'total-due' => 'Total Devido',
'cancel-confirm-msg' => 'Tem certeza que deseja cancelar esse pedido ?',
'refunds' => 'Refunds',
'refunded' => 'Refunded'
'refunded' => 'Refunded',
'comment-added-success' => 'Comment addded successfully.',
'comment' => 'Comment',
'submit-comment' => 'Submit Comment',
'notify-customer' => 'Notify Customer',
],
'invoices' => [

View File

@ -339,66 +339,107 @@
</table>
</div>
<table class="sale-summary">
<tr>
<td>{{ __('admin::app.sales.orders.subtotal') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_sub_total) }}</td>
</tr>
<div class="summary-comment-container">
<div class="comment-container">
<form action="{{ route('admin.sales.orders.comment', $order->id) }}" method="post">
@csrf()
@if ($order->haveStockableItems())
<div class="control-group" :class="[errors.has('comment') ? 'has-error' : '']">
<label for="comment" class="required">{{ __('admin::app.sales.orders.comment') }}</label>
<textarea v-validate="'required'" class="control" id="comment" name="comment" data-vv-as="&quot;{{ __('admin::app.sales.orders.comment') }}&quot;"></textarea>
<span class="control-error" v-if="errors.has('comment')">@{{ errors.first('comment') }}</span>
</div>
<div class="control-group">
<span class="checkbox">
<input type="checkbox" name="customer_notified" id="customer-notified" name="checkbox[]">
<label class="checkbox-view" for="customer-notified"></label>
{{ __('admin::app.sales.orders.notify-customer') }}
</span>
</div>
<button type="submit" class="btn btn-lg btn-primary">
{{ __('admin::app.sales.orders.submit-comment') }}
</button>
</form>
<ul class="comment-list">
@foreach ($order->comments()->orderBy('id', 'desc')->get() as $comment)
<li>
<span class="comment-info">
@if ($comment->customer_notified)
{!! __('admin::app.sales.orders.customer-notified', ['date' => $comment->created_at]) !!}
@else
{!! __('admin::app.sales.orders.customer-not-notified', ['date' => $comment->created_at]) !!}
@endif
</span>
<p>{{ $comment->comment }}</p>
</li>
@endforeach
</ul>
</div>
<table class="sale-summary">
<tr>
<td>{{ __('admin::app.sales.orders.shipping-handling') }}</td>
<td>{{ __('admin::app.sales.orders.subtotal') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_shipping_amount) }}</td>
<td>{{ core()->formatBasePrice($order->base_sub_total) }}</td>
</tr>
@endif
@if ($order->base_discount_amount > 0)
<tr>
<td>
{{ __('admin::app.sales.orders.discount') }}
@if ($order->haveStockableItems())
<tr>
<td>{{ __('admin::app.sales.orders.shipping-handling') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_shipping_amount) }}</td>
</tr>
@endif
@if ($order->coupon_code)
({{ $order->coupon_code }})
@endif
</td>
@if ($order->base_discount_amount > 0)
<tr>
<td>
{{ __('admin::app.sales.orders.discount') }}
@if ($order->coupon_code)
({{ $order->coupon_code }})
@endif
</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_discount_amount) }}</td>
</tr>
@endif
<tr class="border">
<td>{{ __('admin::app.sales.orders.tax') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_discount_amount) }}</td>
<td>{{ core()->formatBasePrice($order->base_tax_amount) }}</td>
</tr>
@endif
<tr class="border">
<td>{{ __('admin::app.sales.orders.tax') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_tax_amount) }}</td>
</tr>
<tr class="bold">
<td>{{ __('admin::app.sales.orders.grand-total') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_grand_total) }}</td>
</tr>
<tr class="bold">
<td>{{ __('admin::app.sales.orders.grand-total') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_grand_total) }}</td>
</tr>
<tr class="bold">
<td>{{ __('admin::app.sales.orders.total-paid') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_grand_total_invoiced) }}</td>
</tr>
<tr class="bold">
<td>{{ __('admin::app.sales.orders.total-paid') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_grand_total_invoiced) }}</td>
</tr>
<tr class="bold">
<td>{{ __('admin::app.sales.orders.total-refunded') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_grand_total_refunded) }}</td>
</tr>
<tr class="bold">
<td>{{ __('admin::app.sales.orders.total-due') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_total_due) }}</td>
</tr>
</table>
<tr class="bold">
<td>{{ __('admin::app.sales.orders.total-refunded') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_grand_total_refunded) }}</td>
</tr>
<tr class="bold">
<td>{{ __('admin::app.sales.orders.total-due') }}</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_total_due) }}</td>
</tr>
</table>
</div>
</div>
</accordian>

View File

@ -0,0 +1,7 @@
<?php
namespace Webkul\Sales\Contracts;
interface OrderComment
{
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOrderCommentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('order_comments', function (Blueprint $table) {
$table->increments('id');
$table->text('comment');
$table->boolean('customer_notified')->default(0);
$table->integer('order_id')->unsigned()->nullable();
$table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('order_comments');
}
}

View File

@ -78,7 +78,6 @@ class Order extends Model implements OrderContract
return $this->belongsTo(CartProxy::modelClass());
}
/**
* Get the order items record associated with the order.
*/
@ -87,6 +86,14 @@ class Order extends Model implements OrderContract
return $this->hasMany(OrderItemProxy::modelClass())->whereNull('parent_id');
}
/**
* Get the comments record associated with the order.
*/
public function comments()
{
return $this->hasMany(OrderCommentProxy::modelClass());
}
/**
* Get the order items record associated with the order.
*/

View File

@ -0,0 +1,24 @@
<?php
namespace Webkul\Sales\Models;
use Webkul\Checkout\Models\CartProxy;
use Illuminate\Database\Eloquent\Model;
use Webkul\Sales\Contracts\OrderComment as OrderCommentContract;
class OrderComment extends Model implements OrderCommentContract
{
protected $fillable = [
'comment',
'customer_notified',
'order_id',
];
/**
* Get the order record associated with the order comment.
*/
public function order()
{
return $this->belongsTo(OrderProxy::modelClass());
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Webkul\Sales\Models;
use Konekt\Concord\Proxies\ModelProxy;
class OrderCommentProxy extends ModelProxy
{
}

View File

@ -12,6 +12,7 @@ class ModuleServiceProvider extends BaseModuleServiceProvider
\Webkul\Sales\Models\DownloadableLinkPurchased::class,
\Webkul\Sales\Models\OrderAddress::class,
\Webkul\Sales\Models\OrderPayment::class,
\Webkul\Sales\Models\OrderComment::class,
\Webkul\Sales\Models\Invoice::class,
\Webkul\Sales\Models\InvoiceItem::class,
\Webkul\Sales\Models\Shipment::class,

View File

@ -0,0 +1,19 @@
<?php
namespace Webkul\Sales\Repositories;
use Webkul\Core\Eloquent\Repository;
use Webkul\Sales\Contracts\OrderComment;
class OrderCommentRepository extends Repository
{
/**
* Specify Model class name
*
* @return string
*/
public function model()
{
return OrderComment::class;
}
}