How to retrieve product quantity per J user ID

  • Posts: 24
  • Thank you received: 1
10 years 11 months ago #137788

-- url of the page with the problem -- : localhost
-- HikaShop version -- : 2.2.3
-- Joomla version -- : 2.5.17
-- PHP version -- : 5.4.6

Hi there,

After my HikaShop customer pays for a product, he will need to log in and fill in for me a small web form in which, as he fills it in, I will need one of his fields to be calculated based on the quantity of the HikaShop product he just purchased.

I am using RSForms Pro to construct the form and one of their tutorials deals with similar task: it inserts into the form field a Cummunity Builder user first name with this code:

//<code>
$user = JFactory::getUser();
$db = JFactory::getDbo();
$userId = $user->get('id');

// Is the user logged in?
if ($userId) {
// Grab the value from the database.
$db->setQuery("SELECT `firstname` FROM `#__comprofiler` WHERE `user_id`='".$userId."'");
return $db->loadResult();
}
//</code>

Could you advise what SELECT would help me to retrieve the quantity of the product from the last order of a logged in Joomla 2.5 user/HikaShop customer?

Cheers,

Alex


Seek and you shall find.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13378
  • MODERATOR
10 years 11 months ago #137876

Hi,

$db->setQuery("SELECT op.order_product_quantity FROM #__hikashop_user AS u LEFT JOIN #__hikashop_order AS o ON u.user_id=o.order_user_id LEFT JOIN #__hikashop_order_product AS op ON o.order_id=op.order_id WHERE u.user_cms_id=".(int)$userId." ORDER BY o.order_id DESC;");

The following user(s) said Thank You: alexsmirnov

Please Log in or Create an account to join the conversation.

  • Posts: 24
  • Thank you received: 1
10 years 10 months ago #137934

Cheers, Nicolas. This query worked like charm.


Seek and you shall find.

Please Log in or Create an account to join the conversation.

Time to create page: 0.050 seconds
Powered by Kunena Forum