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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Sort Order Not Working


Reply

640 Views

Avatar
Media Contour

18 February 2012 at 2:12pm (Last edited: 21 February 2012 7:36am), Community Member, 33 Posts

Please reference code below.

I'm able to sort the CatalogProducts in the admin but it does not get rendered in the HomePage by the sort order. I'm not sure what the problem is as the sort order gets saved in the admin. What is it sorting by? Why is it sorting by that?

_config.php

SortableDataObject::add_sortable_classes(array('CatalogProduct'));

CatalogProduct.php

class CatalogProduct extends Page {
   static $belongs_many_many = array('HomePage' => 'HomePage');
}

class CatalogProduct_Controller extends Page_Controller {}

HomePage.php

class HomePage extends Page {
   public static $many_many = array('CarouselProducts' => 'CatalogProduct');
   
   function getCMSFields() {
      $fields = parent::getCMSFields();
      
      $carousel = new ManyManyDataObjectManager(
         $this,
         'CarouselProducts',
         'CatalogProduct',
         array('Title' => 'Title'),
         'getCMSFields_forPopup'
      );
      $fields->addFieldToTab('Root.Content.CarouselProducts', new LiteralField('Carousel Products Break', '<br />'));
      $fields->addFieldToTab('Root.Content.CarouselProducts', new LabelField('Carousel Products Label', 'Carousel Products'));
      $fields->addFieldToTab('Root.Content.CarouselProducts', $carousel);
      
      return $fields;
   }
}

class HomePage_Controller extends Page_Controller {
   public static $allowed_actions = array ();

   public function init() {
      parent::init();
   }
}

HomePage.ss

<% control CarouselProducts %>
   <a href="$Link">$Title</a>
<% end_control %>