Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tzyganu committed Oct 22, 2014
1 parent a0bd99b commit f673e8d
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 95 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
Easylife Switcher
========

Configurable products switcher v1.1.0
Configurable products switcher v1.2.0

**Release Notes 1.2.0 - 2014-10-22**

|Type|Issue|Comment|
|----|-----|-----|
|Feature|Manually set attributes to be transformed to labels|You can now choose to transform only specific dropdowns to labels. You have the option to transform all, none, or select the attributes to be turned into labels|
|Feature|Keep selected values|You can keep selected values when changing attributes above the current one. See example on the configuration section for field **Keep previously selected values**|
|Feature|When the image is switched, you can use the cofigurable product image if the simple product does not have its own image| ([35](https://github.com/tzyganu/Switcher/issues/35))|
|Bug Fix|If you choose to show out of stock combinations all the products that are visible in the configurable products page (related, up-sells) are seen as in stock|[55](https://github.com/tzyganu/Switcher/issues/35). This is partially fixed. All the products that are displayed in the configurable product page but are rendered before the main configurable product will still appear in stock even if they are not. All theproducts rendered after the main product will appear with their real stock state. I have a solution to fix this for all the products but it involves rewriting a block or observing the event `core_block_abstract_to_html_before` and I don't want to do either of them.|
|Bug Fix|Images are not switched when the configurable product does not have an image|If the configurable product does not have an image and displays the placeholder, images could not be switched with the ones from the simple product. In the default theme this is fixed changing the main image dom selector to `$('image') || $$('.product-image img')[0]`|

**Release Notes 1.1.0 - 2014-09-05**

Expand Down Expand Up @@ -71,7 +81,9 @@ How to use:
Configuration:
------------
- **Enabled**: This can enable or disable the extension.
- **Transform dropdowns to labels**: If set to `Yes` then in the frontend the default dropdowns for the configurable products will be replaced by labels.
- **Keep previously selected values** - If set to `Yes` it will allow you to keep selected values when changing attributes from above. Example: You have a t-shirt configurable by color and size in the following combinations: Size S in Red and Green, Size L in Red and Green and Blue, Size XL in Blue. If you first select S Red, then change the size to L, the Red color will still be selected. If you change the size to XL nothing will be selected for color because the XL shirt has only Blue available. .
- **Transform dropdowns to labels**: If set to `All` then in the frontend the default dropdowns for the configurable products will be replaced by labels. If set to `Specific` you can select the attributes to be changed to labels.
- **Transform only the following attributes**: Available only the attributes that you would like to be changed to labels. The rest will remain dropdowns.
- **Show added configurable prices in label**: If you set this to `No`, you will not get in the labels or the dropdowns with the configurable attributes the price difference for the different combinations.
- **Show out of stock configurations**: If set to `Yes` then you will see in the configurable product page the out of stock simple product combinations. By default this is disabled in Magento.
- **Allow out of stock products to be selected**: If this is set to `Yes` then the customer will be able to click on the labels for the out of stock combinations and select them. He will still get an error when trying to add it to the cart. If it is set to `No` the labels for out of stock combinations will be disabled.
Expand All @@ -81,6 +93,7 @@ Configuration:
- **Switch product images**: This allows you to change the product image or the whole media block when an attribute combination is changed. If you choose to change the image, this will be changed only if there is one available for the simple product. If you have a lot of simple product combinations and choose to change the whole media block it can lead to performance issues.
- **Change images when these attributes are changed**: It appears only if you choose to change only the main image and allows you to select which attribute change triggers the image change also.
- **Dom selector for main image**: It appears only if you choose to change only the main image. This should be the prototype selector for the main image element. by default it looks for the element with id `image`.
- **Use configurable product image if the simple one does not have images** - If set to `Yes` it will use for simple products that don't have their own image, the configurable product image.
- **Main image size**: It appears only if you choose to change only the main image. You can specify here the main image size, because I cannot read it from the media block. If empty then the image won't be resized.
- **Js Callback after main image change**: It appears only if you choose to change only the main image. This is the javascript code that will be executed after the image changes. Useful if you have image zoom.
- **Change media content when these attributes are changed**: It appears only if you choose to change the media block and it allows you to select which attribute change triggers the media block change also.
Expand Down Expand Up @@ -145,6 +158,11 @@ The extension **might** conflict with other extensions that handle image switchi
The extension might not work if the js variable used for configurable products page is not named `spConfig`.
If you changed it's name, change it in this file also: `app/design/frontend/base/default/template/easylife_switcher/catalog/product/view/type/configurable/config.phtml`

If you are using cloudzoom as an image zoomer You need to set this configuration to make both extensions work:
- **DOM selector for main image:** `$$('#zoom1 img')[0]` - if you are using cloudzoom with ultimo theme. Otherwise this may be different.
- **Js Callback after image change**: `jQuery('#zoom1').data('zoom').destroy();jQuery('#zoom1').attr('href', jQuery('#zoom1 img:first').attr('src'));jQuery('#zoom1').CloudZoom();`
- **Js Callback after media change**: `jQuery('.cloud-zoom, .cloud-zoom-gallery').CloudZoom()`

Bug report:
-----------
<a href="https://github.com/tzyganu/Switcher/issues">Please submit any bugs or feature requests here</a>.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()){
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
);
}
}
Expand Down
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;
}
}
2 changes: 2 additions & 0 deletions app/code/community/Easylife/Switcher/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function checkShowStock(Varien_Event_Observer $observer){
/** @var Mage_Catalog_Model_Product $product */
$product = $observer->getEvent()->getProduct();
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
Mage::register('old_skip_aleable_check', Mage::helper('catalog/product')->getSkipSaleableCheck());
Mage::helper('catalog/product')->setSkipSaleableCheck(Mage::getStoreConfigFlag(self::XML_SHOW_OUT_OF_STOCK_PATH));
}
}
Expand All @@ -54,6 +55,7 @@ public function checkShowStock(Varien_Event_Observer $observer){
*/
public function checkShowStockOnConfigure(Varien_Event_Observer $observer) {
if (Mage::helper('easylife_switcher')->isEnabled()){
Mage::register('old_skip_aleable_check', Mage::helper('catalog/product')->getSkipSaleableCheck());
Mage::helper('catalog/product')->setSkipSaleableCheck(Mage::getStoreConfigFlag(self::XML_SHOW_OUT_OF_STOCK_PATH));
}
return $this;
Expand Down
6 changes: 4 additions & 2 deletions app/code/community/Easylife/Switcher/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,19 @@
<default>
<easylife_switcher>
<settings>
<enabled>1</enabled>
<enabled>0</enabled>
<keep_values>1</keep_values>
<transform_dropdowns>1</transform_dropdowns>
<autoselect_first>1</autoselect_first>
<show_added_prices>1</show_added_prices>
<out_of_stock>1</out_of_stock>
<use_images>color</use_images>
<image_attribute>small_image</image_attribute>
<change_images>1</change_images>
<use_conf_image>1</use_conf_image>
<change_image_attribtues>color</change_image_attribtues>
<change_media_attribtues>color</change_media_attribtues>
<image_selector>$('image')</image_selector>
<image_selector>$('image') || $$('.product-image img')[0]</image_selector>
<image_change_callback>$('image').setStyle({width:'', height:''});$('image').up().addClassName('product-image-zoom');product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');</image_change_callback>
<media_selector>$$('.product-view .product-img-box')[0]</media_selector>
<media_change_callback>product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');</media_change_callback>
Expand Down
Loading

0 comments on commit f673e8d

Please sign in to comment.