Advertisement
Guest User

Related Products

a guest
Apr 8th, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. <?php
  2. class ProductPage extends Page {
  3. private static $many_many = array(
  4. 'RelatedProducts' => 'Product'
  5. );
  6.  
  7. public function getCMSFields() {
  8. $fields = parent::getCMSFields();
  9.  
  10. $products = ProductPage::get()->exclude(array('ID' => $this->owner->ID));
  11. $gridField = new GridField('products', 'Related Products', $products);
  12. $gridField->getConfig()->addComponent(new GridFieldManyRelationHandler($this, 'RelatedProducts'));
  13.  
  14. $fields->addFieldToTab('Root.RelatedProducts', $gridfield);
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement