Skip to content

Commit

Permalink
Final updates for version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
WillStrohl committed Feb 1, 2017
1 parent a0e8c26 commit a12287e
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<dependencies>
<dependency type="CoreVersion">07.04.02</dependency>
</dependencies>
<azureCompatible>true</azureCompatible>

<components>

Expand Down Expand Up @@ -55,8 +56,8 @@
</component>
<component type="Assembly">
<assemblies>
<basePath>bin</basePath>
<assembly>
<path>bin</path>
<name>Hotcakes.Modules.AdjustReservedInventoryModule.dll</name>
</assembly>
</assemblies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@
<value>Product Name</value>
</data>
<data name="ProductsFound.Text" xml:space="preserve">
<value>Yikes! Some products were found with reserved inventory associated with at least one cancelled order.</value>
<value>Whoops! Some products were found with reserved inventory associated with at least one cancelled order.</value>
</data>
<data name="Sku.Header" xml:space="preserve">
<value>Product SKU</value>
</data>
<data name="VariantId.Header" xml:space="preserve">
<value>Variant ID</value>
</data>
</root>
15 changes: 6 additions & 9 deletions Modules/AdjustReservedInventoryModule/View.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@
<asp:Panel id="pnlProductList" runat="server">
<div class="dnnFormMessage dnnFormValidationSummary"><%=GetLocalizedString("ProductsFound") %></div>
<div class="dnnClear">
<asp:GridView id="grdProducts" AutoGenerateColumns="false"
CssClass="dnnGrid" DataKeyNames="Bvin" Width="100%" runat="server">
<asp:GridView id="grdProducts" AutoGenerateColumns="false"
CssClass="dnnGrid" DataKeyNames="Id" Width="100%" runat="server">
<Columns>
<asp:BoundField DataField="Sku" HeaderText="Sku" />
<asp:BoundField DataField="ProductSku" HeaderText="Sku" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" />
<asp:BoundField DataField="VariantId" HeaderText="VariantId" />
<asp:TemplateField HeaderText="Inventory">
<ItemTemplate>
<%#GetInventoryText(DataBinder.Eval(Container.DataItem, "bvin")) %>
<%#GetInventoryText(DataBinder.Eval(Container.DataItem, "ProductId"), DataBinder.Eval(Container.DataItem, "VariantId")) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<!--
Links to Edit Here
- Reset Reserve to Zero
- Return Cancelled Inventory
-->
<asp:LinkButton OnClick="ResetInventoryReserve" Text="Restore Cancelled Inventory" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
Expand Down
104 changes: 94 additions & 10 deletions Modules/AdjustReservedInventoryModule/View.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using Hotcakes.Commerce;
Expand All @@ -34,6 +35,12 @@

namespace Hotcakes.Modules.AdjustReservedInventoryModule
{
/// <summary>
///
/// </summary>
/// <remarks>
/// Has not been tested against product bundles
/// </remarks>
public partial class View : AdjustReservedInventoryModuleBase
{
#region Private Members
Expand Down Expand Up @@ -67,6 +74,61 @@ protected void Page_Load(object sender, EventArgs e)
}
}

protected void ResetInventoryReserve(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
var sku = grdrow.Cells[0].Text;
var variantId = grdrow.Cells[2].Text;

var product = HccApp.CatalogServices.Products.FindBySku(sku);

var orders = HccApp.OrderServices.Orders.FindAll().Where(o => o.StatusCode == OrderStatusCode.Cancelled);

var lineItems =
HccApp.OrderServices.Orders.FindLineItemsForOrders(orders.ToList()).Where(li => li.ProductId == product.Bvin);

var returnQty = lineItems.Sum(li => li.QuantityReserved);

if (lineItems.Any())
{
// this will need to be done differently in Hotcakes version 2.0 and newer
LineItemRepository repo = null;
repo = Factory.CreateRepo<LineItemRepository>(HccApp.CurrentRequestContext);

foreach (var lineItem in lineItems)
{
lineItem.QuantityReserved = 0;

repo.Update(lineItem);
}
}

List<ProductInventory> inventories = null;

if (string.IsNullOrEmpty(variantId))
{
inventories = HccApp.CatalogServices.ProductInventories.FindByProductId(product.Bvin);
}
else
{
inventories = new List<ProductInventory>
{
HccApp.CatalogServices.ProductInventories.FindByProductIdAndVariantId(product.Bvin, variantId)
};
}

if (inventories != null && inventories.Count > 0)
{
foreach (var inventory in inventories)
{
inventory.QuantityReserved = inventory.QuantityReserved - returnQty;
HccApp.CatalogServices.ProductInventories.Update(inventory);
}
}

Response.Redirect(DotNetNuke.Common.Globals.NavigateURL());
}

#endregion

#region Helper Methods
Expand All @@ -91,9 +153,11 @@ private void ShowProducts(bool hasProducts = true)

private void LoadGrid()
{
//
// this is a broad search, and it should instead include some
// additional criteria to lessen the number of orders returned,
// such as a date range
//
var orders = HccApp.OrderServices.Orders.FindAll().Where(o => o.StatusCode == OrderStatusCode.Cancelled);

if (orders == null || !orders.Any())
Expand All @@ -102,25 +166,28 @@ private void LoadGrid()
return;
}

var products = new List<Product>();
var lineItems = HccApp.OrderServices.Orders.FindLineItemsForOrders(orders.ToList()).Where(li => li.QuantityReserved > 0);
var filteredLineItems = new List<LineItem>();

var lineItems = HccApp.OrderServices.Orders.FindLineItemsForOrders(orders.ToList());
// get a reference to only the products that match the line items we're looking for
var products = HccApp.CatalogServices.Products.FindAllPaged(1, int.MaxValue).Where(product => lineItems.Any(li => li.ProductId == product.Bvin)).ToList();

foreach (var lineItem in lineItems)
{
// determine if the product has inventory mode set to reserve product
var productInList = products.Any(p => p.Bvin == lineItem.ProductId && p.InventoryMode != ProductInventoryMode.AlwayInStock && p.InventoryMode != ProductInventoryMode.NotSet);

if (!productInList)
if (productInList)
{
products.Add(HccApp.CatalogServices.Products.Find(lineItem.ProductId));
filteredLineItems.Add(lineItem);
}
}

if (products.Count > 0)
if (filteredLineItems.Count > 0)
{
ShowProducts();

grdProducts.DataSource = products;
grdProducts.DataSource = filteredLineItems;
grdProducts.DataBind();
}
else
Expand All @@ -129,13 +196,30 @@ private void LoadGrid()
}
}

protected string GetInventoryText(object value)
protected string GetInventoryText(object oBvin, object oVariant)
{
if (value == null) return string.Empty;
if (oBvin == null) return string.Empty;

var bvin = value.ToString();
var bvin = oBvin.ToString();
var variantId = string.Empty;
if (oVariant != null)
{
variantId = oVariant.ToString();
}

List<ProductInventory> inventories = null;

var inventories = HccApp.CatalogServices.ProductInventories.FindByProductId(bvin);
if (string.IsNullOrEmpty(variantId))
{
inventories = HccApp.CatalogServices.ProductInventories.FindByProductId(bvin);
}
else
{
inventories = new List<ProductInventory>
{
HccApp.CatalogServices.ProductInventories.FindByProductIdAndVariantId(bvin, variantId)
};
}

if (inventories == null || inventories.Count == 0)
{
Expand Down

0 comments on commit a12287e

Please sign in to comment.