VevoCart Options In-Stock Mod

I’ve been playing around with Vevocart for a while and there’s something I felt was missing. To be able to show the stock level of individual options.

So if you’re selling Tshirts, in the drop down, it’ll say something like:

Small - 12
Medium (SOLD OUT)
Large - 8
X-Large - 3

This way the customer knows right away if the size they want is available or not BEFORE they try to add it to their cart. =)

Please keep in mind that I’m a VB.NET guy. This is my first time playing around with C# and with this apps code, so there may be a better way, but it’s working for me.

Hope it helps someone else out!

.: Adam

Here’s what I modded:

Made a new class file: /App_Code/GlobalFunctions.cs ::

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;

///


/// Summary description for GlobalFunctions
///

namespace Adam
{
public class GlobalFunctions
{

public static DataSet GetDataFromSQL(string strDBName, string strSQL)
{
string strConn = ConfigurationManager.ConnectionStrings[strDBName].ConnectionString;
SqlConnection objConn = new SqlConnection();
objConn.ConnectionString = strConn;
SqlDataAdapter objAdapter = new SqlDataAdapter();
SqlCommand objCommand = new SqlCommand();
DataSet myDataSet = new DataSet();

objCommand.Connection = objConn;
objCommand.CommandText = strSQL;
objAdapter.SelectCommand = objCommand;
objAdapter.Fill(myDataSet, strDBName);
objAdapter.Dispose();
objConn.Close();
objConn.Dispose();

return myDataSet;
}
}
}

/Components/OptionItemDetails.ascx.cs ::

Add ProductID to the variables being sent to the function

Line 174: uxOptionDropDownItem.SetUpDropDown( table, ProductID );

/Components/OptionDropDownItem.ascx.cs ::

Replace class SetUpDropDown with the following code:

public void SetUpDropDown( DataTable table, string ProductID )
{
int i = 0;
int intOptionID = 0;
string strOptionValue = “”;
string strValue = “”;

foreach (DataRow dRow in table.Rows)
{
// Get the option ID
intOptionID = Convert.ToInt32(table.Rows[i][0].ToString());

// Get the option value
strOptionValue = table.Rows[i][7].ToString();

DataSet ds = new DataSet();
string strSQL = “select ProductStock.Stock”;
strSQL += ” FROM ProductStock”;
strSQL += ” LEFT JOIN OptionCombination”;
strSQL += ” ON ProductStock.OptionCombinationID = OptionCombination.OptionCombinationID”;
strSQL += ” WHERE ProductStock.ProductID=” + ProductID + ” AND OptionCombination.ProductOptionItemID=” + intOptionID;
strSQL += ” ORDER BY OptionCombination.ProductOptionItemID”;

ds = Adam.GlobalFunctions.GetDataFromSQL(”MainConnection”, strSQL);
if (ds.Tables[0].Rows.Count > 0)
{
strValue = ds.Tables[0].Rows[0]["Stock"].ToString();
}

// Update the value and insert into table
if (strValue == “0″)
{
strValue = ” (SOLD OUT)”;
}
else
{
strValue = ” - ” + strValue;
}
table.Rows[i][7] = strOptionValue + strValue;

// Increment
i++;
}

uxOptionDrop.DataSource = table;
uxOptionDrop.DataBind();

uxOptionDrop.Items.Insert(0, new ListItem(” — Please Select — “, String.Empty));
}


Leave a Reply