[Skip to main content](#vessel-content)

#   onBeforeProductUpdate product\_vendor\_id scope

##

- **[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")**
- [![DeeEmm's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar26410.jpg)](/forum/user/26410-deeemm "View DeeEmm's Profile") Topic Author
- [ Offline](/forum/user/26410-deeemm)

Less More

- Posts: 114
- Thank you received: 14
-
- [](http://deeemm.com)
-

13 years 1 month ago -  13 years 1 month ago [\#128084](#128084) by [DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")  *[onBeforeProductUpdate product\_vendor\_id scope](/forum/19-hikamarket/862852-onbeforeproductupdate-product-vendor-id-scope#128084 "Hi.  I am writing a plugin to process uploaded files and as discussed in 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&#95;id using $product-&gt;product&#95;vendor&#95;id;  The reason I want to access the vendor&#95;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&#95;vendor&#95;id from within theonBeforeProductUpdate and onBeforeProductcreate methods?  TIA  /DM")* was created by *[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")*

Hi.

I am writing a plugin to process uploaded files and as discussed in [ This Post](http://www.hikashop.com/forum/19-hikamarket/862772-onafterproductupdate-save-method.html) 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-&gt;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

---

[ deeemm.com](http://deeemm.com)

Last edit: 13 years 1 month ago by [DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile"). Reason: spelling

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE5LWhpa2FtYXJrZXQvODYyODUyLW9uYmVmb3JlcHJvZHVjdHVwZGF0ZS1wcm9kdWN0LXZlbmRvci1pZC1zY29wZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26401
- Thank you received: 4081
-
- [](http://obsi.dev)
-

13 years 1 month ago [\#128148](#128148) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[onBeforeProductUpdate product\_vendor\_id scope](/forum/19-hikamarket/862852-onbeforeproductupdate-product-vendor-id-scope#128148 "Hi.  I am writing a plugin to process uploaded files and as discussed in 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&#95;id using $product-&gt;product&#95;vendor&#95;id;  The reason I want to access the vendor&#95;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&#95;vendor&#95;id from within theonBeforeProductUpdate and onBeforeProductcreate methods?  TIA  /DM")*

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-&gt;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 &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE5LWhpa2FtYXJrZXQvODYyODUyLW9uYmVmb3JlcHJvZHVjdHVwZGF0ZS1wcm9kdWN0LXZlbmRvci1pZC1zY29wZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")**
- [![DeeEmm's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar26410.jpg)](/forum/user/26410-deeemm "View DeeEmm's Profile") Topic Author
- [ Offline](/forum/user/26410-deeemm)

Less More

- Posts: 114
- Thank you received: 14
-
- [](http://deeemm.com)
-

13 years 1 month ago [\#128154](#128154) by [DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")  Replied by *[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")* on topic *[onBeforeProductUpdate product\_vendor\_id scope](/forum/19-hikamarket/862852-onbeforeproductupdate-product-vendor-id-scope#128154 "Hi.  I am writing a plugin to process uploaded files and as discussed in 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&#95;id using $product-&gt;product&#95;vendor&#95;id;  The reason I want to access the vendor&#95;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&#95;vendor&#95;id from within theonBeforeProductUpdate and onBeforeProductcreate methods?  TIA  /DM")*

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 =&amp; 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.
Code:

function onBeforeProductcreate(&amp;$product, &amp;$do) { //add todays date $dt = new DateTime(); $product-&gt;date_added = $dt-&gt;format('d-m-Y'); $file_id = $product-&gt;files[0]; // Get filepath data from database. $db = JFactory::getDbo(); $query = "SELECT &#96;file_path&#96; FROM &#96;#__hikashop_file&#96; WHERE &#96;file_id&#96; = '$file_id' AND &#96;file_type&#96; = 'file' ORDER BY &#96;file_id&#96; DESC LIMIT 1"; $db-&gt;setQuery($query); $file_path = $this-&gt;dl_path . $db-&gt;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-&gt;product_vendor_id; $this-&gt;preLoader($file_path); $product-&gt;word_count = $this-&gt;getWords() . ' words'; $product-&gt;page_count = $this-&gt;getPages() . ' grams'; $product-&gt;preview_url = '&lt;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;" &gt; File Viewer&lt;/a&gt;'; } }

Any thoughts?

Regards

/DM

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

---

[ deeemm.com](http://deeemm.com)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE5LWhpa2FtYXJrZXQvODYyODUyLW9uYmVmb3JlcHJvZHVjdHVwZGF0ZS1wcm9kdWN0LXZlbmRvci1pZC1zY29wZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")**
- [![DeeEmm's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar26410.jpg)](/forum/user/26410-deeemm "View DeeEmm's Profile") Topic Author
- [ Offline](/forum/user/26410-deeemm)

Less More

- Posts: 114
- Thank you received: 14
-
- [](http://deeemm.com)
-

13 years 1 month ago [\#128159](#128159) by [DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")  Replied by *[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")* on topic *[onBeforeProductUpdate product\_vendor\_id scope](/forum/19-hikamarket/862852-onbeforeproductupdate-product-vendor-id-scope#128159 "Hi.  I am writing a plugin to process uploaded files and as discussed in 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&#95;id using $product-&gt;product&#95;vendor&#95;id;  The reason I want to access the vendor&#95;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&#95;vendor&#95;id from within theonBeforeProductUpdate and onBeforeProductcreate methods?  TIA  /DM")*

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](/media/kunena/emoticons/1.png ":D") )

/DM

---

[ deeemm.com](http://deeemm.com)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE5LWhpa2FtYXJrZXQvODYyODUyLW9uYmVmb3JlcHJvZHVjdHVwZGF0ZS1wcm9kdWN0LXZlbmRvci1pZC1zY29wZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")**
- [![DeeEmm's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar26410.jpg)](/forum/user/26410-deeemm "View DeeEmm's Profile") Topic Author
- [ Offline](/forum/user/26410-deeemm)

Less More

- Posts: 114
- Thank you received: 14
-
- [](http://deeemm.com)
-

13 years 1 month ago [\#128239](#128239) by [DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")  Replied by *[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")* on topic *[onBeforeProductUpdate product\_vendor\_id scope](/forum/19-hikamarket/862852-onbeforeproductupdate-product-vendor-id-scope#128239 "Hi.  I am writing a plugin to process uploaded files and as discussed in 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&#95;id using $product-&gt;product&#95;vendor&#95;id;  The reason I want to access the vendor&#95;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&#95;vendor&#95;id from within theonBeforeProductUpdate and onBeforeProductcreate methods?  TIA  /DM")*

I circumvented the issue by creating a method to retrieve the current users vendor id
Code:

function getVendorId(){ $user = JFactory::getUser(); $db = JFactory::getDbo(); $userid = $user-&gt;id; $query = "SELECT &#96;user_id&#96; FROM &#96;#__hikashop_user&#96; WHERE &#96;user_cms_id&#96; = '" . $userid . "'"; $db-&gt;setQuery($query); $hika_user_id = $db-&gt;loadResult(); $query = "SELECT &#96;vendor_id&#96; FROM &#96;#__hikamarket_vendor&#96; WHERE &#96;vendor_admin_id&#96; = '" . $hika_user_id . "'"; $db-&gt;setQuery($query); $hika_vendor_id = $db-&gt;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 ![;)](/media/kunena/emoticons/24.png ";)")

(BTW you really should consider using the Joomla userid )

/DM

---

[ deeemm.com](http://deeemm.com)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE5LWhpa2FtYXJrZXQvODYyODUyLW9uYmVmb3JlcHJvZHVjdHVwZGF0ZS1wcm9kdWN0LXZlbmRvci1pZC1zY29wZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26401
- Thank you received: 4081
-
- [](http://obsi.dev)
-

13 years 1 month ago [\#128244](#128244) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[onBeforeProductUpdate product\_vendor\_id scope](/forum/19-hikamarket/862852-onbeforeproductupdate-product-vendor-id-scope#128244 "Hi.  I am writing a plugin to process uploaded files and as discussed in 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&#95;id using $product-&gt;product&#95;vendor&#95;id;  The reason I want to access the vendor&#95;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&#95;vendor&#95;id from within theonBeforeProductUpdate and onBeforeProductcreate methods?  TIA  /DM")*

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 &amp; HikaSerial developer / HikaShop core dev team.

The following user(s) said Thank You: [DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE5LWhpa2FtYXJrZXQvODYyODUyLW9uYmVmb3JlcHJvZHVjdHVwZGF0ZS1wcm9kdWN0LXZlbmRvci1pZC1zY29wZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")**
- [![DeeEmm's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar26410.jpg)](/forum/user/26410-deeemm "View DeeEmm's Profile") Topic Author
- [ Offline](/forum/user/26410-deeemm)

Less More

- Posts: 114
- Thank you received: 14
-
- [](http://deeemm.com)
-

13 years 1 month ago [\#128282](#128282) by [DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")  Replied by *[DeeEmm](/forum/user/26410-deeemm "View DeeEmm's Profile")* on topic *[onBeforeProductUpdate product\_vendor\_id scope](/forum/19-hikamarket/862852-onbeforeproductupdate-product-vendor-id-scope#128282 "Hi.  I am writing a plugin to process uploaded files and as discussed in 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&#95;id using $product-&gt;product&#95;vendor&#95;id;  The reason I want to access the vendor&#95;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&#95;vendor&#95;id from within theonBeforeProductUpdate and onBeforeProductcreate methods?  TIA  /DM")*

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](/media/kunena/emoticons/1.png ":D")

Thanks

/DM

---

[ deeemm.com](http://deeemm.com)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzE5LWhpa2FtYXJrZXQvODYyODUyLW9uYmVmb3JlcHJvZHVjdHVwZGF0ZS1wcm9kdWN0LXZlbmRvci1pZC1zY29wZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

Moderators: [Obsidev](/forum/user/7040-obsidev "View Obsidev's Profile")

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.060 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
