public function getLink()
 {
     $page = ProductGroupWithTags::get()->filter(array("LevelOfProductsToShow" => 2))->first();
     if (!$page) {
         $pages2 = $this->ProductGroupWithTagsPages();
         if ($pages2) {
             $page = $pages2->First();
         }
         if (!$page) {
             $page = ProductGroupWithTags::get()->first();
         }
     }
     if ($page) {
         return $page->Link() . "#filter_" . $this->Code;
     }
 }
 /**
  * returns the inital (all) products, based on the all the eligile products
  * for the page.
  *
  * This is THE pivotal method that probably changes for classes that
  * extend ProductGroup as here you can determine what products or other buyables are shown.
  *
  * The return from this method will then be sorted and filtered to product the final product list
  *
  * @param string $extraFilter Additional SQL filters to apply to the Product retrieval
  * @param boolean $recursive
  * @return DataObjectSet | Null
  **/
 public function currentInitialProducts($extraFilter = null, $alternativeFilterKey = '')
 {
     $this->allProducts = parent::currentInitialProducts($extraFilter, $alternativeFilterKey);
     if ($extraFilter) {
         if ($extraFilter instanceof DataObjectSet) {
             $tags = $extraFilter;
             //do nothing
         } elseif ($extraFilter instanceof DataObject) {
             $tags = new ArrayList(array($extraFilter));
         } elseif (is_array($extraFilter) || intval($extraFilter) == $extraFilter) {
             $tags = EcommerceProductTag::get()->filter(array("ID" => $extraFilter));
         } else {
             user_error("Error in tags", E_USER_NOTICE);
         }
         $idArray = array();
         if ($tags->count()) {
             $stage = '';
             if (Versioned::current_stage() == "Live") {
                 $stage = "_Live";
             }
             if ($tags->count()) {
                 foreach ($tags as $tag) {
                     $rows = DB::query("\n\t\t\t\t\t\t\tSELECT \"ProductID\"\n\t\t\t\t\t\t\tFROM \"EcommerceProductTag_Products\"\n\t\t\t\t\t\t\t\tINNER JOIN \"ModuleProduct{$stage}\"\n\t\t\t\t\t\t\t\t\tON \"ModuleProduct{$stage}\".\"ID\" = \"EcommerceProductTag_Products\".\"ProductID\"\n\t\t\t\t\t\t\tWHERE \"EcommerceProductTag_Products\".\"EcommerceProductTagID\" IN (" . implode(",", $tags->column("ID")) . ")\n\t\t\t\t\t\t");
                     if ($rows) {
                         foreach ($rows as $row) {
                             $idArray[$row["ProductID"]] = $row["ProductID"];
                         }
                     }
                 }
                 if (count($idArray)) {
                     $this->allProducts = $this->allProducts->filter(array("ID" => $idArray));
                 }
             }
         }
     }
     return $this->allProducts;
 }
 private function createtags()
 {
     $products = Product::get()->where("ClassName = 'Product'")->sort("Rand()")->limit(4);
     $this->addExamplePages(1, "Product Tags", $products);
     foreach ($products as $pos => $product) {
         $idArray[$pos] = $product->ID;
         $titleArray[] = $product->MenuTitle;
         $this->addToTitle($product, "with tag", true);
     }
     $page = Page::get()->where("\"URLSegment\" = 'tag-explanation'")->First();
     $t1 = new EcommerceProductTag();
     $t1->Title = "TAG 1";
     $t1->ExplanationPageID = $page->ID;
     $t1->Explanation = "explains Tag 1";
     $t1->write();
     $existingProducts = $t1->Products();
     $existingProducts->addMany(array($idArray[0], $idArray[1]));
     DB::alteration_message("Creating tag: " . $t1->Title . " for " . implode(",", $titleArray), "created");
     $t2 = new EcommerceProductTag();
     $t2->Title = "TAG 2";
     $t2->ExplanationPageID = $page->ID;
     $t2->Explanation = "explains Tag 2";
     $t2->write();
     $existingProducts = $t2->Products();
     $existingProducts->addMany(array($idArray[2], $idArray[3]));
     DB::alteration_message("Creating tag: " . $t2->Title . " for " . implode(",", $titleArray), "created");
     $productGroupWithTags = ProductGroupWithTags::get()->First();
     $existingTags = $productGroupWithTags->EcommerceProductTags();
     $existingTags->addMany(array($t1->ID, $t2->ID));
 }