/**
  *
  * standard SS method
  * cleans up codes
  */
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $filter = EcommerceCodeFilter::create();
     $filter->checkCode($this);
 }
 /**
  * Adds keywords to the MetaKeyword
  * Standard SS Method
  */
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $config = $this->EcomConfig();
     //set allowpurchase to false IF
     //free products are not allowed to be purchased
     $filter = EcommerceCodeFilter::create();
     $filter->checkCode($this, "InternalItemID");
     $this->prepareFullFields();
     //we are adding all the fields to the keyword fields here for searching purposes.
     //because the MetaKeywords Field is being searched.
     if ($this->Config()->get("add_data_to_meta_description_for_search")) {
         $this->MetaDescription = "";
         $fieldsToExclude = Config::inst()->get("SiteTree", "db");
         foreach ($this->db() as $fieldName => $fieldType) {
             if (is_string($this->{$fieldName}) && strlen($this->{$fieldName}) > 2) {
                 if (!in_array($fieldName, $fieldsToExclude)) {
                     $this->MetaDescription .= strip_tags($this->{$fieldName});
                 }
             }
         }
         if ($this->hasExtension("ProductWithVariationDecorator")) {
             $variations = $this->Variations();
             if ($variations) {
                 $variationCount = $variations->count();
                 if ($variationCount > 0 && $variationCount < 8) {
                     foreach ($variations as $variation) {
                         $this->MetaDescription .= " - " . $variation->FullName;
                     }
                 }
             }
         }
     }
 }