Changing PageType programmatically
Permalink
I'm creating a package that enhances the built-in eCommerce Gift Registry, and I'm trying to change the page_type of the created pages programmatically via an event extension. What's happening is that the initial page gets created and then when the dialog asks to rename the page, it creates another instance of the page. Both of the generated pages are the correct page_type, but they are just two of them. Here's the code I'm working with.
# my event class
# from my package controller
Can anyone shed some insight on why the pages would be duplicated? (They have unique cIDs). Thanks!
# my event class
class EnhancedRegistryOverride { public function checkPageType($page) { if ($page->getCollectionTypeHandle() == 'registry') { $enhancedRegistryPageType = CollectionType::getByHandle('enhanced_registry', 'core_commerce_enhanced_gift_registry'); $data['ctID'] = $enhancedRegistryPageType->getCollectionTypeID(); $page->update($data); } } }
# from my package controller
public function on_start() { $pkgPath = Package::getByHandle($this->pkgHandle)->getPackagePath(); Events::extend('on_page_add', 'EnhancedRegistryOverride', 'checkPageType', $pkgPath . '/models/enhanced_registry_override.php'); }
Can anyone shed some insight on why the pages would be duplicated? (They have unique cIDs). Thanks!