Developers/Allow siteid NULL in manager

From Aimeos documentation

Developers
Other languages:
English 100%


2016.x version

For certain domains you don't want to bind records to a specific site ID, e.g. if customers should only have one login for all shops and these shops don't share the same parent site. Since core version 2015.01 you are able to extend an existing manager and overwrite the getSearchSiteConditions() method with the following code:

  1. protected function getSearchSiteConditions( \Aimeos\MW\Criteria\Iface $search,
  2. 	array $keys, array $attributes, array $siteIds )
  3. {
  4. 	$cond = array();
  5. 	$sep = $this->getKeySeparator();
  6.  
  7. 	foreach( $keys as $key )
  8. 	{
  9. 		$name = $key . $sep . 'siteid';
  10.  
  11. 		if( isset( $attributes[$name] ) )
  12. 		{
  13. 			$temp = array(
  14. 				$search->compare( '==', $name, $siteIds ),
  15. 				$search->compare( '==', $name, null )
  16. 			);
  17. 			$cond[] = $search->combine( '||', $temp );
  18. 		}
  19. 	}
  20.  
  21. 	return $cond;
  22. }