VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: paranella on September 08, 2014, 01:12:42 AM

Title: Problem checking child product qty in adding to cart
Post by: paranella on September 08, 2014, 01:12:42 AM
I'm using VM 2.6.10
When I add to cart some quantity for a child product VM check for parent stock quantity not for the child

Real example:
I am in (parent) product detail page (parent id product is 1038)
I choose one child product and add some quantity for the cart (chosen child product id is 1980)

In firebug these parameters are sent:
url: .../index.php?option=com_virtuemart&nosef=1&view=cart&task=viewJS&format=json&lang=it&_=1410127200612

post parameters:
Itemid=773
_=1410127545355
customPlugin[3345][stockable][child_id]=1980
customPlugin[3345][stockable][selectoptions1]=M
customPrice[1][44]=3345
format=json
lang=it
nosef=1
option=com_virtuemart
quantity=1
quantity[]=2
task=addJS
view=cart
virtuemart_product_id[]=1038

you can see that "virtuemart_product_id" param is the parent id product

in file /components/com_virtuemart/helper/cart.php on line 731 is declared "checkForQuantities($product, &$quantity=0,&$errorMsg ='')" function
$product param dump is:
stdClass Object
(
   ...
    [virtuemart_product_id] => 1038 (????? parent product id not child!)
    [product_parent_id] => 1038 (OK)
    [product_sku] => 10213EM (CHILD SKU, OK)
    [product_name] => TAGLIA M (CHILD NAME, OK)
    [product_in_stock] => 10 (CHILD STOCK, OK)
    ...
)

the strange here is that "[virtuemart_product_id]" property is the parent product id instead of the child

then on line 746-748 in the same file there is:
// update the stock info from the database
$product_model = VmModel::getModel('product');
$product = $product_model->getProduct($product->virtuemart_product_id);

so before I had the right child stock, now VM get the wrong parent stock because $product->virtuemart_product_id is the parent id

I Have been clear enough?
Title: Re: Problem checking child product qty in adding to cart
Post by: nvanzutphen on January 10, 2015, 16:50:34 PM
I think I'm facing exactly the same problem:

A parent product with a stock of 4 (total of the childen) has 2 children, both have a stock of 2. When I order 6 instances of one of the child products, VM reduces the number of products in the cart to 4, which equals the amount of the parents stock instead of the childs stock of 2.
To me it seems the cart simply checks the wrong product, the parent instead of the child, is there a way to fix this? I presume adjusting a bit of code would do the trick?

I'm running an old version of VM 2.0 RC3, unfortunately updating is not an option, the install has already been 'hacked' so I'm completely fine with adjusting any code. I hope you can give me a hint, it means the world to me :-).
Title: Re: Problem checking child product qty in adding to cart
Post by: GJC Web Design on January 10, 2015, 19:42:29 PM
VM 2.0 RC3 -> your joking??????

http://virtuemart.net/news/latest-news/462-security-release-of-vm2-6-10-and-vm2-9-9b

think the child not checked was fixed in 2.6.12