Skip to content

Commit

Permalink
Further changes Grand.Web.Vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Oct 28, 2023
1 parent 113460c commit 3587775
Show file tree
Hide file tree
Showing 28 changed files with 689 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
field: "CategoryId",
title: "@Loc["Vendor.Catalog.Products.Categories.Fields.Category"]",
width: 200,
editor: categoryDropDownEditor
editor: categoryDropDownEditor,
template: '#:Category#'
},
{
field: "DisplayOrder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
field: "CollectionId",
title: "@Loc["Vendor.Catalog.Products.Collections.Fields.Collection"]",
width: 200,
editor: collectionDropDownEditor
editor: collectionDropDownEditor,
template: '#:Collection#'
},
{
field: "DisplayOrder",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
@model ProductModel
@inject Grand.Business.Core.Interfaces.Common.Security.IPermissionService permissionService
@{
//has "Manage Documents" permission?
var canManageDocuments = await permissionService.Authorize(Grand.Business.Core.Utilities.Common.Security.StandardPermission.ManageDocuments);
}

<div asp-validation-summary="All"></div>
<input asp-for="Id" type="hidden" />
<input asp-for="Ticks" type="hidden" />
Expand Down Expand Up @@ -134,16 +130,6 @@
</div>
</content>
</tabstrip-item>
if (canManageDocuments)
{
<tabstrip-item text="@Loc["Vendor.Catalog.Products.Documents"]" tab-index="17">
<content>
<div>
<partial name="Partials/CreateOrUpdate.Documents" model="Model" />
</div>
</content>
</tabstrip-item>
}
}
<vc:vendor-widget widget-zone="product_details_tabs" additional-data="Model" />
</items>
Expand Down
14 changes: 2 additions & 12 deletions src/Web/Grand.Web.Vendor/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,7 @@ public async Task<IActionResult> CrossSellProductList(DataSourceRequest command,
public async Task<IActionResult> CrossSellProductDelete(ProductModel.CrossSellProductModel model)
{
var product = await _productService.GetProductById(model.ProductId);
if (product == null)
{
throw new ArgumentException("Product not exists");
}


var crossSellProduct = product.CrossSellProduct.FirstOrDefault(x => x == model.Id);
if (string.IsNullOrEmpty(crossSellProduct))
throw new ArgumentException("No cross-sell product found with the specified id");
Expand Down Expand Up @@ -1406,9 +1402,7 @@ public async Task<IActionResult> ProductSpecAttrPopup(
if (ModelState.IsValid)
{
var product = await _productService.GetProductById(model.ProductId);
if (product == null)
return Content("Product not exists");


var psa = product.ProductSpecificationAttributes.FirstOrDefault(x => x.Id == model.Id);
if (psa == null)
await _productViewModelService.InsertProductSpecificationAttributeModel(model, product);
Expand Down Expand Up @@ -1945,10 +1939,6 @@ public async Task<IActionResult> ProductAttributeMappingPopup(ProductModel.Produ
{
if (ModelState.IsValid)
{
var product = await _productService.GetProductById(model.ProductId);
if (product == null)
throw new ArgumentException("No product found with the specified id");

if (string.IsNullOrEmpty(model.Id))
await _productViewModelService.InsertProductAttributeMappingModel(model);
else
Expand Down
143 changes: 143 additions & 0 deletions src/Web/Grand.Web.Vendor/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Interfaces.Catalog.Collections;
using Microsoft.AspNetCore.Mvc;
using Grand.Web.Common.DataSource;
using Grand.Domain.Catalog;
using Grand.Business.Core.Interfaces.Catalog.Brands;
using Grand.Domain.Admin;
using Grand.Web.Vendor.Models.Common;

namespace Grand.Web.Vendor.Controllers
{
public class SearchController : BaseVendorController
{
private readonly ICategoryService _categoryService;
private readonly ICollectionService _collectionService;
private readonly AdminSearchSettings _adminSearchSettings;
private readonly IBrandService _brandService;

public SearchController(ICategoryService categoryService,
IBrandService brandService, ICollectionService collectionService,
AdminSearchSettings adminSearchSettings)
{
_categoryService = categoryService;
_brandService = brandService;
_collectionService = collectionService;
_adminSearchSettings = adminSearchSettings;
}

[HttpGet]
public async Task<IActionResult> Category(string categoryId)
{
var value = HttpContext.Request.Query["filter[filters][0][value]"].ToString();

async Task<IList<SearchModel>> PrepareModel(IEnumerable<Category> categories)
{
var model = new List<SearchModel>();
if (!string.IsNullOrEmpty(categoryId))
{
var currentCategory = await _categoryService.GetCategoryById(categoryId);
if (currentCategory != null)
{
model.Add(new SearchModel {
Id = currentCategory.Id,
Name = await _categoryService.GetFormattedBreadCrumb(currentCategory)
});
}
}
foreach (var item in categories)
{
if (item.Id != categoryId)
model.Add(new SearchModel {
Id = item.Id,
Name = await _categoryService.GetFormattedBreadCrumb(item)
});
}
return model;
}

var categories = await _categoryService.GetAllCategories(
categoryName: value,
pageSize: _adminSearchSettings.CategorySizeLimit);
var gridModel = new DataSourceResult
{
Data = await PrepareModel(categories)
};
return Json(gridModel);
}

[HttpGet]
public async Task<IActionResult> Collection(string collectionId)
{
var value = HttpContext.Request.Query["filter[filters][0][value]"].ToString();

async Task<IList<SearchModel>> PrepareModel(IEnumerable<Collection> collections)
{
var model = new List<SearchModel>();
if (!string.IsNullOrEmpty(collectionId))
{
var currentCollection = await _collectionService.GetCollectionById(collectionId);
if (currentCollection != null)
{
model.Add(new SearchModel {
Id = currentCollection.Id,
Name = currentCollection.Name
});
}
}
foreach (var item in collections)
{
if (item.Id != collectionId)
model.Add(new SearchModel {
Id = item.Id,
Name = item.Name
});
}
return model;
}

var collections = await _collectionService.GetAllCollections(
collectionName: value,
pageSize: _adminSearchSettings.CollectionSizeLimit);

var gridModel = new DataSourceResult
{
Data = await PrepareModel(collections)
};
return Json(gridModel);
}

[HttpGet]
public async Task<IActionResult> Brand(string brandId)
{
var value = HttpContext.Request.Query["filter[filters][0][value]"].ToString();

async Task<IList<SearchModel>> PrepareModel(IEnumerable<Brand> brands)
{
var model = new List<SearchModel>();
if (!string.IsNullOrEmpty(brandId))
{
var currentBrand = await _brandService.GetBrandById(brandId);
if (currentBrand != null)
{
model.Add(new SearchModel {
Id = currentBrand.Id,
Name = currentBrand.Name
});
}
}

model.AddRange(from item in brands where item.Id != brandId select new SearchModel { Id = item.Id, Name = item.Name });
return model;
}
var brands = await _brandService.GetAllBrands(
brandName: value,
pageSize: _adminSearchSettings.BrandSizeLimit);
var gridModel = new DataSourceResult
{
Data = await PrepareModel(brands)
};
return Json(gridModel);
}
}
}
36 changes: 0 additions & 36 deletions src/Web/Grand.Web.Vendor/Models/Catalog/ProductAttributeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,6 @@

namespace Grand.Web.Vendor.Models.Catalog
{
public class ProductAttributeModel : BaseEntityModel, ILocalizedModel<ProductAttributeLocalizedModel>, IStoreLinkModel
{
public ProductAttributeModel()
{
Locales = new List<ProductAttributeLocalizedModel>();
}

[GrandResourceDisplayName("Vendor.Catalog.Attributes.ProductAttributes.Fields.Name")]
public string Name { get; set; }

[GrandResourceDisplayName("Vendor.Catalog.Attributes.ProductAttributes.Fields.SeName")]
public string SeName { get; set; }

[GrandResourceDisplayName("Vendor.Catalog.Attributes.ProductAttributes.Fields.Description")]
public string Description { get; set; }

//Store acl
[GrandResourceDisplayName("Vendor.Catalog.Categories.Fields.LimitedToStores")]
[UIHint("Stores")]
public string[] Stores { get; set; }

public IList<ProductAttributeLocalizedModel> Locales { get; set; }

#region Nested classes

public class UsedByProductModel : BaseEntityModel
{
[GrandResourceDisplayName("Vendor.Catalog.Attributes.ProductAttributes.UsedByProducts.Product")]
public string ProductName { get; set; }
[GrandResourceDisplayName("Vendor.Catalog.Attributes.ProductAttributes.UsedByProducts.Published")]
public bool Published { get; set; }
}

#endregion
}

public class ProductAttributeLocalizedModel : ILocalizedModelLocal
{
public string LanguageId { get; set; }
Expand Down
35 changes: 0 additions & 35 deletions src/Web/Grand.Web.Vendor/Models/Catalog/ProductReviewListModel.cs

This file was deleted.

8 changes: 8 additions & 0 deletions src/Web/Grand.Web.Vendor/Models/Common/SearchModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Grand.Web.Vendor.Models.Common
{
public class SearchModel
{
public string Id { get; set; }
public string Name { get; set; }
}
}
Loading

0 comments on commit 3587775

Please sign in to comment.