phpzen-cart

Mimic ZenCart's page lookup


Anyone know how would I get started on trying to code an alternative lookup for products?

What I was hoping on doing is changing ZenCart to not only look up a product page from this: http://www.example.com/index.php?main_page=product_cards_ufs_info&cPath=1_6&products_id=124

To this as an alternative: http://www.example.com/index.php?ufs_card=SOME_ID

So that it pulls up the product page of that SOME_ID (which is stored in a seperate database attached to a product ID number).

I'm trying to find the look ups for $_GET['main_page'] but I'm running out of ideas.


Solution

  • So here's how I ended up doing this. As a separate file under /zencart/includes/functions/extra_functions folder, I ended up using the following code. Essentially the script will look up the short handle in some database table and return the master_category_id and the products_id. Since I'm using an outside table to do the look up, a join is performed and we're limiting the result to only the first.

    if(isset($_GET['ufs_card'])) {
    
        $ufs = $_GET['ufs_card'];
    
        // First let's "fix" the search symbol.
        // Let's remove any Underscores
    
        $ufs = strtoupper(str_replace("_", " ", $ufs));
    
        $ufs_query = "SELECT ufs.products_id, master_categories_id FROM " . TABLE_CARDS_UFS . " ufs LEFT JOIN " . TABLE_PRODUCTS . " p ON ufs.products_id = p.products_id WHERE collector_no = '" . $ufs . "' LIMIT 1";
        // echo $ufs_query;
        $ufs_get_result = $db->Execute($ufs_query);
    
        $ufs_id = $ufs_get_result->fields['products_id'];
        $category_id = $ufs_get_result->fields['master_categories_id'];
        if($ufs_id && $category_id) {
            // Okay we have a valid result... Let's do a redirect.
            zen_redirect(zen_href_link("product_cards_ufs_info", 'cPath=' . zen_get_generated_category_path_rev($category_id) . '&products_id=' . $ufs_id, 'NONSSL'), 307);
        } else { // We didn't find a valid result... so redirect them to page not found OR homepage.
            if (MISSING_PAGE_CHECK == 'Page Not Found') {
                zen_redirect(zen_href_link(FILENAME_PAGE_NOT_FOUND));
            } else if (MISSING_PAGE_CHECK == 'On' || MISSING_PAGE_CHECK == 'true') {
                zen_redirect(zen_href_link(FILENAME_DEFAULT));
            } 
        }
    }