4.30 Plugin with Data Access

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 năm cách đây
I need to be able to access product data in my plugin and copy that data to an external database table. Can anyone point me to a good example?  

Thank you
3 năm cách đây
The Nop.Plugin.Shipping.FixedByWeightByTotal and Nop.Plugin.Pickup.PickupInStore both use Data Access.
Also See https://docs.nopcommerce.com/en/developer/plugins/plugin-with-data-access.html
3 năm cách đây
I have following error when I try out this example. I can't figure out what I did wrong

Severity  Code  Description  Project  File  Line  Suppression State
Error  CS0308  The non-generic method 'IColumnOptionSyntax<ICreateTableColumnOptionOrWithColumnSyntax, ICreateTableColumnOptionOrForeignKeyCascadeOrWithColumnSyntax>.ForeignKey(string, string)' cannot be used with type arguments  Nop.Plugin.Other.ProductViewTracker  D:\VS2019\nopCommerce430Dev\Plugins\Nop.Plugin.Other.ProductViewTracker\Data\ProductViewTrackerRecordBuilder.cs  21  Active

using FluentMigrator.Builders.Create.Table;
using Nop.Data.Mapping.Builders;
using Nop.Core.Domain.Customers;
using Nop.Plugin.Other.ProductViewTracker.Domain;
using System.Data;
using Nop.Core.Domain.Catalog;

namespace Nop.Plugin.Other.ProductViewTracker.Data
{
    public class ProductViewTrackerRecordBuilder : NopEntityBuilder<ProductViewTrackerRecord>
    {
        /// <summary>
        /// Apply entity configuration
        /// </summary>
        /// <param name="table">Create table expression builder</param>
        public override void MapEntity(CreateTableExpressionBuilder table)
        {
            //map the primary key (not necessary if it is Id field)
            table.WithColumn(nameof(ProductViewTrackerRecord.Id)).AsInt32().PrimaryKey()
            //map the additional properties as foreign keys
            .WithColumn(nameof(ProductViewTrackerRecord.ProductId)).AsInt32().ForeignKey<Product>(onDelete: Rule.Cascade)
            .WithColumn(nameof(ProductViewTrackerRecord.CustomerId)).AsInt32().ForeignKey<Customer>(onDelete: Rule.Cascade)
            //avoiding truncation/failure
            //so we set the same max length used in the product name
            .WithColumn(nameof(ProductViewTrackerRecord.ProductName)).AsString(400)
            //not necessary if we don't specify any rules
            .WithColumn(nameof(ProductViewTrackerRecord.IpAddress)).AsString()
            .WithColumn(nameof(ProductViewTrackerRecord.IsRegistered)).AsInt32();
        }
    }
}
3 năm cách đây
See https://www.nopcommerce.com/en/boards/topic/87270/errorin-nop-commerce-documentation
3 năm cách đây
This error only pops up after I add using FluentMigrator.Builders.Create.Table;
and why does it only cause issue with
.WithColumn(nameof(ProductViewTrackerRecord.ProductId)).AsInt32().ForeignKey<Product>(onDelete: Rule.Cascade)

but not
.WithColumn(nameof(ProductViewTrackerRecord.CustomerId)).AsInt32().ForeignKey<Customer>(onDelete: Rule.Cascade)
3 năm cách đây
I have similar issue, and based on my experience you must be sure that any foreign key is a primary key in reference table also.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.