onBeforeProductUpdate product_vendor_id scope
12 years 11 months ago - 12 years 11 months ago #128084
by DeeEmm
onBeforeProductUpdate product_vendor_id scope was created by DeeEmm
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
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: 12 years 11 months ago by DeeEmm. Reason: spelling
Please Log in or Create an account to join the conversation.
12 years 11 months ago #128148
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Replied by Jerome on topic onBeforeProductUpdate product_vendor_id scope
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,
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.
Please Log in or Create an account to join the conversation.
12 years 11 months ago #128154
by DeeEmm
Replied by DeeEmm on topic onBeforeProductUpdate product_vendor_id scope
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.
Any thoughts?
Regards
/DM
PS. Your preview pane is sometimes not working for me - (Mac OSX + Firefox)
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.
Code:
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.
12 years 11 months ago #128159
by DeeEmm
Replied by DeeEmm on topic onBeforeProductUpdate product_vendor_id scope
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
)
/DM
So it is present in onAfterProductCreate but not in onBeforeProductcreate.
(for me at any rate
)/DM
Please Log in or Create an account to join the conversation.
12 years 11 months ago #128239
by DeeEmm
Replied by DeeEmm on topic onBeforeProductUpdate product_vendor_id scope
I circumvented the issue by creating a method to retrieve the current users 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
Code:
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.
12 years 11 months ago #128244
by Jerome
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Replied by Jerome on topic onBeforeProductUpdate product_vendor_id scope
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,
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.
The following user(s) said Thank You: DeeEmm
Please Log in or Create an account to join the conversation.
12 years 11 months ago #128282
by DeeEmm
Replied by DeeEmm on topic onBeforeProductUpdate product_vendor_id scope
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
Thanks
/DM
I will take a look into hikamarket::loadVendor it is certainly a lot more elegant that what I have concocted

Thanks
/DM
Please Log in or Create an account to join the conversation.
Moderators: Obsidev
Time to create page: 0.229 seconds