onBeforeProductUpdate product_vendor_id scope

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128084

Hi.

I am writing a plugin to process uploaded files and as discussed in This Post I have been using the onBeforeProductUpdate and onBeforeProductcreate methods to trigger my code.

Everything is working great except for one small thing. I seem to be unable to access the vendor_id using $product->product_vendor_id;

The reason I want to access the vendor_id is so that I can create the correct path to the vendors files so that they can be processed by my code.

How can I access the product_vendor_id from within theonBeforeProductUpdate and onBeforeProductcreate methods?

TIA

/DM

Last edit: 10 years 6 months ago by DeeEmm. Reason: spelling

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
10 years 6 months ago #128148

Hi,

For a product creation, the product_vendor_id is set.

In the backend, the product_vendor_id will be there.

In the front-end, the product_vendor_id will be there only if the customer has the right to change it. At this moment the best is to load the old product in order to read the value.

If there is no value in the front-end it's because we don't want to modify the value but we checked it.
I think I will introduce an "$product->old" object like for order so it will be easier to access to the old product data (for comparison or just accessing to all values).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128154

Hi Jerome, thanks for the fast reply.

I think that I need to clarify the difference between the front-end and-back end in the context of what I am trying to do.

Some more information...

I am writing a plugin that has no front end GUI. All methods are within the plugins main class. The plugin is of type group="hikashop" and the main class extends the JPlugin class. There is no part of the plugin visible or accessible from the 'front-end'.I assume that my plugins scope is therefore entirely within the 'back-end'.

The user that I am testing with has normal vendor permissions and is not a superuser or admin.

I still cannot see product_vendor_id when creating a new product within the onBeforeProductcreate method. Additionally if I perform a var_dump($product) within onBeforeProductcreate product_vendor_id is not present in the output.

I have partially solved this problem by fetching product_vendor_id from the #__hikashop_product table in the database, but this is only works for the onBeforeProdictUpdate method as the product record already exists. This solution does not work for the onBeforeProductcreate method as there is no actual database record at this time.

If it is not possible to access product_vendor_id I will have to use the user_id to look up the product_vendor_id from the #_hikamarket_vendor table. I should be able get this from $user =& JFactory::getUser(); However it seems strange that I cannot access product_vendor_id when it seems likely that I should be able to.

If you are sure that product_vendor_id should be accessible (as I have assumed) then there is perhaps some problem with what I am doing or maybe with hikashop?

Here is the code I am using.

	function onBeforeProductcreate(&$product, &$do) {

		//add todays date
		$dt = new DateTime();
		$product->date_added = $dt->format('d-m-Y');	

		$file_id = $product->files[0];

		// Get filepath data from database.
		$db = JFactory::getDbo();
 		$query = "SELECT `file_path` FROM `#__hikashop_file` WHERE `file_id` = '$file_id' AND `file_type` = 'file' ORDER BY `file_id` DESC LIMIT 1";		
		$db->setQuery($query);
		$file_path = $this->dl_path . $db->loadResult();

		$file_name = substr($file_path, strrpos($str, '/') + 1);
		$file_ext = substr($file_path, strrpos($file_path, '.') + 1);

		if ($file_ext == 'ext') {

                        $product_vendor_id = $product->product_vendor_id;

			$this->preLoader($file_path);			
			$product->word_count  = $this->getWords() . ' words';
			$product->page_count  = $this->getPages() . ' grams';
				
			$product->preview_url   =  '<a class="modal hikashop_cart_button" rel="{handler:\'iframe\',size:{x:800,y:560}}" href="http://mysite.com/files/' .  $product_vendor_id . '/' . test.php?file=' . $file_name .'" onclick="SqueezeBox.fromElement(this,{parse: \'rel\'});return false;" > File Viewer</a>';

		}		
	}

Any thoughts?

Regards

/DM

PS. Your preview pane is sometimes not working for me - (Mac OSX + Firefox)

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128159

I have just carried out a var_dump for onAfterProductCreate and product_vendor_id is present.

So it is present in onAfterProductCreate but not in onBeforeProductcreate.

(for me at any rate :D )

/DM

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128239

I circumvented the issue by creating a method to retrieve the current users 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;
	}

Could probably improve the SQL and combine both queries into one but I'm lazy and the overheads are low for my site ;)

(BTW you really should consider using the Joomla userid )

/DM

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

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
10 years 6 months ago #128244

Hi,

HikaMarket gives you some functions in order to get this information (the current logged vendor).
It will be quite better to use it: hikamarket::loadVendor($full = false)

For your "onBeforeProductCreate", are you in the backend (so in HikaShop) or in the front-end (so in HikaMarket).
That is the important point, because in the backend the logged user is not a vendor, so you have to read the value in the object. But in the front-end, you can use the hikamarket::loadVendor function in order to know the current vendor for the logged user.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: DeeEmm

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

  • Posts: 114
  • Thank you received: 14
10 years 6 months ago #128282

Ahhh now I understand the distinction between back-end (hikashop) and front-end (hikamarket). My brain was telling me that back-end = admin-panel and front-end = website, I did not make the connection before.

I will take a look into hikamarket::loadVendor it is certainly a lot more elegant that what I have concocted :D

Thanks

/DM

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

Moderators: Obsidev
Time to create page: 0.067 seconds
Powered by Kunena Forum