VirtueMart Forum

VirtueMart 2 + 3 => Product creation => Topic started by: roman5527 on September 26, 2018, 19:10:48 pm

Title: Product multi variant stock problem
Post by: roman5527 on September 26, 2018, 19:10:48 pm
Hello !!!

I have a VM shop with the option "If stock=0 - Show notify button". The client need it in this way.
Then... I have products that I have stock of child's, but I don't have stock of parent !!

In this situation, product is display on site but i see notify button , but the child's have stock.

I need a solution to show notify button on parent product only when all child product stock = 0
Please, someone knows the solution?

Thank's in advance

Best regards :)
Title: Re: Product multi variant stock problem
Post by: Studio 42 on September 26, 2018, 22:46:07 pm
I can change the behavior in my plugin "Professional product Child variants".
See https://shop.st42.fr/en/products/product-child-variants.htm
Title: Re: Product multi variant stock problem
Post by: roman5527 on September 28, 2018, 10:50:11 am
Thanks but i need it no only module but in category page and product detail page too.
Title: Re: Product multi variant stock problem
Post by: StefanSTS on September 28, 2018, 12:10:19 pm
Hi Roman,

normally I set the parent that is not orderable to a positve number of available products like 1000000. It will then show "Choose Variant".
If all child products are out of stock, each shows the "Notify me".
In this case the customer sends the notify only from the child, that he actually wants.

Like T-Shirt, color blue, size L.

Only you don't get the notify on the parent if all children are at 0. But the customer would normally want to know when the specific child is available.

Stefan
Title: Re: Product multi variant stock problem
Post by: Studio 42 on September 28, 2018, 14:02:46 pm
Thanks but i need it no only module but in category page and product detail page too.
The plugin handle it for all cases same way. In a module, category or product detail
Title: Re: Product multi variant stock problem
Post by: roman5527 on September 29, 2018, 21:55:27 pm
Hi Roman,

normally I set the parent that is not orderable to a positve number of available products like 1000000. It will then show "Choose Variant".
If all child products are out of stock, each shows the "Notify me".
In this case the customer sends the notify only from the child, that he actually wants.

Like T-Shirt, color blue, size L.

Only you don't get the notify on the parent if all children are at 0. But the customer would normally want to know when the specific child is available.

Stefan

Hi, StefanSTS. Where i set parent product how is not orderable ? because i used multi variant custom field.
and from this tutorial : https://docs.virtuemart.net/tutorials/product-creation/221-multivariant.html i have parent do not orderable, because i see choose variant in select box.

and this solution is not good.
Because i need when is at least one child product stock > 0 , parent product show choose variant , but when all child product stock = 0 , parent produt show notify me . But when i set stock parent product i never see notify me on parent product.

any idea ? thanks
Title: Re: Product multi variant stock problem
Post by: StefanSTS on September 30, 2018, 16:45:16 pm
Hi Roman,

if you really need to change to "Notify" on the parent product, I don't think there is a core solution to it. As I said, I use that type only with "Choose" for the parent and "Notify" in any or all child products that have a stock of 0.

You would either
1. need a plugin that calculates the available products for the parent from the child products or
2. an override for the productdetails layout that counts the child products if the current product is a parent and accordingly displays "notify" or "Choose".

If you cannot code that yourself, you might ask Max from iStraxx if he can make that layout for you, or if he would consider putting that into core for a supporter membership.

I guess it's not too hard to find the stock level of child products in a parent, but I haven't looked into that yet.
Title: Re: Product multi variant stock problem
Post by: GJC Web Design on September 30, 2018, 18:23:38 pm
I do this in addtocart.php

Code: [Select]
//GJC added to get stock info for childs
$is_in_stock ='0';
$nochildren = 0;
$prodmodel = VmModel::getModel ('product');
$children = $prodmodel->getProductChilds($product->virtuemart_product_id);
if(!empty($children)){
foreach($children as $child) {
if($child->published == 0) {
continue;
}elseif($child->product_in_stock - $child->product_ordered < 1){
continue;
}else{
$is_in_stock++;
}
}
}else{
$nochildren = 1;
}

then switch the label/display of the parent depending on $is_in_stock etc