Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Custom search


Go to End


767 Views

Avatar
tomjohn

Community Member, 19 Posts

20 August 2016 at 3:16am

Edited: 20/08/2016 3:18am

I have a product catalog. There are:
Dzial.php - category page PodDzial.php - subcategory page
Produkt.php - product - DataObjects which belong to PodDzial.php
Kategoria.php - type of product- which belong to PodDzial (has_one) and to Produkt (has_many)
Marka.php - brand of product- which belong to Dzial (has_one) and to Produkt (has_many)

I work on custom search on PodDzial page.

There is code which don't work:
public function getDefaultSearchContext() {

$fields = new FieldList(
TextField::create('PodDzial', 'PodDzial')->setValue($this->PodDzialID) ,
DropdownField::create(
'MarkaID',
'Marka',
Marka::get()->map('ID','Title')
)->setEmptyString('--Wybierz marke--') ,
DropdownField::create(
'KategoriaID',
'Kategoria',
Kategoria::get()->filter(array('PodDzialID' => $this->PodDzialID))->map('ID','Title')
)->setEmptyString('--Wybierz kategorie--')

);

$filters = array(
'PodDzialID' => new ExactMatchFilter('PodDzialID') ,
'MarkaID' => new ExactMatchFilter('MarkaID'),
'KategoriaID' => new ExactMatchFilter('KategoriaID')
);

return new SearchContext(
$this->class,

$fields,
$filters
);
}

Marka's field shows all Marka even from other categories. Kategoria show nothing. This same code for Kategoria works propertly in function getCMSFields().

Anyone can help?