Code: Select all
SELECT *
FROM ac_Products
WHERE Sku LIKE @sku OR @sku LIKE Sku+'%'
Code: Select all
SELECT *
FROM ac_Products
WHERE Sku LIKE @sku OR @sku LIKE Sku+'%'
Code: Select all
[DataObjectMethod(DataObjectMethodType.Select)]
public static IList<ProductInventoryDetailExt> GetInventoryBySku(string sku, int maximumRows = 0, int startRowIndex = 0, string sortExpression = "")
{
if (string.IsNullOrEmpty(sku))
return new List<ProductInventoryDetailExt>();
//First check for matching variant
IList<ProductInventoryDetailExt> inventoryDetails = NHibernateHelper.CreateCriteria<ProductVariant>("PV", maximumRows, startRowIndex, string.Empty)
.CreateCriteria("Product", "P", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.Eq("PV.Sku", sku))
.Add(Restrictions.Eq("P.InventoryModeId", (byte)InventoryMode.Variant))
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("P.Id"), "ProductId")
.Add(Projections.Property("P.Name"), "Name")
.Add(Projections.Property("PV.Id"), "ProductVariantId")
.Add(Projections.Property("PV.VariantName"), "VariantName")
.Add(Projections.Property("PV.InStock"), "InStock")
.Add(Projections.Property("PV.Sku"), "Sku"))
.SetResultTransformer(Transformers.AliasToBean(typeof(ProductInventoryDetailExt)))
.List<ProductInventoryDetailExt>();
//If there were no matches, it is either a dynamic variant sku or a product base sku
//Start with exact matches for a product base sku
if (inventoryDetails.Count == 0)
{
inventoryDetails = NHibernateHelper.CreateCriteria<Product>(maximumRows, startRowIndex, string.Empty)
.Add(Restrictions.Eq("Sku", sku))
.Add(Restrictions.Eq("InventoryModeId", (byte)InventoryMode.Product))
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("Id"), "ProductId")
.Add(Projections.Property("Name"), "Name")
.Add(Projections.Property("InStock"), "InStock")
.Add(Projections.Property("Sku"), "Sku"))
.SetResultTransformer(Transformers.AliasToBean(typeof(ProductInventoryDetailExt)))
.List<ProductInventoryDetailExt>();
}
//If still no matches, it might be a dynamic variant sku
//We need to do a reverse match on the product base sku
//then load up the variant manager and attempt to locate
//a matching variant sku. This will be slow.
if (inventoryDetails.Count == 0)
{
IList<int> productIds = NHibernateHelper.CreateSQLQuery(
"SELECT ProductId" +
" FROM ac_Products" +
" WHERE :sku LIKE Sku+'%'" +
" AND InventoryModeId = :mode"
).SetString("sku", sku)
.SetByte("mode", (byte)InventoryMode.Variant)
.List<int>();
int index = 0;
foreach (int id in productIds)
{
if (inventoryDetails.Count >= maximumRows)
break;
ProductVariantManager pvm = new ProductVariantManager(id);
IEnumerable<ProductVariant> matchingVariants = pvm.LoadVariantGrid().Where(v => v.Sku == sku);
foreach (ProductVariant variant in matchingVariants)
{
if (inventoryDetails.Count >= maximumRows)
break;
if (index >= startRowIndex)
{
ProductInventoryDetailExt detail = new ProductInventoryDetailExt();
detail.Sku = variant.Sku;
detail.ProductId = variant.ProductId;
detail.Name = variant.Product.Name;
detail.ProductVariantId = variant.Id;
detail.VariantName = variant.VariantName;
detail.InStock = variant.InStock;
inventoryDetails.Add(detail);
}
++index;
}
}
}
SortResults(inventoryDetails, sortExpression);
return inventoryDetails;
}
This was almost 2.5 years ago. Has this feature been added yet?Our SQL Criteria search provider will have this ability in next version
I know why it was changed. It happened in Gold R4 (issue AC8-1679). This is a summary of the issue:the records should be written to the table as soon as they're generated.
You mean in general? Or in terms of other potential issues created by variants not being persisted?Katie wrote:Joe, is there anything besides search by variant SKU that is a known issue?