kavo Project.
create table in DB , add script to database update folder
D:\development\Florette_935_2\DatabaseUpdates
create new hbm or update existing.
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false" namespace="Sana.Commerce.Catalog" assembly="Sana.Commerce.Sdk">
<class name="RelatedProductItems" table="RelatedProductItems"> <id name="Id" type="Guid"> <generator class="guid" /> </id> <property name="WebsiteId" type="string" length="50" not-null="true" /> <property name="CategoryId" type="string" length="50" not-null="false" /> <property name="ProductSetId" type="Guid" length="50" not-null="true" /> </class>
need to set correct name space . else get an error.
eh:Catalog.hbm.xml
namespace="Sana.Commerce.Catalog" <-----
RelatedProductitem.cs
namespace Sana.Commerce.Catalog <--------- { [Serializable] [DataContract(Name = "RelatedProductItem", Namespace = "")] public class RelatedProductItem : IRelatedProductItem { /// <summary> /// Gets or sets the stock range identifier. /// </summary> [IgnoreDataMember] public Guid Id { get; set; } /// <summary> /// Gets or sets the website identifier. /// </summary> [IgnoreDataMember] public string WebsiteId { get; set; } /// <summary> /// Gets or sets the category identifier. /// </summary> [DataMember] public string CategoryId { get; set; } /// <summary> /// Gets or sets the out of stock value. /// </summary> [DataMember] public Guid ProductSetId { get; set; } }
namespace Sana.Commerce.Catalog { /// Ticket 88704: [Kavo] 3.9. PDP – RELATED ITEMS /// <summary> /// Describes related product item. /// </summary> public interface IRelatedProductSet : IIdentityObject { /// <summary> /// Gets or sets the website identifier. /// </summary> string WebsiteId { get; set; } /// <summary> /// Gets or sets the category identifier. /// </summary> string CategoryId { get; set; } /// <summary> /// Gets or sets the Product set id. /// </summary> Guid ProductSetId { get; set; } } }
Top media Ticket 100006: [Topmedia] 3.1. Search – Product Finder
create table on DB
CREATE TABLE [dbo].[ProductTypes]( [Id] [uniqueidentifier] NOT NULL, [WebsiteId] [nvarchar](50) NOT NULL, [Code] [nvarchar](50) NULL, [Name] [nvarchar](100) NULL, CONSTRAINT [PK_ProductTypes] PRIMARY KEY CLUSTERED ( [Id] 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 ALTER TABLE [dbo].[ProductTypes] WITH CHECK ADD CONSTRAINT [FK_ProductTypes_ProductTypes] FOREIGN KEY([Id]) REFERENCES [dbo].[ProductTypes] ([Id]) GO ALTER TABLE [dbo].[ProductTypes] CHECK CONSTRAINT [FK_ProductTypes_ProductTypes] GO
common.hbm.xml
<class name="ProductType" table="ProductTypes" polymorphism="explicit"> <id name="Id" type="Guid"> <generator class="guid" /> </id> <property name="WebsiteId" type="string" length="50" not-null="true" /> <property name="Code" type="string" length="50" not-null="false" /> <property name="Name" type="string" length="100" not-null="false" /> </class>
When u want to get datafrom DB use OfflineCommonProvider
from ERP use ExtendedCommonProvider
How to call these methods . This is calling on General import runing
public class ExtendedSyncTask: SyncTask { protected override void Synchronize() { base.Synchronize(); var offlineCommonProvider = Providers.Offline.Common; var onlineCommonProvider = Providers.Common; // Ticket 100006: [Topmedia] 3.1. Search – Product Finder // Get Prodcuct type data from ERP. var pickupLocations = ((ExtendedCommonProvider)onlineCommonProvider).GetProductTypes(); ((ExtendedOfflineCommonProvider)offlineCommonProvider).DeleteAllProductTypes(); ((ExtendedOfflineCommonProvider)offlineCommonProvider).SaveProductTypes(pickupLocations); taskLog.Add(this, "Saved product types."); } }
Get data from ERP (online)
public class ExtendedCommonProvider : CommonProvider, IExtendedCommonProvider { public virtual IList<IProductType> GetProductTypes() { var request = new List<XElement>(); var result = ExecuteRequest("GetProductTypes", request); var productTypes = result.Elements("ProductType").Select(e => ((ExtendedCommonXmlParser)Parser).ParseProductType(e)).ToList(); foreach (var item in productTypes) { item.WebsiteId = Context.WebsiteId; } return productTypes; } }
get data from DB offline
public class ExtendedOfflineCommonProvider : OfflineCommonProvider, IExtendedCommonProvider { /// Ticket 100006: [Topmedia] 3.1. Search – Product Finder /// <summary> /// Delete all product types. /// </summary> public virtual void DeleteAllProductTypes() { WrapDataAccessException(() => { using (var sm = CreateSessionManager(false)) { var productTypes = GetProductTypes(); foreach (var productType in productTypes) { sm.Session.Delete(productType); } sm.Commit(); } }, "Cannot delete pickup locations for {0} website".FormatWith(Context.WebsiteId)); } /// Ticket 100006: [Topmedia] 3.1. Search – Product Finder /// <summary> /// Get product types. /// </summary> /// <returns></returns> public virtual IList<IProductType> GetProductTypes() { using (var sm = CreateSessionManager(true)) { var productTypes = sm.Session.CreateCriteria(GetRegisteredType<IProductType>()) .Add(NHibernate.Criterion.Restrictions.Eq("WebsiteId", CommerceFrameworkBase.Context.WebsiteId)) .List<IProductType>(); return productTypes; } } /// Ticket 100006: [Topmedia] 3.1. Search – Product Finder /// <summary> /// Save product types. /// </summary> /// <param name="productTypes"></param> public virtual void SaveProductTypes(IList<IProductType> productTypes) { WrapDataAccessException(() => { using (var sm = CreateSessionManager(false)) { productTypes.Each(c => sm.Session.SaveOrUpdate(c)); sm.Commit(); } }, "Cannot save pickup location"); } }