Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » feature page & product pages with features

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 863 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    feature page & product pages with features Link to this post

    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.

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: feature page & product pages with features Link to this post

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

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: feature page & product pages with features Link to this post

    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)

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: feature page & product pages with features Link to this post

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

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: feature page & product pages with features Link to this post

    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 %>

    863 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.