Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • discountufoparts Friend
    #156677

    Do you know of any way to pass the actual k2 article item id into the search filter results for the query setup in the jak2_filter.php. I am having a hard time finding a way to pass this variable into the search setup.

    Phan Gam Friend
    #363829

    Hi,
    About this question. If you want to get k2-item ID in search results, please go to about line 217 in plugins/search/ja_k2filter.php file
    (in code secsion
    $query = "
    SELECT i.title ....

    )
    Replace it by
    $query = "
    SELECT i.id, i.title ....

    .
    Hope can help you 🙂

    discountufoparts Friend
    #363898

    I tried this and it does not produce a result for $result->title. I don’t know if I am doing something wrong but I can’t get it to work and have tried several variations. This is the workaround I designed and am using to get what I need currently. It is sort of messy but its working and doesn’t seem to be throwing or bogging page load. In my search results I am calling the Article id by doing a sql search off of the item title.[PHP]<?php
    $K2articleID = ”;
    $findThis = $result->title;
    $db =& JFactory::getDBO();
    $query = “SELECT id FROM #__k2_items WHERE title = ‘$findThis'”;
    $db->setQuery($query);
    $K2articleID = $db->loadResult();
    $item->searchimage = JURI::root().’media/k2/items/cache/’.md5(“Image”.$K2articleID).’_XS.jpg’;
    ?>[/PHP]

    discountufoparts Friend
    #363899

    Then I am using this to get the featured class:

    [PHP]<?php
    $featured = ”;
    $db =& JFactory::getDBO();
    $query = “SELECT featured FROM #__k2_items WHERE id = ‘$K2articleID'”;
    $db->setQuery($query);
    $featured = $db->loadResult();
    ?>[/PHP]

    and then I am getting the extra fields this way:[PHP]<?php
    $custom = ”;
    $customBits[] = ”;
    $db =& JFactory::getDBO();
    $query = “SELECT extra_fields_search FROM #__k2_items WHERE id = ‘$K2articleID'”;
    $db->setQuery($query);
    $custom = $db->loadResult();
    $customBits = explode(” “, $custom);

    ?>[/PHP]

    Phan Gam Friend
    #364010

    Hi,
    Could you please let me know where you got those lines of code, if you use it to overwite ja_k2filter.php file you can follow my suggestions
    For k2-extrafields, you can get it from k2-items, and then parse it from json string to object. for more details, please check code on com_k2/models/item.php in GetData() and prepareItem() methods.
    Good luck for you!

    discountufoparts Friend
    #364126

    I actually put those lines of code right in :

    components/com_search/views/search/tmpl/default_results.php

    I got the results->title from your results array.

    I am not much of php coder I just am picking up bits and pieces along the way. Here is my entire default_results page if it helps:
    [PHP]<?php defined(‘_JEXEC’) or die(‘Restricted access’); ?>

    <?php foreach( $this->results as $result ) : ?>

    <?php
    $K2articleID = ”;
    $findThis = $result->title;
    $db =& JFactory::getDBO();
    $query = “SELECT id FROM #__k2_items WHERE title = ‘$findThis'”;
    $db->setQuery($query);
    $K2articleID = $db->loadResult();
    $item->searchimage = JURI::root().’media/k2/items/cache/’.md5(“Image”.$K2articleID).’_XS.jpg’;
    ?>
    <?php
    $featured = ”;
    $db =& JFactory::getDBO();
    $query = “SELECT featured FROM #__k2_items WHERE id = ‘$K2articleID'”;
    $db->setQuery($query);
    $featured = $db->loadResult();
    ?>

    <div class=”catItemView groupLeading <?php if ($featured == ‘1’) echo ‘ catItemIsFeatured’; ?>”>

    <div class=”ham_category_blocking”>
    <div class=”ham_catItemHeader”>
    <!– Item Image –>
    <div class=”ham_catItemImageBlock”>
    <a href=”<?php echo JRoute::_($result->href); ?>” title=”<?php echo $result->title; ?>”>
    <img src=”<?php echo $item->searchimage; ?>” alt=”<?php echo $result->title; ?>” /></a>
    </div>
    <!– Item title –>
    <h3 class=”ham_catItemTitle”>
    <a href=”<?php echo JRoute::_($result->href); ?>”>
    <?php echo $this->escape($result->title); ?>
    </a>
    </h3>
    </div>
    <?php
    $custom = ”;
    $customBits[] = ”;
    $db =& JFactory::getDBO();
    $query = “SELECT extra_fields_search FROM #__k2_items WHERE id = ‘$K2articleID'”;
    $db->setQuery($query);
    $custom = $db->loadResult();
    $customBits = explode(” “, $custom);

    ?>

    <div class=”ham_catItemFields”>Boat Color: <?php echo $customBits[0]; ?></div>
    <div class=”ham_catItemFields”>Motor: <?php echo $customBits[1]; ?></div>
    <div class=”ham_catItemFields”>Location: <?php echo $customBits[2]; ?></div>
    <div class=”ham_catItemFields”> <?php if ($featured == ‘1’): ?>Price: <span style=”color:#FF0000; font-weight:bold;”><?php echo $customBits[4]; ?></span> <?php else: ?>
    <a href=”<?php echo JRoute::_($result->href); ?>#quoteForm”>Get a quote!</a> <?php endif ?>
    </div>
    </div>
    </div>
    <?php endforeach; ?>
    <div align=”center”><?php echo $this->pagination->getPagesLinks( ); ?></div>
    [/PHP]

    Phan Gam Friend
    #364177

    Hi,
    As your code, i think, you want to get $item->id, $item->featured, $item->extra_fields_search, you can do this using my suggestions
    1. open plugins/search/ja_k2filter.php, go to about line 217.
    2. Set sql-query as
    [PHP]$query = ”
    SELECT i.id, i.featured,
    i.title,
    i.metadesc,
    i.metakey,
    c.name as section,
    i.image_caption,
    i.image_credits,
    i.video_caption,
    i.video_credits,
    i.extra_fields_search,
    i.created,
    CONCAT(i.introtext, i.fulltext) AS text,
    CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(‘:’, i.id, i.alias) ELSE i.id END as slug,
    CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(‘:’, c.id, c.alias) ELSE c.id END as catslug
    FROM #__k2_items AS i
    INNER JOIN #__k2_categories AS c ON c.id=i.catid AND c.access <= {$access} “;[/PHP]
    3. In default_results.php, you no need use sql to get id,featured and extra_fields_search, you can use them from $result object
    eg: 3.1. $result ->searchimage = JURI::root().’media/k2/items/cache/’.md5(“Image”.$result ->id).’_XS.jpg’;
    3.2. <div class=”catItemView groupLeading <?php if ($featured == ‘1’) echo ‘ catItemIsFeatured’; ?>”>
    by <div class=”catItemView groupLeading <?php if ($result->featured == ‘1’) echo ‘ catItemIsFeatured’; ?>”>
    and 3. $customBits = explode(” “, $result->extra_fields_search) and continues.
    Hope can help you!

    discountufoparts Friend
    #364844

    I will have to try some things.

    discountufoparts Friend
    #364859

    This is still not returning the actual item id. It is returning the search result id which is 0 for the first one, 1 for the second result and so on…… I need the actual k2 item id that is in the searches.

    discountufoparts Friend
    #364862

    I fixed it the variable result->id is conflicting with the actual result->id from the result array and listing that instead so i did this in the query instead and it resolved the conflict i had:[PHP]$query = “
    SELECT i.id as item_id, i.featured,
    i.title,
    i.metadesc,
    i.metakey,
    c.name as section,
    i.image_caption,
    i.image_credits,
    i.video_caption,
    i.video_credits,
    i.extra_fields_search,
    i.created,
    CONCAT(i.introtext, i.fulltext) AS text,
    CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(‘:’, i.id, i.alias) ELSE i.id END as slug,
    CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(‘:’, c.id, c.alias) ELSE c.id END as catslug
    FROM #__k2_items AS i
    INNER JOIN #__k2_categories AS c ON c.id=i.catid AND c.access <= {$access} “;
    [/PHP]

Viewing 10 posts - 1 through 10 (of 10 total)

This topic contains 10 replies, has 2 voices, and was last updated by  discountufoparts 13 years, 11 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum