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.

Data Model Questions /

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

Compare dynamic page-attributes


Go to End


6 Posts   1885 Views

Avatar
SamSmooth

Community Member, 18 Posts

17 September 2010 at 6:49pm

I need to compare products on my page.

The product-pages are grouped by holders.
My plan is to setup an arbitrary list of attribute-fields for each holder, that can be filled-in in the product-page administration.

Anyone around who can give assistance? Is there a best practice?

Avatar
SamSmooth

Community Member, 18 Posts

30 September 2010 at 12:12am

Nobody who could give a hint for a product comparison?

Avatar
swaiba

Forum Moderator, 1899 Posts

30 September 2010 at 12:34am

I think we'd need some more info... what is your dataobject page you are looking to compare, can you include code?

Avatar
SamSmooth

Community Member, 18 Posts

30 September 2010 at 2:51am

Thank you swaiba for your reply.

I do not have code to show yet. I'm just searching for the right approach.

To compare products I'll need to have extendable attribute keys which I'd like to declare with the product-group (holder).
But I've no idea how to store the values to each product.

Avatar
swaiba

Forum Moderator, 1899 Posts

30 September 2010 at 2:59am

are you intending to use the eCommerce module?

Avatar
SamSmooth

Community Member, 18 Posts

30 September 2010 at 7:17am

Edited: 30/09/2010 7:19am

No. It's just a product presentation, no shop.

Now here's my first approach:

class ProductAttribute extends DataObject {
   static $db = array(
      'Attribute' => 'Text',
      'Value' => 'Text',
   );
   
   static $has_one = array(
   		'ProductPage' => 'ProductPage',
   );
   
   static $field_names = array(
      'Attribute' => 'Attribute',
      'Value' => 'Value',
   );
    
   function getCMSFields_forPopup() {
   	
      $fields = new FieldSet();

	  $attributes = DataObject::get('ProductHolderAttribute');
      if ($attributes) {
		 $attributes = $attributes->toDropdownMap('Title', 'Title', '(Select one)', true);
	  }

	  $fields->push(new DropdownField('Attribute', 'Attribute', $attributes));
	  $fields->push(new TextField('Value', 'Value'));
   
      return $fields;
   }
}

In the page:

 function getCMSFields() {

      $fields = parent::getCMSFields();

        $attributetable = new ComplexTableField(
         $this,
         'ProductAttributes', // relation name
         'ProductAttribute', // object class
         ProductAttribute::$field_names, // fields to show in table
         ProductAttribute::getCMSFields_forPopup(), // form that pops up for edit
         "ProductPageID = {$this->ID}", // a filter to only display item associated with this page
      );
      $fields->addFieldToTab('Root.Content.Specifications', $attributetable); 
      return $fields;
   }