-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
379 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,11 +103,29 @@ class Easylife_Switcher_Block_Catalog_Product_View_Type_Configurable_Config | |
* default media template | ||
*/ | ||
const DEFAULT_MEDIA_TEMPLATE = 'catalog/product/view/media.phtml'; | ||
/** | ||
* show out of stock combinations | ||
*/ | ||
const XML_SHOW_OUT_OF_STOCK_PATH = 'easylife_switcher/settings/out_of_stock'; | ||
/** | ||
* transform specific dropdowns | ||
*/ | ||
const XML_TRANSFORM_SPECIFIC_PATH = 'easylife_switcher/settings/transform_specific'; | ||
/** | ||
* keep previously selected values | ||
*/ | ||
const XML_KEEP_SELECTED_VALUES = 'easylife_switcher/settings/keep_values'; | ||
/** | ||
* use configurable product image if the simple product does not have one. | ||
*/ | ||
const XML_USE_CONF_IMAGE = 'easylife_switcher/settings/use_conf_image'; | ||
/** | ||
* cache for switch attributes | ||
* @var array | ||
*/ | ||
protected $_switchAttribtues = array(); | ||
protected $_switchAttributes = array(); | ||
|
||
protected $_confProductImage = null; | ||
|
||
/** | ||
* get additional config for configurable products | ||
|
@@ -118,13 +136,19 @@ class Easylife_Switcher_Block_Catalog_Product_View_Type_Configurable_Config | |
public function getJsonAdditionalConfig(){ | ||
$config = array(); | ||
if (Mage::helper('easylife_switcher')->isEnabled()){ | ||
$config['transform_dropdowns'] = Mage::getStoreConfigFlag(self::XML_TRANSFORM_PATH); | ||
$config['transform_dropdowns'] = Mage::getStoreConfig(self::XML_TRANSFORM_PATH); | ||
$config['show_added_prices'] = Mage::getStoreConfigFlag(self::XML_ADDED_PRICES_PATH); | ||
} | ||
$config['stock'] = $this->getStockOptions(); | ||
$config['switch_attributes'] = $this->getSwitchAttributes(); | ||
$config['images'] = $this->getImages(); | ||
$config['option_images'] = $this->getOptionImages(); | ||
if ($config['transform_dropdowns'] == Easylife_Switcher_Model_Adminhtml_System_Config_Source_Transform::SPECIFIC) { | ||
$config['transform_specific'] = explode(',', Mage::getStoreConfig(self::XML_TRANSFORM_SPECIFIC_PATH)); | ||
} | ||
else { | ||
$config['transform_specific'] = array(); | ||
} | ||
|
||
|
||
if (!$this->getProduct()->hasPreconfiguredValues()){ | ||
|
@@ -140,9 +164,13 @@ public function getJsonAdditionalConfig(){ | |
$config['switch_media_selector'] = Mage::getStoreConfig(self::XML_MEDIA_SELECTOR); | ||
$config['switch_media_callback'] = Mage::getStoreConfig(self::XML_MEDIA_CALLBACK_PATH); | ||
$config['allow_no_stock_select'] = Mage::getStoreConfigFlag(self::XML_NO_STOCK_SELECT_PATH); | ||
$config['keep_values'] = Mage::getStoreConfigFlag(self::XML_KEEP_SELECTED_VALUES); | ||
|
||
$config['autoselect_first'] = Mage::getStoreConfigFlag(self::XML_TRANSFORM_PATH) && Mage::getStoreConfigFlag(self::XML_AUTOSELECT_FIRST_PATH); | ||
|
||
$config['autoselect_first'] = /*Mage::getStoreConfigFlag(self::XML_TRANSFORM_PATH) &&*/ Mage::getStoreConfigFlag(self::XML_AUTOSELECT_FIRST_PATH); | ||
$oldCheck = Mage::registry('old_skip_aleable_check'); | ||
if (!is_null($oldCheck)){ | ||
Mage::helper('catalog/product')->setSkipSaleableCheck($oldCheck); | ||
} | ||
return Mage::helper('core')->jsonEncode($config); | ||
} | ||
|
||
|
@@ -195,10 +223,10 @@ public function getConfigurableBlock(){ | |
* @author Marius Strajeru <[email protected]> | ||
*/ | ||
public function getSwitchAttributes($path = self::XML_USE_IMAGES_PATH){ | ||
if (!isset($this->_switchAttribtues[$path])){ | ||
if (!isset($this->_switchAttributes[$path])){ | ||
$allowedString = trim(Mage::getStoreConfig($path),' ,'); | ||
if (!$allowedString){ | ||
$this->_switchAttribtues[$path] = array(); | ||
$this->_switchAttributes[$path] = array(); | ||
} | ||
else{ | ||
$allowed = explode(',', $allowedString); | ||
|
@@ -210,10 +238,10 @@ public function getSwitchAttributes($path = self::XML_USE_IMAGES_PATH){ | |
$allowedAttributeIds[(int)$productAttribute->getId()] = $productAttribute->getAttributeCode(); | ||
} | ||
} | ||
$this->_switchAttribtues[$path] = $allowedAttributeIds; | ||
$this->_switchAttributes[$path] = $allowedAttributeIds; | ||
} | ||
} | ||
return $this->_switchAttribtues[$path]; | ||
return $this->_switchAttributes[$path]; | ||
} | ||
/** | ||
* get attribute option images to use for labels | ||
|
@@ -381,11 +409,30 @@ public function getSwitchImages(){ | |
} | ||
$images[$id][$product->getId()] = (string)$image; | ||
} | ||
elseif (Mage::getStoreConfigFlag(self::XML_USE_CONF_IMAGE)) { | ||
$images[$id][$product->getId()] = (string)$this->getConfProductImage(); | ||
} | ||
} | ||
} | ||
return $images; | ||
} | ||
|
||
/** | ||
* @access public | ||
* @return mixed | ||
* @author Marius Strajeru <[email protected]> | ||
*/ | ||
public function getConfProductImage() { | ||
if (is_null($this->_confProductImage)) { | ||
$this->_confProductImage = Mage::helper('catalog/image')->init($this->getProduct(), 'image'); | ||
$dimensions = $this->_getImageDimensions(); | ||
if (!empty($dimensions)){ | ||
$this->_confProductImage->resize($dimensions[0], $dimensions[1]); | ||
} | ||
} | ||
return $this->_confProductImage; | ||
} | ||
|
||
/** | ||
* get media images for changing full media | ||
* @access public | ||
|
27 changes: 27 additions & 0 deletions
27
app/code/community/Easylife/Switcher/Model/Adminhtml/System/Config/Source/Attributeids.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Easylife_Switcher extension | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the MIT License | ||
* that is bundled with this package in the file LICENSE_EASYLIFE_SWITCHER.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://opensource.org/licenses/mit-license.php | ||
* | ||
* @category Easylife | ||
* @package Easylife_Switcher | ||
* @copyright Copyright (c) 2013 | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
/** | ||
* Source model for available attributes | ||
* | ||
* @category Easylife | ||
* @package Easylife_Switcher | ||
* @author Marius Strajeru <[email protected]> | ||
*/ | ||
class Easylife_Switcher_Model_Adminhtml_System_Config_Source_AttributeIds | ||
extends Easylife_Switcher_Model_Adminhtml_System_Config_Source_Attributes { | ||
protected $_idKey = 'attribute_id'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
* @author Marius Strajeru <[email protected]> | ||
*/ | ||
class Easylife_Switcher_Model_Adminhtml_System_Config_Source_Attributes{ | ||
protected $_idKey = 'attribute_code'; | ||
/** | ||
* available options | ||
* @var null|mixed | ||
|
@@ -52,7 +53,7 @@ public function toOptionArray($withEmpty = true){ | |
if (Mage::getSingleton('catalog/product_type_configurable')->canUseAttribute($attribute)){ | ||
$this->_options[] = array( | ||
'label'=>$attribute->getFrontendLabel(), | ||
'value'=>$attribute->getAttributeCode() | ||
'value'=>$attribute->getData($this->_idKey) | ||
); | ||
} | ||
} | ||
|
57 changes: 57 additions & 0 deletions
57
app/code/community/Easylife/Switcher/Model/Adminhtml/System/Config/Source/Transform.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Easylife_Switcher extension | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the MIT License | ||
* that is bundled with this package in the file LICENSE_EASYLIFE_SWITCHER.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://opensource.org/licenses/mit-license.php | ||
* | ||
* @category Easylife | ||
* @package Easylife_Switcher | ||
* @copyright Copyright (c) 2013 | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
/** | ||
* Source model for available attributes | ||
* | ||
* @category Easylife | ||
* @package Easylife_Switcher | ||
* @author Marius Strajeru <[email protected]> | ||
*/ | ||
class Easylife_Switcher_Model_Adminhtml_System_Config_Source_Transform{ | ||
const ALL = 1; | ||
const NONE = 0; | ||
const SPECIFIC = 2; | ||
/** | ||
* available options | ||
* @var null|mixed | ||
*/ | ||
protected $_options = null; | ||
/** | ||
* get the list of attributes | ||
* @access public | ||
* @param bool $withEmpty | ||
* @return mixed|null | ||
* @author Marius Strajeru <[email protected]> | ||
*/ | ||
public function toOptionArray($withEmpty = true){ | ||
if (is_null($this->_options)){ | ||
$this->_options[] = array( | ||
'value' => self::ALL, | ||
'label' => Mage::helper('easylife_switcher')->__('All') | ||
); | ||
$this->_options[] = array( | ||
'value' => self::NONE, | ||
'label' => Mage::helper('easylife_switcher')->__('None') | ||
); | ||
$this->_options[] = array( | ||
'value' => self::SPECIFIC, | ||
'label' => Mage::helper('easylife_switcher')->__('Specific') | ||
); | ||
} | ||
return $this->_options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.