3

I'm trying to extend the magento widget insertion functionality (under CMS menu). specifically i'd like to add 'Enabled' and also an Active From/To.

I can do this on the admin interface in the normal way, however i can't seem to track down how the layout updates are loaded. ideally i'd like to be able to intercept the point where it gets the list of widgets from the db\collection and apply some conditional logic to ignore widgets that aren't yet active. I know if i get this working that caching could make it unreliable, but that's less of a concern.

If anyone could point me in the right direction, i'd appreciate it.

Thanks in advance.

  • Do you mean that you want to show widgets on the front end if they are added and enabled via the admin? – David Manners May 20 '14 at 8:32
  • yes sort of. i'd like to extend the base widget so that each has an 'active' and a from\to date. but yes i want that to influence the front end - only an enabled widget should be visible\do whatever it is supposed to do. – Dean May 20 '14 at 10:39
  • An example use case is a product offer that expires (want to pre-set the date) or to allow me to queue up widgets and manually make them active on the date of my choosing – Dean May 20 '14 at 10:40
0

So from the front end what happens with these layout updates is as follows.

Firstly they are stored in the table core_layout_update. This will store the handle and the xml code snippet that is required. Note that the link between widget and layout update is in the table widget_instance_page_layout.

During the layout load in the file Mage_Core_Model_Layout_Update there is a call to merge all the layout information based on the handle.

This in turn calls the $this->fetchDbLayoutUpdates($handle); which will load any information based on the given layout handle from the table core_layout_update and create a xml string from the results. This update will then be added to the layout.

I would suggest that one function you could look into extending would be Mage_Core_Model_Resource_Layout::fetchUpdatesByHandle and adding your filter checks here.

  • Thanks. i had implemented this in the template which is obviously quite inefficient – Dean Nov 11 '14 at 11:56
0

Looks like this is done in Mage/Widget/Model/Widget.php. The function getWidgetsXml() builds the list of the configured widgets. Looks like it already has a filtering option, but rewriting that function seems to be the simplest thing to do. Just check for whatever you want to hardcode first and then let it do it's filter check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.