logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
judy at Web2Market  
#1 Posted : Monday, November 16, 2020 8:22:50 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
I am getting an error on code I am trying to include from what it was in AC Gold.

Unable to locate persister for the entity named 'AbleCommerce.Code.W2M_SEOManager.W2MSEOContent'.
The persister define the persistence strategy for an entity.
Possible causes:
- The mapping for 'AbleCommerce.Code.W2M_SEOManager.W2MSEOContent' was not added to the NHibernate configuration.

I cannot figure out the issue. I've re-typed, reviewed, had another developer review. I do have another custom entity I was able to add to AC9 in this project and three I was able to add in another project. I have another one I am not able to use in this project- similar persister error. Can you see what the issue is? I do have the hbm.xml set as an Embedded Resource.
Windsor.config:
<component id="W2MSEOContentRepo" service="AbleCommerce.Code.W2M_SEOManager.IW2MSEOContentRepository, AbleCommerce" type="AbleCommerce.Code.W2M_SEOManager.W2MSEOContentRepository, AbleCommerce"/>

NHibernate.config:
<mapping assembly="CommerceBuilder"/>
<mapping assembly="AbleCommerce"/>

Thanks for any help

W2M_SEOManager.zip (2kb) downloaded 3 time(s).

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

judy at Web2Market  
#2 Posted : Monday, November 16, 2020 8:27:08 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Here is the script for the database table- this was from before you all had separate fields for SEO meta stuff, but this site still uses a couple of the fields and I'm upgrading it to AC9.
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[W2MSEOContent](
[Id] [INT] IDENTITY(1,1) NOT NULL,
[CatalogNodeId] [INT] NOT NULL,
[CatalogNodeTypeId] [INT] NOT NULL,
[SEOTitle] [NVARCHAR](200) NULL,
[SEOKeywords] [NVARCHAR](500) NULL,
[ContentOne] [NVARCHAR](1000) NULL,
[ContentTwo] [NVARCHAR](1000) NULL,
[ContentThree] [NVARCHAR](1000) NULL,
[ContentFour] [NVARCHAR](1000) NULL,
[ContentFive] [NVARCHAR](1000) NULL,
CONSTRAINT [PK_W2MSEOContent] PRIMARY KEY CLUSTERED
(
[CatalogNodeId] ASC,
[CatalogNodeTypeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
Joe Payne2  
#3 Posted : Monday, November 16, 2020 8:37:30 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
The namespace 'AbleCommerce.Code' is used in the existing Able /Code/ helper class files. If you're using that also in a compiled class file, that overlap would cause a conflict wouldn't it?
judy at Web2Market  
#4 Posted : Monday, November 16, 2020 12:12:14 PM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
I don't know, Joe. On my 9.0.2 site, I used AbleCommerce.Code and on the class that works in my 9.0.3, I used AbleCommerce.Code. I thought that in the past I had tested and I had to use AbleCommerce.Code to get AC to pick it up. I didn't think AC would pick it up if I used a different namespace and didn't create a plugin. The code on both sites is in subfolders in the Code folder for each entity.
Joe Payne2  
#5 Posted : Monday, November 16, 2020 12:50:12 PM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Hey Judy, I downloaded your project and loaded it into an Able v9.0.3 install with the included windsor and nhibernate config file changes.

You have a syntax error in one of your class files...you're missing a closing semi-colon. It prevented me from doing a build on the AbleCommerce app.

After I fixed that, the solution builds without error and the app spins up without any problems. Where are you getting the persister error?

Capture.JPG (54kb) downloaded 1 time(s).
judy at Web2Market  
#6 Posted : Tuesday, November 17, 2020 5:43:29 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
I must have uploaded the file before I fixed that error. In this case, the no persister error comes when I try to save some content. When I try to load the content, the object is null.
To test, you need to make sure to add to the product controller:
private readonly IW2MSEOContentRepository _seoContentRepo;

public ProductController(....,IW2MSEOContentRepository seoContentRepo)

Add to EditProduct at the end
//TODO doesn't load
W2MSEOContent seoContent = _seoContentRepo.LoadForCatalogNode(editProductModel.Id, 1);

if (seoContent != null)
{
//editProductModel.SEOContentModel.SEOContentOne = seoContent.ContentOne;
//editProductModel.SEOContentModel.SEOContentTwo = seoContent.ContentTwo;
}

Add to ProductDetails
// TODO
/* W2MSEOContent seoContent = _seoContentRepo.LoadForCatalogNode(product.Id, 1);
if (seoContent == null && editProductModel.SEOContentModel.SEOContentOne != null && editProductModel.SEOContentModel.SEOContentTwo != null)
{
seoContent = new W2MSEOContent();
seoContent.CatalogNodeId = product.Id;
seoContent.CatalogNodeTypeId = 1;
_seoContentRepo.Save(seoContent);
}
if (seoContent != null)
{
seoContent.ContentOne = editProductModel.SEOContentModel.SEOContentOne.Trim();
seoContent.ContentTwo = editProductModel.SEOContentModel.SEOContentTwo.Trim();
_seoContentRepo.Save(seoContent);
}*/

In the ProductModel

Add to EditProductModel:
public EditProductSEOContentModel SEOContentModel { get; set; }

public class EditProductSEOContentModel
{
public string SEOContentOne { get; set; }
public string SEOContentTwo { get; set; }
public string SEOContentThree { get; set; }
public string SEOContentFour { get; set; }
public string SEOContentFive { get; set; }
public int CatalogNodeId { get; set; }
public int CatalogNodeTypeId { get; set; }

}

EditProduct view- I added in the Product Description area

<div class="form-group">
<label>SEO Content One</label>
@Html.TextAreaFor(m => m.SEOContentModel.SEOContentOne, new { @class = "form-control" })
</div>
<div class="form-group">
<label>SEO Content Two</label>
@Html.TextAreaFor(m => m.SEOContentModel.SEOContentTwo, new { @class = "form-control" })
</div>

Thanks for looking into this.

Joe Payne2  
#7 Posted : Tuesday, November 17, 2020 7:29:39 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
No problem.

Pretty sure I have it working now. Testing it a few more times before I make it official.
Joe Payne2  
#8 Posted : Tuesday, November 17, 2020 7:55:42 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Ok, first off, thank you for the detailed set up instructions. These MVC changes are a huge pain to document online and you did a great job of it.

First, you know about the syntax bug mentioned previously.

What you're missing are the decorators on your repository class. You need to have these two RegisterFor() decorators added at the top of any class being connected to Windsor/nHibernate. These decorators tell the IOC engine "I'm officially declaring this class to represent this IRepository any time you see it referenced".

Code:

    [RegisterFor(typeof(IW2MSEOContentRepository))]
    [RegisterFor(typeof(IRepository<W2MSEOContent>))]
    public class W2MSEOContentRepository : Repository<W2MSEOContent>, IW2MSEOContentRepository
    {


You also have a bug in your code changes for the EditProductModel. You're basically adding a child class as a property on the model, which is fine. But you never initialize the child class when the model is instantiated. The first time you try to reference editModel.SEOContentModel.SomeProperty you get a null exception. So at the bottom of the EditProductModel, you have to do this:

Code:

        public EditProductModel()
        {
            SelectedProductGroupId = new List<int>();
            RedirectUrl = true;
            SEOContentModel = new EditProductSEOContentModel();
        }


Also, make sure your .hbm.xml file is set as Embedded Resource in the project. Even though it's in the /Code/ folder, it'll still only be treated as content until you specifically mark it as embedded resource.

Finally, it helps a lot to splice your customizations into sub-folders away from all the Able code. Their class files are massive. It's just stupid to have every single model or action method in one massive, single class file. They should all be split into separate files to make it easier on devs. So what I do is make a /Controllers/Custom/ folder, edit the original controller to be 'partial' and put my custom actions in a separate file. Same thing for models too. Works both in Admin and retail side. Huge help having customizations in separate files. Obviously won't work in every instance, but anything helps.
judy at Web2Market  
#9 Posted : Tuesday, November 17, 2020 2:14:41 PM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Thank you for your help, Joe. I will try all this in the morning. It's weird because the three other entities I did don't have the RegisterFor decoration, but I'll do anything that will make it work!
judy at Web2Market  
#10 Posted : Wednesday, November 18, 2020 11:26:03 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Thanks again for your help. I've made the changes you had posted and am still getting the no persister error. I get a null error when I try to load in the EditProduct section of the ProductController, even after I added all the code and made sure I had the hbm.xml set as embedded resource.
Here's where I try to load:
W2MSEOContent seoContent = _seoContentRepo.LoadForCatalogNode(editProductModel.Id, 1);

if (seoContent != null)
{
editProductModel.SEOContentModel.SEOContentOne = seoContent.ContentOne;
editProductModel.SEOContentModel.SEOContentTwo = seoContent.ContentTwo;
}

I get null for seoContent. If I hard code in W2MSEOContent seoContent = _seoContentRepo.Load(139), where 139 is the Id of an entry in the database, I get the persister error.
If I try to save the content, I get the persister error.(SEOContentOne has a value)
in ProductDetails:
W2MSEOContent seoContent = _seoContentRepo.LoadForCatalogNode(product.Id, 1);
if (seoContent == null && (editProductModel.SEOContentModel.SEOContentOne != null || editProductModel.SEOContentModel.SEOContentTwo != null))
{
seoContent = new W2MSEOContent();
seoContent.CatalogNodeId = product.Id;
seoContent.CatalogNodeTypeId = 1;
_seoContentRepo.Save(seoContent);
}
if (seoContent != null)
{
seoContent.ContentOne = editProductModel.SEOContentModel.SEOContentOne.Trim();
seoContent.ContentTwo = editProductModel.SEOContentModel.SEOContentTwo.Trim();
_seoContentRepo.Save(seoContent);
}

if (clearChangeset)
product.Changesets.Clear();

Did you make an entry in windsor.config as well as the RegisterFor? I have.


namespace AbleCommerce.Code.W2M_SEOManager
{
[RegisterFor(typeof(IW2MSEOContentRepository))]
[RegisterFor(typeof(IRepository<W2MSEOContent>))]
public class W2MSEOContentRepository : Repository<W2MSEOContent>, IW2MSEOContentRepository

Thanks again.
Joe Payne2  
#11 Posted : Thursday, November 19, 2020 6:54:10 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Ok, let's walk through it together from the beginning.

First, make sure your /app_data/windsor.config looks like this:

Code:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <components>
	<!--
	Define your custom service implementations here. For example if you have 
	a custom coupon calculator implementation, you can define it here like this
	<component id="MyCouponCalculator" service="CommerceBuilder.Services.ICouponCalculator, CommerceBuilder" type="MyCustomNamespace.MyCouponCalculator, MyCustomAssembly"/>
	-->
  <component id="W2MSEOContentRepo" service="AbleCommerce.Code.W2M_SEOManager.IW2MSEOContentRepository, AbleCommerce" type="AbleCommerce.Code.W2M_SEOManager.W2MSEOContentRepository, AbleCommerce"/>
  </components>
</configuration>


Next, check your /app_data/nhibernate.config and make sure you've referenced the ablecommerce assembly:

Code:

    <property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
    <mapping assembly="CommerceBuilder"/>
    <mapping assembly="AbleCommerce"/>


Now, in the /Code/ folder, I put your stuff in a sub-folder called 'W2M_SEOManager' so make a /Code/W2M_SEOManager/ folder and move your four files to there

Next, make sure all the files are included in your visual studio solution. I've seen it where they are greyed out, and you have to right-click and say 'Include in Project'.

Next, make sure you click on the .hbm.xml file and in the properties set it to embedded resource.

Finally, check your repository class and make sure you have the two decorators at the start of the class:

Code:

namespace AbleCommerce.Code.W2M_SEOManager
{
    [RegisterFor(typeof(IW2MSEOContentRepository))]
    [RegisterFor(typeof(IRepository<W2MSEOContent>))]
    public class W2MSEOContentRepository : Repository<W2MSEOContent>, IW2MSEOContentRepository
    {
    }
}


Recompile the solution. And then check the /bin/ folder to make sure ablecommerce.dll got replaced and the date/time for the file has updated to reflect you just recompiled it.
Joe Payne2  
#12 Posted : Thursday, December 3, 2020 5:24:42 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Judy did you ever get this working?
judy at Web2Market  
#13 Posted : Thursday, December 3, 2020 6:20:25 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
No, I didn't. I was getting ready to circle around to it again. I had to stop to make other progress so our design implementer could start work.
Joe Payne2  
#14 Posted : Thursday, December 3, 2020 6:33:29 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
No problem. Just let me know if you want to do a quick screen share - happy to help you through it.
judy at Web2Market  
#15 Posted : Tuesday, December 15, 2020 7:13:54 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 286

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Well, I reactivated all the code I had commented out and it worked this time! I must have missed something the last time. Thanks so much for your help, Joe.
Joe Payne2  
#16 Posted : Tuesday, December 15, 2020 8:04:45 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Hey I'm so good at this MVC stuff now I don't even have to touch it and it starts working! :)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.