Rank: Newbie
Groups: Authorized User
Joined: 12/4/2018(UTC) Posts: 8
|
I understand that CustomFields are to be used for more simple applications, but as a Source holder, I figured the process should be ironed out for users to add their own fields to the database if they see fit. This post will contain only excerpts and source I have written. I have created the following custom class, located in a custom version of the CommerceBuilder assembly for use throughout our store.
Code:
namespace CommerceBuilder.Products
{
using System;
/// <summary>
/// Class that contains the physical location of a product
/// </summary>
public class ProductLocation : IComparable, IComparable<ProductLocation>
{
/// <summary>
/// Initializes a new instance of the <see cref="ProductLocation" /> class.
/// </summary>
public ProductLocation()
{
Sector = string.Empty;
Bank = -1;
Position = -1;
}
/// <summary>
/// Gets or sets the Unit in which the Product resides.
/// </summary>
public virtual string Sector { get; set; }
/// <summary>
/// Gets or sets the Row of specified Unit in which the Product resides.
/// </summary>
public virtual int Bank { get; set; }
/// <summary>
/// Gets or sets the Column of specified Row in which the Product resides.
/// </summary>
public virtual int Position { get; set; }
/// <inheritdoc />
public static int Compare(ProductLocation left, ProductLocation right)
{
if (object.ReferenceEquals(left, right))
{
return 0;
}
if (string.IsNullOrEmpty(left.Sector) || left.Bank < 0 || left.Position < 0)
{
left = null;
}
if (left is null)
{
return -1;
}
return left.CompareTo(right);
}
/// <inheritdoc />
public static bool operator ==(ProductLocation left, ProductLocation right)
{
if (left is null)
{
return right is null;
}
return left.Equals(right);
}
/// <inheritdoc />
public static bool operator !=(ProductLocation left, ProductLocation right)
{
return !(left == right);
}
/// <inheritdoc />
public static bool operator <(ProductLocation left, ProductLocation right)
{
return (Compare(left, right) < 0);
}
/// <inheritdoc />
public static bool operator >(ProductLocation left, ProductLocation right)
{
return (Compare(left, right) > 0);
}
/// <inheritdoc />
public int CompareTo(object obj)
{
if (obj == null)
{
return 1;
}
ProductLocation other = obj as ProductLocation;
if (other == null)
{
throw new ArgumentException("A ProductLocation object is required for comparison.", "obj");
}
return CompareTo(other);
}
/// <inheritdoc />
public int CompareTo(ProductLocation other)
{
if (string.IsNullOrEmpty(other.Sector) || other.Bank < 0 || other.Position < 0)
{
other = null;
}
if (other is null)
{
return 1;
}
// If Units are even, compare the rows
// If rows are even, compare on columns
if (this.Sector.CompareTo(other.Sector) == 0)
{
if (this.Bank.CompareTo(other.Bank) == 0)
{
return this.Position.CompareTo(other.Position);
}
else
{
return this.Bank.CompareTo(other.Bank);
}
}
else
{
return this.Sector.CompareTo(other.Sector);
}
}
/// <inheritdoc />
public override bool Equals(object obj)
{
ProductLocation other = obj as ProductLocation;
if (other is null)
{
return false;
}
return this.CompareTo(other) == 0;
}
/// <inheritdoc />
public override int GetHashCode()
{
return Tuple.Create(this.Sector, this.Bank, this.Position).GetHashCode();
}
}
}
To include this field in the database, I have added the following mapping to the product.hbm.xml file.
Code:
<component name="Location" class="CommerceBuilder.Products.ProductLocation, CommerceBuilder">
<property name="Sector" type="string" />
<property name="Bank" type="int" />
<property name="Position" type="int" />
</component>
And the following field to the definition of the Product object, in Product.cs
Code:
/// <summary>
/// Gets or sets the physical Location of this product
/// </summary>
public virtual ProductLocation Location
{
get
{
if (this.Location == null)
{
this.Location = new ProductLocation();
}
return this.Location;
}
set
{
this.Location = (ProductLocation)value;
}
}
The following SQL is used to generate these fields in a (live) database, after a normal, functional upgrade from AC Gold.
Code:
/* ADD Location fields to ac_Products */
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'ac_Products' AND COLUMN_NAME = 'Sector')
BEGIN
ALTER TABLE ac_Products ADD Sector VARCHAR(4) NULL,
Bank INT NULL,
Position INT NULL,
END
GO
Assuming the above is dotting all Is and crossing all Ts, we end up hitting a roadblock. Requests to the Admin and Product listing pages end up timing out, and despite request tracing and logging wizardry of the highest degree, I am unable to narrow down the cause of the page timeout. fr000002.zip (15kb) downloaded 3 time(s). is a Failed Request Log generated as demonstrated here. The Failed Request Log shows the last AspNetPipelineEnter event before erroring out is event 413. regarding CommerceBuilder.Licensing.AbleApplication+a, of which even Source holders have no access to. I would like some assistance as to whether I am barking up the wrong tree here. I have added objects to the database in the past, but component mapping specifically seems to cause issues on our development site. Thank you for your time. Edited by user Tuesday, November 23, 2021 4:07:00 PM(UTC)
| Reason: Clarification of FRL location. They are large files.
|