I have made a component to add items to cart, but I have found a problem when I tried to add a item through the other plugin or component outside of virtuemart.
Virtuemart inserts items to cart by using a POST to get quantity
Currently using VM3.2.12 on Joomla 3.8.7 PHP 7.0.25
My example code to insert items in cart.
--------------
$cart = VirtuemartCart::getCart();
if (!$cart) {
JError::raiseWarning(500, 'Error');
return false;
}
$error = true;
$cart->add($pks, $error);
And the patch permit to it
--- components/com_virtuemart/helpers/cart.php.old 2018-01-10 12:43:32.129002324 +0100
+++ components/com_virtuemart/helpers/cart.php 2018-02-22 18:45:29.785968463 +0100
@@ -512,11 +512,7 @@
$productData['virtuemart_product_id'] = (int)$virtuemart_product_id;
}
- if(!empty( $post['quantity'][$p_key])){
- $productData['quantity'] = (int) $post['quantity'][$p_key];
- } else {
- continue;
- }
+ $productData['quantity'] = (empty( $post['quantity'][$p_key]) ? 1 : (int) $post['quantity'][$p_key]);
if(!empty( $post['customProductData'][$virtuemart_product_id])){
//$productData['customProductData']