Example rewrite to disable Magento from falling back to base/default
<?php | |
class Vendor_BaseBlocker_Rewrite_Mage_Core_Model_Design_Package extends Mage_Core_Model_Design_Package | |
{ | |
/** | |
* Magento's function with additional condition to around falling back to base/default | |
* | |
* @author Wenjiang Xu <wenjiang.xu@ampersandcommerce.com> | |
*/ | |
protected function _fallback($file, array &$params, array $fallbackScheme = array(array())) | |
{ | |
if ($this->_shouldFallback) { | |
foreach ($fallbackScheme as $try) { | |
$params = array_merge($params, $try); | |
$filename = $this->validateFile($file, $params); | |
if ($filename) { | |
return $filename; | |
} | |
} | |
// This condition is added to allow certain files to fallback to base/default | |
if ($this->shouldFallbackToBase($file)) { | |
$params['_package'] = self::BASE_PACKAGE; | |
$params['_theme'] = self::DEFAULT_THEME; | |
} | |
} | |
return $this->_renderFilename($file, $params); | |
} | |
/** | |
* This function is a white list, return true to allow file to fallback to base/default | |
* | |
* @param $file | |
* @return bool | |
* @author Wenjiang Xu <wenjiang.xu@ampersandcommerce.com> | |
* @author Yousef Cisco <yc@amp.co> | |
*/ | |
protected function shouldFallbackToBase($file) | |
{ | |
// Allow fallback in adminhtml | |
if ($this->getArea() != self::DEFAULT_AREA) { | |
return true; | |
} | |
$exceptions = array( | |
'vendor', | |
'paypal', | |
'sagepay', | |
'payment', | |
); | |
// Allow exceptions | |
foreach ($exceptions as $exception) { | |
if (stripos($file, $exception) !== false) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment