Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Compare dynamic page-attributes

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

Page: 1
Go to End
Author Topic: 1097 Views
  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Compare dynamic page-attributes Link to this post

    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?

  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Re: Compare dynamic page-attributes Link to this post

    Nobody who could give a hint for a product comparison?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Compare dynamic page-attributes Link to this post

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

  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Re: Compare dynamic page-attributes Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Compare dynamic page-attributes Link to this post

    are you intending to use the eCommerce module?

  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Re: Compare dynamic page-attributes Link to this post

    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;
    }

    1097 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.