Author Topic: Problem checking child product qty in adding to cart  (Read 1502 times)

paranella

  • 3rd party VirtueMart Developer
  • Beginner
  • *
  • Posts: 3
Problem checking child product qty in adding to cart
« 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?

nvanzutphen

  • Beginner
  • *
  • Posts: 1
Re: Problem checking child product qty in adding to cart
« Reply #1 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 :-).

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9653
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Problem checking child product qty in adding to cart
« Reply #2 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

GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation