Skip to content

Commit

Permalink
Got started on vendor access to orders
Browse files Browse the repository at this point in the history
--HG--
branch : multi-vendor
  • Loading branch information
andreymaz committed Mar 26, 2013
1 parent 05f73c4 commit 204d377
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 28 deletions.
Expand Up @@ -597,6 +597,9 @@ public ActionResult List()
foreach (var v in _vendorService.GetAllVendors(0, int.MaxValue, true))
model.AvailableVendors.Add(new SelectListItem() { Text = v.Name, Value = v.Id.ToString() });

//a vendor should have access only to orders with his products
model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

return View(model);
}

Expand All @@ -606,6 +609,12 @@ public ActionResult OrderList(GridCommand command, OrderListModel model)
if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
return AccessDeniedView();

//a vendor should have access only to his products
if (_workContext.CurrentVendor != null)
{
model.VendorId = _workContext.CurrentVendor.Id;
}

DateTime? startDateValue = (model.StartDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

Expand Down Expand Up @@ -682,6 +691,10 @@ public ActionResult ExportXmlAll()
if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
return AccessDeniedView();

//a vendor cannot export orders
if (_workContext.CurrentVendor != null)
return AccessDeniedView();

try
{
var orders = _orderService.SearchOrders(0, 0, 0, null, null, null,
Expand All @@ -702,6 +715,10 @@ public ActionResult ExportXmlSelected(string selectedIds)
if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
return AccessDeniedView();

//a vendor cannot export orders
if (_workContext.CurrentVendor != null)
return AccessDeniedView();

var orders = new List<Order>();
if (selectedIds != null)
{
Expand All @@ -721,6 +738,10 @@ public ActionResult ExportExcelAll()
if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
return AccessDeniedView();

//a vendor cannot export orders
if (_workContext.CurrentVendor != null)
return AccessDeniedView();

try
{
var orders = _orderService.SearchOrders(0, 0, 0, null, null, null,
Expand All @@ -746,6 +767,10 @@ public ActionResult ExportExcelSelected(string selectedIds)
if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
return AccessDeniedView();

//a vendor cannot export orders
if (_workContext.CurrentVendor != null)
return AccessDeniedView();

var orders = new List<Order>();
if (selectedIds != null)
{
Expand Down
Expand Up @@ -2166,7 +2166,7 @@ public ActionResult ImportExcel()

//a vendor cannot import products
if (_workContext.CurrentVendor != null)
return RedirectToAction("List");
return AccessDeniedView();

try
{
Expand Down
Expand Up @@ -50,6 +50,8 @@ public OrderListModel()
[AllowHtml]
public int GoDirectlyToNumber { get; set; }

public bool IsLoggedInAsVendor { get; set; }


public IList<SelectListItem> AvailableOrderStatuses { get; set; }
public IList<SelectListItem> AvailablePaymentStatuses { get; set; }
Expand Down
61 changes: 34 additions & 27 deletions src/Presentation/Nop.Web/Administration/Views/Order/List.cshtml
Expand Up @@ -4,7 +4,6 @@

@{
var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
var hideProfitReport = false;

//page title
ViewBag.Title = T("Admin.Orders").Text;
Expand All @@ -18,10 +17,14 @@
@T("Admin.Orders")
</div>
<div class="options">
<a href="@Url.Action("ExportXmlAll")" class="t-button">@T("Admin.Common.ExportToXml.All")</a>
<input type="button" id="exportxml-selected" class="t-button" value="@T("Admin.Common.ExportToXml.Selected")" />
<a href="@Url.Action("ExportExcelAll")" class="t-button">@T("Admin.Common.ExportToExcel.All")</a>
<input type="button" id="exportexcel-selected" class="t-button" value="@T("Admin.Common.ExportToExcel.Selected")" />
@if (!Model.IsLoggedInAsVendor)
{
//a vendor cannot export/import orders
<a href="@Url.Action("ExportXmlAll")" class="t-button">@T("Admin.Common.ExportToXml.All")</a>
<input type="button" id="exportxml-selected" class="t-button" value="@T("Admin.Common.ExportToXml.Selected")" />
<a href="@Url.Action("ExportExcelAll")" class="t-button">@T("Admin.Common.ExportToExcel.All")</a>
<input type="button" id="exportexcel-selected" class="t-button" value="@T("Admin.Common.ExportToExcel.Selected")" />
}
</div>
</div>
<table width="100%">
Expand Down Expand Up @@ -49,23 +52,23 @@
@Html.EditorFor(model => Model.CustomerEmail)
</td>
</tr>
<tr>
<tr @(Model.IsLoggedInAsVendor ? Html.Raw("style='display: none;'") : null)>
<td class="adminTitle">
@Html.NopLabelFor(model => model.OrderStatusId):
</td>
<td class="adminData">
@Html.DropDownList("OrderStatusId", Model.AvailableOrderStatuses)
</td>
</tr>
<tr>
<tr @(Model.IsLoggedInAsVendor ? Html.Raw("style='display: none;'") : null)>
<td class="adminTitle">
@Html.NopLabelFor(model => model.PaymentStatusId):
</td>
<td class="adminData">
@Html.DropDownList("PaymentStatusId", Model.AvailablePaymentStatuses)
</td>
</tr>
<tr>
<tr @(Model.IsLoggedInAsVendor ? Html.Raw("style='display: none;'") : null)>
<td class="adminTitle">
@Html.NopLabelFor(model => model.ShippingStatusId):
</td>
Expand All @@ -81,7 +84,7 @@
@Html.DropDownList("StoreId", Model.AvailableStores)
</td>
</tr>
<tr>
<tr @(Model.IsLoggedInAsVendor ? Html.Raw("style='display: none;'") : null)>
<td class="adminTitle">
@Html.NopLabelFor(model => model.VendorId):
</td>
Expand Down Expand Up @@ -133,22 +136,30 @@
.HeaderHtmlAttributes(new { style = "text-align:center" });

columns.Bound(x => x.Id);
columns.Bound(x => x.OrderStatus);
columns.Bound(x => x.PaymentStatus);
columns.Bound(x => x.ShippingStatus);
if (!Model.IsLoggedInAsVendor)
{
//a vendor does not see order details such statuses or totals
columns.Bound(x => x.OrderStatus);
columns.Bound(x => x.PaymentStatus);
columns.Bound(x => x.ShippingStatus);
}
columns.Bound(x => x.CustomerEmail);
columns.Bound(x => x.StoreName);
columns.Bound(x => x.CreatedOn);
columns.Bound(x => x.OrderTotal)
.FooterTemplate(
string.Format("<div><strong>{0}:</strong></div>" +
(hideProfitReport ? "{1}" : "<div>{1}: <span id=\"aggregator-profit-block\"></span></div>") +
"<div>{2}: <span id=\"aggregator-tax-block\"></span></div>" +
"<div>{3}: <span id=\"aggregator-total-block\"></span></div>",
@T("Admin.Orders.Report.Summary").Text,
(hideProfitReport ? "" : @T("Admin.Orders.Report.Profit").Text),
@T("Admin.Orders.Report.Tax").Text,
@T("Admin.Orders.Report.Total").Text));
if (!Model.IsLoggedInAsVendor)
{
//a vendor does not see order details such statuses or totals
columns.Bound(x => x.OrderTotal)
.FooterTemplate(
string.Format("<div><strong>{0}:</strong></div>" +
"<div>{1}: <span id=\"aggregator-profit-block\"></span></div>" +
"<div>{2}: <span id=\"aggregator-tax-block\"></span></div>" +
"<div>{3}: <span id=\"aggregator-total-block\"></span></div>",
T("Admin.Orders.Report.Summary").Text,
T("Admin.Orders.Report.Profit").Text,
T("Admin.Orders.Report.Tax").Text,
T("Admin.Orders.Report.Total").Text));
}
columns.Bound(x => x.Id)
.Template(x => Html.ActionLink(T("Admin.Common.View").Text, "Edit", new { id = x.Id }))
.ClientTemplate("<a href=\"Edit/<#= Id #>\">" + T("Admin.Common.View").Text + "</a>")
Expand Down Expand Up @@ -270,11 +281,7 @@
}
function updateAggregates(aggs) {
for (var key in aggs) {
@if (!hideProfitReport)
{
<text>$('#aggregator-profit-block').text(aggs['aggregatorprofit']);</text>
}
$('#aggregator-profit-block').text(aggs['aggregatorprofit']);
$('#aggregator-tax-block').text(aggs['aggregatortax']);
$('#aggregator-total-block').text(aggs['aggregatortotal']);
}
Expand Down

0 comments on commit 204d377

Please sign in to comment.