Version Notes
This is the initial stable version.
Download this release
Release Info
| Developer | Lister Technologies (P) Ltd |
| Extension | Lister_CookieThemer |
| Version | 0.0.1 |
| Comparing to | |
| See all releases | |
Version 0.0.1
- app/code/community/Lister/CookieThemer/Block/Adminhtml/System/Config/Form/Field/Cookieexceptions.php +18 -0
- app/code/community/Lister/CookieThemer/Helper/Data.php +20 -0
- app/code/community/Lister/CookieThemer/Model/Design/Package.php +146 -0
- app/code/community/Lister/CookieThemer/etc/config.xml +41 -0
- app/code/community/Lister/CookieThemer/etc/system.xml +56 -0
- app/etc/modules/Lister_CookieThemer.xml +8 -0
- package.xml +20 -0
app/code/community/Lister/CookieThemer/Block/Adminhtml/System/Config/Form/Field/Cookieexceptions.php
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Lister_CookieThemer_Block_Adminhtml_System_Config_Form_Field_Cookieexceptions extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
|
| 3 |
+
{
|
| 4 |
+
public function __construct()
|
| 5 |
+
{
|
| 6 |
+
$this->addColumn('cookienv', array(
|
| 7 |
+
'label' => Mage::helper('adminhtml')->__('Cookie Name Value'),
|
| 8 |
+
'style' => 'width:120px',
|
| 9 |
+
));
|
| 10 |
+
$this->addColumn('value', array(
|
| 11 |
+
'label' => Mage::helper('adminhtml')->__('Theme Name'),
|
| 12 |
+
'style' => 'width:120px',
|
| 13 |
+
));
|
| 14 |
+
$this->_addAfter = false;
|
| 15 |
+
$this->_addButtonLabel = Mage::helper('adminhtml')->__('Add Cookie Exception');
|
| 16 |
+
parent::__construct();
|
| 17 |
+
}
|
| 18 |
+
}
|
app/code/community/Lister/CookieThemer/Helper/Data.php
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Lister_CookieThemer_Helper_Data extends Mage_Core_Helper_Abstract {
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* @param cookiename
|
| 6 |
+
* @return cookie value
|
| 7 |
+
*/
|
| 8 |
+
public function getCookieValue($cookie_name){
|
| 9 |
+
$cookie_value = Mage::getModel('core/cookie')->get($cookie_name);
|
| 10 |
+
return $cookie_value;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
app/code/community/Lister/CookieThemer/Model/Design/Package.php
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Lister_CookieThemer_Model_Design_Package extends Mage_Core_Model_Design_Package {
|
| 3 |
+
|
| 4 |
+
private static $_regexMatchCache = array();
|
| 5 |
+
private static $_customThemeTypeCache = array();
|
| 6 |
+
private static $_regpathMatchCache = array();
|
| 7 |
+
|
| 8 |
+
public function getTheme($type) {
|
| 9 |
+
|
| 10 |
+
if (empty($this->_theme[$type])) {
|
| 11 |
+
$this->_theme[$type] = Mage::getStoreConfig('design/theme/'.$type, $this->getStore());
|
| 12 |
+
if ($type !== 'default' && empty($this->_theme[$type])) {
|
| 13 |
+
$this->_theme[$type] = $this->getTheme('default');
|
| 14 |
+
if (empty($this->_theme[$type])) {
|
| 15 |
+
$this->_theme[$type] = self::DEFAULT_THEME;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
// "locale", "layout", "template"
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
// + "default", "skin"
|
| 23 |
+
// set exception value for theme based on cookie, if defined in config
|
| 24 |
+
$instVar = "design/theme/{$type}_cookie";
|
| 25 |
+
$cookieThemeType = $this->_checkAgainstCookie($instVar);
|
| 26 |
+
|
| 27 |
+
$validFolder = $this->validateFolder($cookieThemeType, $type, $instVar);
|
| 28 |
+
if ($cookieThemeType && $validFolder) {
|
| 29 |
+
//validate the existence of the value /folder mentiond in config
|
| 30 |
+
$this->_theme[$type] = $cookieThemeType;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// set exception value for theme, if defined in config
|
| 34 |
+
$customThemeType = $this->_checkUserAgentAgainstRegexps("design/theme/{$type}_ua_regexp");
|
| 35 |
+
if ($customThemeType) {
|
| 36 |
+
$this->_theme[$type] = $customThemeType;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
return $this->_theme[$type];
|
| 40 |
+
}
|
| 41 |
+
/**
|
| 42 |
+
* Return if a folder exists in the name given in the config
|
| 43 |
+
*
|
| 44 |
+
* @param $pathValue - design / skin name
|
| 45 |
+
* @param string $type
|
| 46 |
+
* @param string $instVar
|
| 47 |
+
* @return bool|string
|
| 48 |
+
*/
|
| 49 |
+
public function validateFolder($pathValue, $type, $instVar) {
|
| 50 |
+
if (!$pathValue) {
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
if (!empty(self::$_regpathMatchCache[$instVar][$pathValue])) {
|
| 54 |
+
return self::$_regpathMatchCache[$instVar][$pathValue];
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
return $this->designExists($pathValue, $instVar, $type);
|
| 58 |
+
}
|
| 59 |
+
/**
|
| 60 |
+
* Return if the theme / skin mentioned is a valid folder
|
| 61 |
+
*
|
| 62 |
+
* @param string $themeName
|
| 63 |
+
* @param string $instVar
|
| 64 |
+
* @param string $type
|
| 65 |
+
* @param string $area
|
| 66 |
+
* @return bool|string
|
| 67 |
+
*/
|
| 68 |
+
public function designExists($themeName, $instVar, $type, $area = self::DEFAULT_AREA) {
|
| 69 |
+
$type = ($type == "skin")?'skin':'design';
|
| 70 |
+
self::$_regpathMatchCache[$instVar][$themeName] = is_dir(Mage::getBaseDir($type).DS.$area.DS.$this->getPackageName().DS.$themeName);
|
| 71 |
+
return is_dir(Mage::getBaseDir($type).DS.$area.DS.$this->getPackageName().DS.$themeName);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Get regex rules from config and check cookie against them
|
| 78 |
+
*
|
| 79 |
+
* Rules must be stored in config as a serialized array(['cookienv']=>'...', ['value'] => '...')
|
| 80 |
+
* Will return false or found string.
|
| 81 |
+
*
|
| 82 |
+
* @param string $cookiePath
|
| 83 |
+
* @return mixed
|
| 84 |
+
*/
|
| 85 |
+
protected function _checkAgainstCookie($cookiePath) {
|
| 86 |
+
|
| 87 |
+
if (empty($cookiePath)) {
|
| 88 |
+
return false;
|
| 89 |
+
}
|
| 90 |
+
if (!empty(self::$_customThemeTypeCache[$cookiePath])) {
|
| 91 |
+
return self::$_customThemeTypeCache[$cookiePath];
|
| 92 |
+
}
|
| 93 |
+
$configValueSerialized = Mage::getStoreConfig($cookiePath, $this->getStore());
|
| 94 |
+
|
| 95 |
+
if (!$configValueSerialized) {
|
| 96 |
+
return false;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
$cookiedetails = @unserialize($configValueSerialized);
|
| 100 |
+
if (empty($cookiedetails)) {
|
| 101 |
+
return false;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
return self::getPackageByCookie($cookiedetails, $cookiePath);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Return package name based on design exception rules
|
| 109 |
+
*
|
| 110 |
+
* @param array $rules - design exception rules
|
| 111 |
+
* @param string $cookiePath
|
| 112 |
+
* @return bool|string
|
| 113 |
+
*/
|
| 114 |
+
public static function getPackageByCookie(array $rules, $cookiePath) {
|
| 115 |
+
foreach ($rules as $rule) {
|
| 116 |
+
if (!empty($rule['cookienv'])) {
|
| 117 |
+
/* Switching mobile theme based on cookie */
|
| 118 |
+
if (strpos($rule['cookienv'], "|") > 0) {
|
| 119 |
+
$cookieNameValue = str_replace("|", "_", trim($rule['cookienv']));
|
| 120 |
+
if (!empty(self::$_regexMatchCache[$cookieNameValue][$cookiePath])) {
|
| 121 |
+
/* Switching mobile theme based on cookie */
|
| 122 |
+
self::$_customThemeTypeCache[$cookiePath] = $rule['value'];
|
| 123 |
+
return $rule['value'];
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
$cookieDetailsArray = explode("|", $rule['cookienv']);
|
| 127 |
+
if (is_array($cookieDetailsArray)) {
|
| 128 |
+
$cookieName = $cookieDetailsArray[0];
|
| 129 |
+
$valFromConfig = $cookieDetailsArray[1];
|
| 130 |
+
$cookieVal = Lister_CookieThemer_Helper_Data::getCookieValue($cookieName);
|
| 131 |
+
if ($cookieVal == $valFromConfig) {
|
| 132 |
+
self::$_regexMatchCache[$cookieNameValue][$cookiePath] = true;
|
| 133 |
+
self::$_customThemeTypeCache[$cookiePath] = $rule['value'];
|
| 134 |
+
return $rule['value'];
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
$regexp = str_replace("|", "_", trim($rule['cookienv']));
|
| 141 |
+
|
| 142 |
+
}
|
| 143 |
+
return false;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
}
|
app/code/community/Lister/CookieThemer/etc/config.xml
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Lister_CookieThemer>
|
| 5 |
+
<version>1.0.0.0</version>
|
| 6 |
+
</Lister_CookieThemer>
|
| 7 |
+
</modules>
|
| 8 |
+
<global>
|
| 9 |
+
<blocks>
|
| 10 |
+
<cookiethemer>
|
| 11 |
+
<class>Lister_CookieThemer_Block</class>
|
| 12 |
+
</cookiethemer>
|
| 13 |
+
</blocks>
|
| 14 |
+
<models>
|
| 15 |
+
<cookiethemer>
|
| 16 |
+
<class>Lister_CookieThemer_Model</class>
|
| 17 |
+
</cookiethemer>
|
| 18 |
+
<core>
|
| 19 |
+
<rewrite>
|
| 20 |
+
<design_package>Lister_CookieThemer_Model_Design_Package</design_package>
|
| 21 |
+
</rewrite>
|
| 22 |
+
</core>
|
| 23 |
+
</models>
|
| 24 |
+
<helpers>
|
| 25 |
+
<cookiethemer>
|
| 26 |
+
<class>Lister_CookieThemer_Helper</class>
|
| 27 |
+
</cookiethemer>
|
| 28 |
+
</helpers>
|
| 29 |
+
</global>
|
| 30 |
+
<admin>
|
| 31 |
+
<routers>
|
| 32 |
+
<adminhtml>
|
| 33 |
+
<args>
|
| 34 |
+
<modules>
|
| 35 |
+
<cookiethemer before="Mage_Adminhtml">Lister_CookieThemer_Adminhtml</cookiethemer>
|
| 36 |
+
</modules>
|
| 37 |
+
</args>
|
| 38 |
+
</adminhtml>
|
| 39 |
+
</routers>
|
| 40 |
+
</admin>
|
| 41 |
+
</config>
|
app/code/community/Lister/CookieThemer/etc/system.xml
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<sections>
|
| 4 |
+
<design translate="label" module="core">
|
| 5 |
+
<label>Design</label>
|
| 6 |
+
<tab>general</tab>
|
| 7 |
+
<frontend_type>text</frontend_type>
|
| 8 |
+
<sort_order>30</sort_order>
|
| 9 |
+
<show_in_default>1</show_in_default>
|
| 10 |
+
<show_in_website>1</show_in_website>
|
| 11 |
+
<show_in_store>1</show_in_store>
|
| 12 |
+
<groups>
|
| 13 |
+
<theme translate="label">
|
| 14 |
+
<label>Themes</label>
|
| 15 |
+
<frontend_type>text</frontend_type>
|
| 16 |
+
<sort_order>2</sort_order>
|
| 17 |
+
<show_in_default>1</show_in_default>
|
| 18 |
+
<show_in_website>1</show_in_website>
|
| 19 |
+
<show_in_store>1</show_in_store>
|
| 20 |
+
<fields>
|
| 21 |
+
<template_cookie translate="comment">
|
| 22 |
+
<label></label>
|
| 23 |
+
<frontend_model>cookiethemer/adminhtml_system_config_form_field_cookieexceptions</frontend_model>
|
| 24 |
+
<backend_model>adminhtml/system_config_backend_design_exception</backend_model>
|
| 25 |
+
<sort_order>26</sort_order>
|
| 26 |
+
<show_in_default>1</show_in_default>
|
| 27 |
+
<show_in_website>1</show_in_website>
|
| 28 |
+
<show_in_store>1</show_in_store>
|
| 29 |
+
<comment>Enter cookiename|cookievalue.Change theme based on the Cookie Match .Match expressions in the same order as displayed in the configuration.</comment>
|
| 30 |
+
</template_cookie>
|
| 31 |
+
<skin_cookie translate="comment">
|
| 32 |
+
<label></label>
|
| 33 |
+
<frontend_model>cookiethemer/adminhtml_system_config_form_field_cookieexceptions</frontend_model>
|
| 34 |
+
<backend_model>adminhtml/system_config_backend_design_exception</backend_model>
|
| 35 |
+
<sort_order>36</sort_order>
|
| 36 |
+
<show_in_default>1</show_in_default>
|
| 37 |
+
<show_in_website>1</show_in_website>
|
| 38 |
+
<show_in_store>1</show_in_store>
|
| 39 |
+
<comment>Enter cookiename|cookievalue.Change skin based on the Cookie Match .Match expressions in the same order as displayed in the configuration.</comment>
|
| 40 |
+
</skin_cookie>
|
| 41 |
+
<layout_cookie translate="comment">
|
| 42 |
+
<label></label>
|
| 43 |
+
<frontend_model>cookiethemer/adminhtml_system_config_form_field_cookieexceptions</frontend_model>
|
| 44 |
+
<backend_model>adminhtml/system_config_backend_design_exception</backend_model>
|
| 45 |
+
<sort_order>56</sort_order>
|
| 46 |
+
<show_in_default>1</show_in_default>
|
| 47 |
+
<show_in_website>1</show_in_website>
|
| 48 |
+
<show_in_store>1</show_in_store>
|
| 49 |
+
<comment>Enter cookiename|cookievalue.Change layout based on the Cookie Match .Match expressions in the same order as displayed in the configuration.</comment>
|
| 50 |
+
</layout_cookie>
|
| 51 |
+
</fields>
|
| 52 |
+
</theme>
|
| 53 |
+
</groups>
|
| 54 |
+
</design>
|
| 55 |
+
</sections>
|
| 56 |
+
</config>
|
app/etc/modules/Lister_CookieThemer.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<config>
|
| 2 |
+
<modules>
|
| 3 |
+
<Lister_CookieThemer>
|
| 4 |
+
<active>true</active>
|
| 5 |
+
<codePool>community</codePool>
|
| 6 |
+
</Lister_CookieThemer>
|
| 7 |
+
</modules>
|
| 8 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Lister_CookieThemer</name>
|
| 4 |
+
<version>0.0.1</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license>Open Software License (OSL)</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>CookieThemer - Module allows us to switch multiple themes for a website based on the cookie set in the page</summary>
|
| 10 |
+
<description>Magento Installations by default allows only one theme to be associated for a website . If you want to test the response for a new design for the same website , by showing only the new design to a certain percent of people and the old design to other people based on geo-location ,we have no inbuilt support.
|
| 11 |
+

|
| 12 |
+
This module helps to reduce the pain by allowing us to set multiple themes for a website ( like we write exceptions for mobile site based on the useragent) . The logic is decided by the cookie name and cookie value set from Test and Target or from external sites which decides which users gets to see the redesigned / old cart .</description>
|
| 13 |
+
<notes>This is the initial stable version.</notes>
|
| 14 |
+
<authors><author><name>Lister Technologies (P) Ltd</name><user>Lister</user><email>senthil.muppidathi@listertechnologies.com</email></author></authors>
|
| 15 |
+
<date>2016-04-13</date>
|
| 16 |
+
<time>06:14:22</time>
|
| 17 |
+
<contents><target name="magecommunity"><dir name="Lister"><dir name="CookieThemer"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Cookieexceptions.php" hash="1d56cd8b8d7d6031f7585b05a8c84843"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="c269e71e6392be2928d16e777df27502"/></dir><dir name="Model"><dir name="Design"><file name="Package.php" hash="a6d881d311d4b42bab735ea2dd7a67d9"/></dir></dir><dir name="etc"><file name="config.xml" hash="52ada04b767a4a3befd5c15a443a5935"/><file name="system.xml" hash="c786b6940f42bdefc2dbbde172ebd525"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Lister_CookieThemer.xml" hash="afcf81d3137642a5bd2d16efdac01c94"/></dir></target></contents>
|
| 18 |
+
<compatible/>
|
| 19 |
+
<dependencies><required><php><min>5.1.0</min><max>5.6.9</max></php></required></dependencies>
|
| 20 |
+
</package>
|
