DeeEmm

Pragmatism in code

If you are writing a plugin and are using the onBeforeProductCreate method to trigger your code you might have found that the product_vendor_id field is not available to you. This is because at this stage the product hasn't technically been created.

You will also probably know that not only is the hikashop user id different to the joomla user id, but the hikamarket user id is different from the hikashop user id.

Crazy huh!!

To get around this you can use the following method to lookup the current users market vendor id ;)

	function getVendorId(){
	
		$user = JFactory::getUser();					
		$db = JFactory::getDbo();
		
		$userid = $user->id;

 		$query = "SELECT `user_id` FROM `#__hikashop_user` WHERE `user_cms_id` = '" . $userid . "'";		
 		$db->setQuery($query);
 		$hika_user_id = $db->loadResult();

 		$query = "SELECT `vendor_id` FROM `#__hikamarket_vendor` WHERE `vendor_admin_id` = '" . $hika_user_id . "'";		
 		$db->setQuery($query);
 		$hika_vendor_id = $db->loadResult();
	 		
		return $hika_vendor_id;
	}