VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: pm4698 on December 15, 2021, 23:19:49 PM

Title: Get products ids in order done page
Post by: pm4698 on December 15, 2021, 23:19:49 PM
Hi there. I have a Joomla 3.10.4 and Virtuemart 3.8.8. Inside orderdone.php I would like to get order's product ids.
What was inside orderdone.php
$db = JFactory::getDBO();
$query = "SELECT * FROM #__virtuemart_orders ORDER BY virtuemart_order_id DESC LIMIT  0, 1";
$db->setQuery($query);
$res_obj  = $db->LoadObject();


What I did is this:
$productquery = "SELECT virtuemart_product_id FROM #__virtuemart_order_items WHERE virtuemart_order_id='".$res_obj->virtuemart_order_id."'";
$db->setQuery($productquery);
$res_obj2  = $db->LoadObject();
print_r($res_obj2);


So If i run query of what I did in phpMyAdmin with my latest order id, then query works (if I have 2 items in order I see the 2 items). In my php code, inside the print_r, I get only 1 product from the order and not all.

Any ideas?

Thank you in advance
Title: Re: Get products ids in order done page
Post by: pinochico on December 16, 2021, 08:39:06 AM
In orderdone.php is only

echo $this->html;

from every payment plugin.

I think your construct can't function anytime.
So I don't have ideas too.
Maybe go to payment plugin and hack this.
Title: Re: Get products ids in order done page
Post by: Studio 42 on December 16, 2021, 16:15:44 PM
pm4698, your query is not safe, because you get last oder and this order can be form another user, if someone finish the order at same date time
Perhaps you can get orderdetails using
$cart = VirtueMartCart::getCart();
var_dump($cart->orderDetails);
I think you should see the current order from last cart
Title: Re: Get products ids in order done page
Post by: pm4698 on December 17, 2021, 19:18:28 PM
Thank you all for your input. When trying to print_r($this) i don't get any details regarding order items, just the order. Also tried:
$cart = VirtueMartCart::getCart();
var_dump($cart->orderDetails);

but I get error message that couldn't find the function. Any ideas?
Title: Re: Get products ids in order done page
Post by: pinochico on December 17, 2021, 22:18:19 PM
QuoteAny ideas?

I think, I already wrote it to you:
The value for $this is generated by the payment plugin, look at its code and create your own.