I'm doing some customizations and need to use a function where model is provided and it would return products_id.
Is there a function like this alreasy in ZenCart, something like zen_products_lookup?
Thanks.
I'm doing some customizations and need to use a function where model is provided and it would return products_id.
Is there a function like this alreasy in ZenCart, something like zen_products_lookup?
Thanks.
I'm curious about this, as well, for use in conjunction with Tony's Cross Sell. This mod uses a combination of model and product ID that can be cumbersome when you have a large inventory. A quick product ID look-up from the model # would be a real time-saver.
You could add this to a file in extra_functions folder:Then you can use it via:Code:<?php if (!function_exists('zen_get_products_id_from_model')) { /* * get products_id from products_model */ function zen_get_products_id_from_model($model) { global $db; $sql = "select p.products_id from " . TABLE_PRODUCTS . " p where p.products_model = '" . zen_db_input($model) . "' LIMIT 1"; $look_up = $db->Execute($sql); if ($look_up->RecordCount() > 0) { return $look_up->fields['products_id']; } else { return false; } } }Code:$my_products_id = zen_get_products_id_from_model($my_model_number);
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.
Hi doc - Thanks for replying. OK, I'll give it a whirl.
Two things: Do I create this page in /includes/functions/extra_functions or /admin/includes/functions/extra_functions/? Also, when you say "use it via..." what does that mean? How do I access the information once everything is in place?
I believe any "file in extra_functions folder" would do, as this is a catchall for custom functions. You will need to create a new file for your own functions if you haven't yet - the folder comes with only index.html. I would guess that /includes or /admin/includes would depend on the intended area of use, and that either would actually work.
$my_products_id = zen_get_products_id_from_model($my_model_number);
$my_products_id and $my_model_number can be any variables you want. You can use the function in any situation where you have a model and want its id... hard to be more specific without having an actual situation to apply it to.
Thanks DrByte!
What would I need to change to make it work exactly like zen_products_lookup? That is, provide model and be able to retrieve any other field, not just products_id.
Just like in zen_products_lookup, products_id is provided and it can return any other field.
As it is right now, it appears it can only retun products_id, correct? Which is great and was what I originally wanted and asked for, but now I realize I might also need to retrieve some other fields as well.
Last edited by tj1; 15 May 2007 at 05:14 PM.
I would say to look at the zen_products_lookup file alongside the new code for zen_get_products_id_from_model, and you may be able to make logical substitutions to turn a copy of zen_products_lookup into zen_products_lookup_from_model.
I saw a problem trying to make zen_products_lookup into zen_products_lookup_from model.
The problem is zen_products_lookup is able to look in both the products and products description tables because products_id appears on both tables.
products_model only appears in the products table; therefore, in order to look in both tables from products_model, we first need to find the products_id and then will be able to search in both tables.
I really don't know php or sql so I couldn't come up with a single combined function to do both things, look up products_id from model and then retrieve whatever field we need from the products or products_description tables.
However, this can be accomplished by using both functions we already have, the one DrByte provided zen_get_products_id_from_model and zen_products_lookup.
I made a simple php file called test_model_lookup.php with the following code and it works perfectly.
PHP Code:<?php
/*Put this file in your shop's root directory.
*Use example: http://www.myzenstore.com/test_model_lookup.php?model=modelhere&what_field=fieldhere
*Substitute 'modelhere' for actual model number and 'fieldhere' with the field you want to retrieve
*/
require('includes/application_top.php');
if (isset($_GET['model']) && isset($_GET['what_field'])){
$model = $_GET['model'];
$what_field = $_GET['what_field'];
$product_id = zen_get_products_id_from_model($model);
if($what_field == 'products_id'){
echo $product_id;
}
else{
echo zen_products_lookup($product_id,$what_field);
}
}
else {
echo 'Model or Field to Return is missing';
}
require('includes/application_bottom.php');
?>