Skip to content

Instantly share code, notes, and snippets.

@hailwood
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hailwood/2a61a13afc888193b964 to your computer and use it in GitHub Desktop.
Save hailwood/2a61a13afc888193b964 to your computer and use it in GitHub Desktop.
<?php
function getCMSFields() {
$fields = parent::getCMSFields();
/** @var DropdownField $featuredProduct */
$featuredProduct = $fields->fieldByName('Root.Main.FeaturedProductID');
$country = $this->Code;
$list = Product::get()->filterByCallback(function (Product $product) use ($country) {
if ($product->AllCountries) {
return true;
}
if ($product->getManyManyComponents('IncludedCountries', "\"Code\" = '$country'")->Count()) {
return true;
}
if ($product->getManyManyComponents('ExcludedCountries', "\"Code\" = '$country'")->Count()) {
return false;
}
return true;
})->map();
$featuredProduct->setSource($list);
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment