Cant able to Display Product Catalog Group and Product Catalog while creating through programmatically
I'm trying to create Product Catalog Group ,Product Catalog,Category and Product through programmatically using API,I am able to store these details in data base,but these details is not displaying in uCommerce site. What am I missing here?
Are they not showing up in the backend or the frontend?
When dealing with the backend remember that everything has permissions assigned to them. If the user logged into the backend doesn't have permission to see a particular store or catalog they'll not show up.
You can assign permissions to new objects by using the RoleService class like so:
var roleService = ObjectFactory.Instance.Resolve<IRoleService>();
var roles = roleService.GetAllRoles().ToList().Where(x => x.Allows(entity)); // Assigns to current user, but you can look up any user using the IUserService
roleService.AddUserToRoles(securityService.GetCurrentUser(), roles.ToList());
I've created a new ProductCatalog (using the API), and looking in the uCommerce_ProductCatalog table, it's there and just like the default one. So is there something else I should create to make this catalog visible in the back-office uCommerce tree? And i tried with above sample code assign permissions to new objects ,now am able to diplay the Product Catalog Group ,but not the Product catlog.
Below is the my code details,please suggest what am I missing here
var productCatalogGroup = new ProductCatalogGroup { Name = dr[DataTableColumnName.ProductCatalogGroup].ToString().Trim(), EmailProfile = emailProfileId, Currency = currencyId, Deleted = false, OrderNumberSerie = ordernumberId }; if (productCatalogGroupExists == null) { productCatalogGroup.Save(); } // Saving Product Catalog var priceGroupId = PriceGroup.SingleOrDefault(x => x.Name == "EUR 15 pct"); var productCatalogGroupToSave = ProductCatalogGroup.SingleOrDefault(x => x.Name == dr[DataTableColumnName.ProductCatalogGroup].ToString().Trim() && x.Deleted == false); var productCatalogExists = ProductCatalog.SingleOrDefault(x => x.Name == dr[DataTableColumnName.ProductCatalog].ToString().Trim() && x.Deleted == false && x.ProductCatalogGroupId == productCatalogGroupToSave.ProductCatalogGroupId); var productCatalog = new ProductCatalog { Name = dr[DataTableColumnName.ProductCatalog].ToString().Trim(), ProductCatalogGroup = productCatalogGroupToSave, PriceGroup = priceGroupId, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, DisplayOnWebSite = false, Deleted = false }; if (productCatalogExists == null) { productCatalog.Save(); } IRoleService roleService = ObjectFactory.Instance.Resolve<IRoleService>(); IUserService userservice = ObjectFactory.Instance.Resolve<IUserService>(); SecurityService securityService = new SecurityService(roleService, userservice); var roles = roleService.GetAllRoles().ToList().Where(x => x.Allows(productCatalogGroup)); var roles1 = roleService.GetAllRoles().ToList().Where(x => x.Allows(productCatalog));
I'm working on doing a bulk import,I've got the import working, creating categories etc. (they're in the database), but nothing new shows up in the tree in the uCommerce section, even after restarting the site .
What could I be missing? I've created a new ProductCatalog (using the API), and looking in the uCommerce_ProductCatalog table, it's there and just like the default one. So is there something else I should create to make this catalog visible in the back-office uCommerce tree?
As u said this issue can be solved by setting permissions to new objects by using the RoleService class,i did the same thing and now am able to see the ProductCatlogGroup,but still it is not displaying ProductCatalog and other child node...
In this below code insteated of entity i passed ProductCatlogGroup object,plz suggest what can i do for ProductCatalog and other child node ,and what is this entity here?
var roleService =ObjectFactory.Instance.Resolve<IRoleService>(); var roles = roleService.GetAllRoles().ToList().Where(x => x.Allows(entity)); // Assigns to current user, but you can look up any user using the IUserService roleService.AddUserToRoles(securityService.GetCurrentUser(), roles.ToList());
You need to assign permissions to both the store and the catalog to have them show up in the backend.
Currently the code only assigns permissions to a single user. If you don't want to worry about permissions at all you can assign permission to the new objects to all users like so:
var roleService = ObjectFactory.Instance.Resolve<IRoleService>();
var userService = ObjectFactory.Instance.Resolve<IUserService>();
// Grab all users so we can assign new permissions // to everyone.
var users = userService.GetAllUsers();
// Grab any roles for catalog and catalog group
var rolesForCatalogAndCatalogGroup = roleService.GetAllRoles().ToList().Where(x => x.Allows(catalog) || x.Allows(catalogGroup));
// Assigns permission to roles to every user
foreach (var user in users)
{
roleService.AddUserToRoles(user, rolesForCatalogAndCatalogGroup.ToList());
}
A different approach is to disable the securty system altogether. uCommerce 3 has a option to turn it off, but for version 2 you need to override the ISecurityService. Basically what you do is implement a different version of ISecurityService that always allows the user to see objects and always returns true when UserIsInRole is called.
When you're done with the service you need to register it in the the components.config file replacing the existing version.
Cant able to Display Product Catalog Group and Product Catalog while creating through programmatically
I'm trying to create Product Catalog Group ,Product Catalog,Category and Product through programmatically using API,I am able to store these details in data base,but these details is not displaying in uCommerce site. What am I missing here?
Hi Sasmita,
Are they not showing up in the backend or the frontend?
When dealing with the backend remember that everything has permissions assigned to them. If the user logged into the backend doesn't have permission to see a particular store or catalog they'll not show up.
You can assign permissions to new objects by using the RoleService class like so:
Thanks a lot Soren for replying me.I am not able to display it on frontend ,but am able store in backend
Below is the my code details,please suggest what am I missing here
The frontend does not enforce permissions so you can safely disregard my reply on setting permissions programatically.
Could you check whether the "Deleted" property of the objects you are creating is set to true or false. (You want it to be false for it to show up).
Also are you using Razor or XSLT to create the frontend?
Hi Soren,
I'm working on doing a bulk import,I've got the import working, creating categories etc. (they're in the database), but nothing new shows up in the tree in the uCommerce section, even after restarting the site .
What could I be missing? I've created a new ProductCatalog (using the API), and looking in the uCommerce_ProductCatalog table, it's there and just like the default one. So is there something else I should create to make this catalog visible in the back-office uCommerce tree?
As u said this issue can be solved by setting permissions to new objects by using the RoleService class,i did the same thing and now am able to see the ProductCatlogGroup,but still it is not displaying ProductCatalog and other child node...
In this below code insteated of entity i passed ProductCatlogGroup object,plz suggest what can i do for ProductCatalog and other child node ,and what is this entity here?
var roleService =ObjectFactory.Instance.Resolve<IRoleService>();
var roles = roleService.GetAllRoles().ToList().Where(x => x.Allows(entity));
// Assigns to current user, but you can look up any user using the IUserService
roleService.AddUserToRoles(securityService.GetCurrentUser(), roles.ToList());
Thanks,
Sasmita
You can do the same for product catalog.
You need to assign permissions to both the store and the catalog to have them show up in the backend.
Currently the code only assigns permissions to a single user. If you don't want to worry about permissions at all you can assign permission to the new objects to all users like so:
Hi Soren,
I did the same thing for Product Catlog,still am not able to make catalog visible in the back-office uCommerce tree,plz any other suggestions?
Thanks
Sasmita
Is the code running without any exceptions?
Does the product catalog have a ProductCatalogGroup set on it?
Could you check umbracoLog for any errors?
Hi Soren,
Yes code is running without any exceptions and product catalog have a ProductCatalogGroup on it.Yes i checked umbracoLog,there is no error.
Thanks
Sasmita
A different approach is to disable the securty system altogether. uCommerce 3 has a option to turn it off, but for version 2 you need to override the ISecurityService. Basically what you do is implement a different version of ISecurityService that always allows the user to see objects and always returns true when UserIsInRole is called.
When you're done with the service you need to register it in the the components.config file replacing the existing version.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.