Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2005
    Location
    California
    Posts
    663
    Plugin Contributions
    0

    help question Is there a function to look up model and return id, sort of like zen_products_lookup?

    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.

  2. #2
    Join Date
    Jun 2006
    Location
    My family and I live in Brighton, England
    Posts
    982
    Plugin Contributions
    0

    Default Re: Is there a function to look up model and return id, sort of like zen_products_loo

    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.

  3. #3
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Is there a function to look up model and return id, sort of like zen_products_loo

    You could add this to a file in extra_functions folder:
    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;
        }
      }
    }
    Then you can use it via:
    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.

  4. #4
    Join Date
    Jun 2006
    Location
    My family and I live in Brighton, England
    Posts
    982
    Plugin Contributions
    0

    Default Re: Is there a function to look up model and return id, sort of like zen_products_loo

    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?

  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Is there a function to look up model and return id, sort of like zen_products_loo

    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.

  6. #6
    Join Date
    Mar 2005
    Location
    California
    Posts
    663
    Plugin Contributions
    0

    Default Re: Is there a function to look up model and return id, sort of like zen_products_loo

    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.

  7. #7
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Is there a function to look up model and return id, sort of like zen_products_loo

    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.

  8. #8
    Join Date
    Jun 2006
    Location
    My family and I live in Brighton, England
    Posts
    982
    Plugin Contributions
    0

    Default Re: Is there a function to look up model and return id, sort of like zen_products_loo

    Quote Originally Posted by gjh42 View Post
    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.
    tj1 if you Do get to this before I do (I hope - I hope - I hope!! ) could you please post your findings here? I'll do the same.

  9. #9
    Join Date
    Mar 2005
    Location
    California
    Posts
    663
    Plugin Contributions
    0

    Default Re: Is there a function to look up model and return id, sort of like zen_products_loo

    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');

    ?>

 

 

Similar Threads

  1. v151 Is there a simple approach to renaming ez pages to look like my core pages
    By mrcastle in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 17 Sep 2014, 01:00 PM
  2. zen_products_lookup: How do I "return any field"?
    By molywerks in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 22 Jun 2008, 09:32 PM
  3. Is there a return/exchange function in frontend/backend and Authorize.net?
    By codingcoding in forum Managing Customers and Orders
    Replies: 0
    Last Post: 15 Dec 2007, 03:47 AM
  4. Cutomising look and function of Zencart
    By hoarel in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 13 Sep 2007, 01:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg