Advertisement:

Author Topic: [SOLVED] show only items related with Category=62  (Read 1443 times)

fog

  • Hero Member
  • *****
  • Posts: 1062
[SOLVED] show only items related with Category=62
« on: December 10, 2013, 06:34:48 pm »
Hi, in plugin Related_ads i need showing related ads with a especific subcategory by number

I clone a new related_ads2.php file

I clone a new function in index.php:
Code: [Select]
function related_ads_start2(){
and i call the new function in item.php, run just fine.

I test, if i remove the next line of code the result is show me all ads without filtered by region an category:

Code: [Select]
// $category = (osc_related_category() != '') ? osc_related_category() : '' ;
what i need is show ads with a especific subcategory by number in the same region... how can i do this?

example: i need show only items related with Category=62 in all items on page item.php, but in the same region.

Please guys, help me with this

Regards
« Last Edit: December 12, 2013, 08:01:52 pm by fog »

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: show only items related with Category=62
« Reply #1 on: December 11, 2013, 03:58:17 pm »
Come on people, i really need this... i don't have a ideia how solve this...

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: show only items related with Category=62
« Reply #2 on: December 11, 2013, 04:42:50 pm »
@fog
http://doc.osclass.org/HItems.php

Change function osc_has_items() to osc_has_custom_items()

http://doc.osclass.org/Display_only_certain_type_of_listings
Add function osc_query_custom_items() with category parameters, so you have:

Code: [Select]
osc_query_item(array(
    "category" => "62"
));

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: show only items related with Category=62
« Reply #3 on: December 11, 2013, 04:54:16 pm »
@frosticek  :) thanks man!

I go try your instructions, and i post the result in soon

Best Regards  ;)

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: show only items related with Category=62
« Reply #4 on: December 11, 2013, 06:11:51 pm »
Something is wrong, but do not know what. When I choose "Show ads with same region" for yes, the items are not shown. If I choose "no", shows in just 1 related announcement. But the problem is he will not show in the same region to relate.

@ frosticek I'll attach the plugin here if you can analyze if I did something wrong since the beginning.

If you can help me I will reciprocate with donation as a thank you.

I use version 3.1.2 osclass

Thanks for any help

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: show only items related with Category=62
« Reply #5 on: December 11, 2013, 07:48:36 pm »
@fog
Hmm, I see there is custom search.
Try to open in original plugin (or rollback my changes) file index.php, find this line:
Code: [Select]
$mSearch2->dao->where(sprintf("%st_item.pk_i_id <> $rmItemId", DB_TABLE_PREFIX));
bellow this line add:
Code: [Select]
$mSearch2->dao->where(sprintf("%st_item.fk_i_category_id = 62", DB_TABLE_PREFIX));

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: show only items related with Category=62
« Reply #6 on: December 11, 2013, 08:22:40 pm »
Hi again  :)

I add the line in function function related_ads_start2() {

but not appears any ad in the same region or any other region.

Maybe you can solve this in localhost or something, when you got a little time for this...   ???

This is the code for the clone function... but i think this function only call the file related_ads2.php... i think the rest of the duplicated code no make any difference... or create a bug...  ???

So I have to thank you for your patience around this   :-X

Code: [Select]
// related ads 2 @fog

function related_ads_start2() {

    $rmItemId = osc_item_id() ;

    $ra_numads = (osc_related_ra_numads() != '') ? osc_related_ra_numads() : '' ;

    $country = (osc_related_country() != '') ? osc_related_country() : '' ;

    $region = (osc_related_region() != '') ? osc_related_region() : '' ;

   // $category = (osc_related_category() != '') ? osc_related_category() : '' ;
   
$category = (osc_related_category() != '') ? osc_related_category() : '' ;

    $picOnly = (osc_related_picOnly() != '') ? osc_related_picOnly() : '';

    $mSearch2 = new Search() ;

    $mSearch2->dao->where(sprintf("%st_item.pk_i_id <> $rmItemId", DB_TABLE_PREFIX));

$mSearch2->dao->where(sprintf("%st_item.fk_i_category_id = 62", DB_TABLE_PREFIX));


    if($country ==1){

    $mSearch2->addCountry(osc_item_country()) ;

    }

    if($region ==1) {

    $mSearch2->addRegion(osc_item_region()) ;

    }

    if($category ==1) {

    $mSearch2->addCategory(osc_item_category_id()) ;

    }

    if($picOnly == 1 ) {

    $mSearch2->withPicture(true); //Search only Item which have pictures

    }

$mSearch2->order('RAND()') ; // fetch random ads

    $mSearch2->limit(0, $ra_numads) ; // fetch number of ads to show set in preference

    $aItems = $mSearch2->doSearch();

$global_items = View::newInstance()->_get('items') ; //save existing item array

View::newInstance()->_exportVariableToView('items', $aItems); //exporting our searched item array

    require_once 'related_ads2.php';

     //calling stored item array

    View::newInstance()->_exportVariableToView('items', $global_items); //restore original item array

    }
// end @fog

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: show only items related with Category=62
« Reply #7 on: December 11, 2013, 09:13:23 pm »
This only works when it relates only ads in the same region, without activating the same time in the same category. If both options are active in the settings, category 62 ads no longer work. I think it makes perfect sense. I believe that the solution is more complex to be able to use the two functions:

The first function display ads in the same category and region
Code: [Select]
function related_ads_start() {
The second function is for display ads from the same region and category 62, if in global settings if it configured only to relate in the same region . otherwise, if related in same category and region, not works. (This make sense)
Code: [Select]
function related_ads_start2() {
The global settings in the admin section are for both functions, so the second function follows the global setting. Thus it will be impossible except with a custom setting only for the second cloned function.

I think I'm on the right reasoning. Tell me what you think, so as soon as you can. If you can resolve this situation, we can negotiate?

Regards

ps:
I'll talk to you tomorrow
Thanks again
« Last Edit: December 11, 2013, 09:26:53 pm by fog »