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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

feature page & product pages with features


Go to End


5 Posts   1831 Views

Avatar
borriej

Community Member, 267 Posts

7 December 2010 at 3:17am

Edited: 07/12/2010 3:19am

Hello,

I've got a few product pages, they must have multiple relations to some features that i will create underneath the page features.

See picture:

The idea:
In the feature page, i want to create subpage. Every subpage is about 1 feature, and also contains text about this feature.
Then.. I create a product page and select all the features that apply for this product.

When you view the product page the checked technology´s should be displayed and the text of that page. The site is multi language.

Downloaded the files and read tutorial5.

How should i create this?
And how do I create just one feature per feature page and link multiple features to product pages.

Avatar
Zauberfisch

Community Member, 30 Posts

8 December 2010 at 2:05am

blubb

once again I'm not sure what the exactly you want, but I just gonna post some code and hope it helps ;)

<?php
class Product extends Page {
  static $many_many = array(
    'ProductVariants' => 'ProductVariant'
  );
  public function getCMSFields() {  
    $fields = parent::getCMSFields();
    $manager = new TranslateableManyManyDataObjectManager(
      $this,
      'ProductVariants',
      'ProductVariant',
      array('Title' => 'Title'),
      'getCMSFields_forPopup',
      "ObjLocale = '".Translatable::get_current_locale()."'"
    );
    $fields->addFieldToTab('Root.Content.Variants', $manager);
    return $fields;

  }
}
class Product_Controller extends Page_Controller {
}
 
class ProductVariant extends DataObject {
   static $db = array(
      'Title' => 'Text',
      'Description' => 'HTMLText',
      'ObjLocale' => 'Text'
   );
   // i use ObjLocale as DB field, since Translatable + DOM doesn't seems to work for me 
   static $belongs_many_many = array(
      'Products' => 'Product'
   );
   function getCMSFields_forPopup() {
      $fields = new FieldSet();
      $fields->push(new TextField('Title'));
      $fields->push(new SimpleHTMLEditorField('Description'));
      if($this->ObjLocale == '')
        $this->ObjLocale = Translatable::get_current_locale();
      $fields->push(new HiddenField('ObjLocale'));
      return $fields;
   }
}

class TranslateableManyManyDataObjectManager extends ManyManyDataObjectManager {
  public function getQueryString($params = array()) {
    $return = parent::getQueryString($params);
    $return .= '&locale='.Translatable::get_current_locale();
    return $return;
  }
	public function AddLink() {
	   // needed to make sure new items get added with the Correct Lang
    return Controller::join_links($this->BaseLink(), '/add?locale='.Translatable::get_current_locale());
	}
}

Avatar
Zauberfisch

Community Member, 30 Posts

8 December 2010 at 3:26am

way 2:

if you want ProductVariant to be a page try something like this:

class Product extends Page {
  static $many_many = array(
    'ProductVariants' => 'ProductVariant'
  ); 
  public function getCMSFields() {
    $fields = parent::getCMSFields();
    $Manager= new TranslateableManyManyDataObjectManager (
      $this,
      'Products',
      'Product',
      array('Title' => 'Title', 'MenuTitle' => 'MenuTitle'),
      'getCMSFields_forPopup',
      "Locale = '".Translatable::get_current_locale()."'" 
    );
    $fields->addFieldToTab('Root.Content.Variants',$Manager);
    return $fields;
  }

class Product_Controller extends Page_Controller {} 

class ProductVariant extends Page {
static $belongs_many_many = array(
'Products' => 'Product'
);  }
class ProductVariant_Controller extends Page_Controller {}


class TranslateableManyManyDataObjectManager extends ManyManyDataObjectManager {
public function getQueryString($params = array()) {
$return = parent::getQueryString($params);
$return .= '&locale='.Translatable::get_current_locale();
return $return;
}
}

i hope this code works for you ;)

(btw i don't know if it is still needed to make your own "TranslateableManyManyDataObjectManager", but when I used this code, I needed to do that to make it work)

Avatar
Zauberfisch

Community Member, 30 Posts

8 December 2010 at 4:15am

Edited: 08/12/2010 4:32am

and instead of DOM you can also use ComplexTableField or simply a TreeMultiselectField

class Product extends Page {
static $many_many = array(
'ProductVariants' => 'ProductVariant'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Variants',new TreeMultiselectField('ProductVariants', 'Select Multiple Variants', 'ProductVariant'));
return $fields;
}

class Product_Controller extends Page_Controller {}

class ProductVariant extends Page {
static $belongs_many_many = array(
'Products' => 'Product'
); }
class ProductVariant_Controller extends Page_Controller {} 

Avatar
Zauberfisch

Community Member, 30 Posts

8 December 2010 at 4:35am

and in template, it doesn't matters with way you pick, all will be the same:

in Product.ss

<h4>this product has the following variants:</h4>
<% control ProductVariants %>
  $Title <!-- Title of the Variant -->
  $Content
  $foobar
<% end_control %>

and in ProductVariants.ss

<h4>this ProductVariant is avaliable for the following Products:</h4>
<% control Products %>
  $Title <!-- Title of the Product -->
  $Content
  $otherStuff
<% end_control %>