Page 1 of 1
kit and show variants in stock
Posted: Tue Apr 07, 2009 3:11 am
by lars-erik
Regarding kits.
I want to display items in stock at each variant.
Now, in the radiobuttonlist / dropdown list, it displays only "2 GB Dual Channel DDR2 SDRAM at 667MHz- 2DIMMs - (kr 0.00)" .
I want to display: "2 GB Dual Channel DDR2 SDRAM at 667MHz- 2DIMMs - (kr 0.00) - 12 items in stock"
Is this possible? Where ?
Do I need to buy the source code?
Re: kit and show variants in stock
Posted: Tue Apr 07, 2009 6:07 am
by mazhar
No need to buy source for this change. Try following fix
Go to following method
Code: Select all
public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
in
App_Code/ProductHelper.cs class and locate following code lines
Code: Select all
if (o != null)
{
Type oType = o.GetType();
if (oType.Equals(typeof(RadioButtonList)))
{
((RadioButtonList)o).AutoPostBack = true;
}
else if (oType.Equals(typeof(DropDownList)))
{
((DropDownList)o).AutoPostBack = true;
}
else if (oType.Equals(typeof(CheckBoxList)))
{
((CheckBoxList)o).AutoPostBack = true;
}
phOptions.Controls.Add(o);
// SEE WHETHER A VALID VALUE FOR THIS FIELD IS PRESENT IN FORM POST
List<int> theseOptions = component.GetControlValue(o);
selectedChoices.AddRange(theseOptions);
}
and replace them with below code block
Code: Select all
if (o != null)
{
Type oType = o.GetType();
if (oType.Equals(typeof(RadioButtonList)))
{
((RadioButtonList)o).AutoPostBack = true;
RadioButtonList rbl = ((RadioButtonList)o);
foreach (KitProduct kitProduct in component.KitProducts)
{
ListItem listItem = rbl.Items.FindByValue(kitProduct.KitProductId.ToString());
if (listItem != null)
listItem.Text += string.Format("- {0} item{1} in stock", kitProduct.Product.InStock,(kitProduct.Product.InStock > 1)?"s":string.Empty);
}
}
else if (oType.Equals(typeof(DropDownList)))
{
((DropDownList)o).AutoPostBack = true;
DropDownList ddl = ((DropDownList)o);
foreach (KitProduct kitProduct in component.KitProducts)
{
ListItem listItem = ddl.Items.FindByValue(kitProduct.KitProductId.ToString());
if (listItem != null)
listItem.Text += string.Format("- {0} item{1} in stock", kitProduct.Product.InStock, (kitProduct.Product.InStock > 1) ? "s" : string.Empty);
}
}
else if (oType.Equals(typeof(CheckBoxList)))
{
((CheckBoxList)o).AutoPostBack = true;
CheckBoxList chkl = ((CheckBoxList)o);
foreach (KitProduct kitProduct in component.KitProducts)
{
ListItem listItem = chkl.Items.FindByValue(kitProduct.KitProductId.ToString());
if (listItem != null)
listItem.Text += string.Format("- {0} item{1} in stock", kitProduct.Product.InStock, (kitProduct.Product.InStock > 1) ? "s" : string.Empty);
}
}
phOptions.Controls.Add(o);
// SEE WHETHER A VALID VALUE FOR THIS FIELD IS PRESENT IN FORM POST
List<int> theseOptions = component.GetControlValue(o);
selectedChoices.AddRange(theseOptions);
}
Re: kit and show variants in stock
Posted: Tue Apr 07, 2009 6:38 am
by lars-erik
Yes, that works if inventory tracking is set to Track Products, but it displays "0 items in stock" if the inventory tracking is set to "Track Variants". (E.g. against the t-shirts)
And I have double checked that stock is set >0 on the variants.
Please, help me. I am almost there now...
Re: kit and show variants in stock
Posted: Tue Apr 07, 2009 7:44 am
by mazhar
Re: kit and show variants in stock
Posted: Tue Apr 07, 2009 7:57 am
by lars-erik
Thank's for the links regarding multilanguage.
But can you still help me with showing stocks for variants. (I just changed my previous post when I discovered that it shows "0 items in stock" when an option in a kit is mapped to a variant in another product. (e.g. mapping to Male, Large in the shirt product).
Re: kit and show variants in stock
Posted: Wed Apr 08, 2009 8:46 am
by mazhar
You can update the
if statement as below to take care of product variants as well
Code: Select all
if (listItem != null)
{
if(kitProduct.ProductVariant != null)
listItem.Text += string.Format("- {0} item{1} in stock", kitProduct.ProductVariant.InStock, (kitProduct.ProductVariant.InStock > 1) ? "s" : string.Empty);
else
listItem.Text += string.Format("- {0} item{1} in stock", kitProduct.Product.InStock, (kitProduct.Product.InStock > 1) ? "s" : string.Empty);
}
Re: kit and show variants in stock
Posted: Fri Apr 10, 2009 2:07 am
by lars-erik
Great ! Thank you.
I have a proposal for improvement for the next version:
E.g. take the t-shirt in demo (presented as an ordinary product, not kit), this comes in sizes (small,large...) and gender (male,female).
Now then, instead of selecting from two drop-down-list (gender and size), let the user select from a single drop-down-list/radio-buttons. Like this:
* Male, Small, 2 items in stock
* Male, Large, 4 items in stock
...
* Female, Small, Out of stock. Approx. 3 weeks of delivery time.
* Female, Medium, 1 item in stock.
..
This will show the currrent stock to the user immediately - he doesn't need to select from two different combos in order to make the "out-of-stock-message" appear.
If backorders are not allowed, the variant combination should not appear at all.
If backorders are allowed, an approximately delivery time should be showed to the user (e.g. 3 weeks of delivery time). This should be given at each product.
The only way to solve this today, is to use kits and putting the delivery time into one of the existing field (e.g. at end of the SKU separated by a semi-colon).
You should consider this, I have seen a lot of norwegian shopping systems that has this functionality.
Re: kit and show variants in stock
Posted: Fri Apr 10, 2009 4:49 am
by mazhar
lars-erik wrote:Great ! Thank you.
I have a proposal for improvement for the next version:
E.g. take the t-shirt in demo (presented as an ordinary product, not kit), this comes in sizes (small,large...) and gender (male,female).
Now then, instead of selecting from two drop-down-list (gender and size), let the user select from a single drop-down-list/radio-buttons. Like this:
* Male, Small, 2 items in stock
* Male, Large, 4 items in stock
...
* Female, Small, Out of stock. Approx. 3 weeks of delivery time.
* Female, Medium, 1 item in stock.
..
This will show the currrent stock to the user immediately - he doesn't need to select from two different combos in order to make the "out-of-stock-message" appear.
If backorders are not allowed, the variant combination should not appear at all.
If backorders are allowed, an approximately delivery time should be showed to the user (e.g. 3 weeks of delivery time). This should be given at each product.
The only way to solve this today, is to use kits and putting the delivery time into one of the existing field (e.g. at end of the SKU separated by a semi-colon).
You should consider this, I have seen a lot of norwegian shopping systems that has this functionality.
If you think this is something helpful you can create a poll in feature request forum.
Re: kit and show variants in stock
Posted: Fri Apr 10, 2009 5:32 am
by jmestep
You could do the dual options now by making the option a combination of the size and color instead of separate fields.
Re: kit and show variants in stock
Posted: Mon May 25, 2009 4:32 am
by lars-erik
Can the same thing be achieved with non-kit products with a 1-dimension variant ?
I sell shoes, and want to display the available sizes in stock in the text in the drop-down-list. I DON'T want the customer to be notified with a "out-of-stock" message after the shoe size is selected.
E.g.
Shoe,
the text in the drop-down-list:
Choose size:
<42, 12 items in stock>
<43, no items in stock>
Is this possible?
Re: kit and show variants in stock
Posted: Mon May 25, 2009 5:45 am
by mazhar
Edit your ProductHelper.cs class BuildProductOptions method and locate following code block in code section where dropdown list being added dynamically
Code: Select all
foreach (OptionChoice optionOption in availableOptions)
{
aspOptions.Items.Add(new ListItem(optionOption.Name, optionOption.OptionChoiceId.ToString()));
}
and then change it as below
Code: Select all
foreach (OptionChoice optionOption in availableOptions)
{
List<int> chList = new List<int>();
chList.Add(optionOption.OptionChoiceId);
ProductVariant productVariant = ProductVariantDataSource.LoadForOptionList(product.ProductId, chList.ToArray());
if (productVariant != null)
{
string msg = string.Format("- {0} item{1} in stock", productVariant.InStock, (productVariant.InStock > 1) ? "s" : string.Empty);
aspOptions.Items.Add(new ListItem(optionOption.Name + msg , optionOption.OptionChoiceId.ToString()));
}
else
aspOptions.Items.Add(new ListItem(optionOption.Name, optionOption.OptionChoiceId.ToString()));
}