Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mage_ConfigurableSwatches - DOC block update #774

Merged
merged 1 commit into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
* @copyright Copyright (c) 2006-2019 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Class Mage_ConfigurableSwatches_Block_Catalog_Layer_State_Swatch
*
* @method $this setJsonConfig(string $value)
* @method int getSwatchInnerHeight()
* @method $this setSwatchInnerHeight(int $value)
* @method int getSwatchInnerWidth()
* @method $this setSwatchInnerWidth(int $value)
* @method $this setSwatchOuterHeight(int $value)
* @method $this setSwatchOuterWidth(int $value)
* @method string getSwatchUrl()
* @method $this setSwatchUrl(string $value)
*/
class Mage_ConfigurableSwatches_Block_Catalog_Layer_State_Swatch extends Mage_Core_Block_Template
{
protected $_initDone = false;
Expand Down Expand Up @@ -57,13 +71,17 @@ protected function _init($filter)
if (!$this->_initDone) {
$dimHelper = Mage::helper('configurableswatches/swatchdimensions');
$this->setSwatchInnerWidth(
$dimHelper->getInnerWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER));
$dimHelper->getInnerWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER)
);
$this->setSwatchInnerHeight(
$dimHelper->getInnerHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER));
$dimHelper->getInnerHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER)
);
$this->setSwatchOuterWidth(
$dimHelper->getOuterWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER));
$dimHelper->getOuterWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER)
);
$this->setSwatchOuterHeight(
$dimHelper->getOuterHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER));
$dimHelper->getOuterHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_LAYER)
);

$swatchUrl = Mage::helper('configurableswatches/productimg')
->getGlobalSwatchUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
* @copyright Copyright (c) 2006-2019 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Class Mage_ConfigurableSwatches_Block_Catalog_Media_Js_Abstract
*/
abstract class Mage_ConfigurableSwatches_Block_Catalog_Media_Js_Abstract extends Mage_Core_Block_Template
{
protected $_template = 'configurableswatches/catalog/media/js.phtml';
Expand All @@ -47,8 +51,9 @@ abstract public function getProducts();
* @param array $imageFallback
* @return string
*/
protected function _getJsImageFallbackString(array $imageFallback) {
/* @var $coreHelper Mage_Core_Helper_Data */
protected function _getJsImageFallbackString(array $imageFallback)
{
/* @var Mage_Core_Helper_Data $coreHelper */
$coreHelper = Mage::helper('core');

return $coreHelper->jsonEncode($imageFallback);
Expand All @@ -68,8 +73,9 @@ abstract protected function _getImageSizes();
* @param null $keepFrame
* @return array
*/
public function getProductImageFallbacks($keepFrame = null) {
/* @var $helper Mage_ConfigurableSwatches_Helper_Mediafallback */
public function getProductImageFallbacks($keepFrame = null)
{
/* @var Mage_ConfigurableSwatches_Helper_Mediafallback $helper */
$helper = Mage::helper('configurableswatches/mediafallback');

$fallbacks = array();
Expand All @@ -80,7 +86,7 @@ public function getProductImageFallbacks($keepFrame = null) {
$keepFrame = $this->isKeepFrame();
}

/* @var $product Mage_Catalog_Model_Product */
/* @var Mage_Catalog_Model_Product $product */
foreach ($products as $product) {
$imageFallback = $helper->getConfigurableImagesFallbackArray($product, $this->_getImageSizes(), $keepFrame);

Expand Down Expand Up @@ -117,7 +123,8 @@ public function isKeepFrame()
*
* @return string
*/
public function getImageType() {
public function getImageType()
{
return parent::getImageType();
}

Expand All @@ -127,7 +134,8 @@ public function getImageType() {
*
* @return string
*/
protected function _toHtml() {
protected function _toHtml()
{
if (!Mage::helper('configurableswatches')->isEnabled()) { // functionality disabled
return ''; // do not render block
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
* @copyright Copyright (c) 2006-2019 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_ConfigurableSwatches_Block_Catalog_Media_Js_List
extends Mage_ConfigurableSwatches_Block_Catalog_Media_Js_Abstract

/**
* Class Mage_ConfigurableSwatches_Block_Catalog_Media_Js_List
*/
class Mage_ConfigurableSwatches_Block_Catalog_Media_Js_List extends Mage_ConfigurableSwatches_Block_Catalog_Media_Js_Abstract
{
/**
* Get target product IDs from product collection
* which was set on block
*
* @return array
*/
public function getProducts() {
public function getProducts()
{
return $this->getProductCollection();
}

Expand All @@ -41,7 +45,8 @@ public function getProducts() {
*
* @return string
*/
public function getImageType() {
public function getImageType()
{
$type = parent::getImageType();

if (empty($type)) {
Expand All @@ -56,7 +61,8 @@ public function getImageType() {
*
* @return array
*/
protected function _getImageSizes() {
protected function _getImageSizes()
{
return array('small_image');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
* @copyright Copyright (c) 2006-2019 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_ConfigurableSwatches_Block_Catalog_Media_Js_Product
extends Mage_ConfigurableSwatches_Block_Catalog_Media_Js_Abstract
class Mage_ConfigurableSwatches_Block_Catalog_Media_Js_Product extends Mage_ConfigurableSwatches_Block_Catalog_Media_Js_Abstract
{
/**
* Return array of single product -- current product
*
* @return array
*/
public function getProducts() {
public function getProducts()
{
$product = Mage::registry('product');

if (!$product) {
Expand All @@ -46,7 +46,8 @@ public function getProducts() {
*
* @return string
*/
public function getImageType() {
public function getImageType()
{
$type = parent::getImageType();

if (empty($type)) {
Expand All @@ -61,7 +62,8 @@ public function getImageType() {
*
* @return array
*/
protected function _getImageSizes() {
protected function _getImageSizes()
{
return array('image');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Class Mage_ConfigurableSwatches_Block_Catalog_Product_List_Price
*
* @method Mage_Eav_Model_Entity_Collection_Abstract getProductCollection()
*/
class Mage_ConfigurableSwatches_Block_Catalog_Product_List_Price extends Mage_Core_Block_Template
{
/**
Expand Down Expand Up @@ -56,7 +61,7 @@ public function getJsonConfig()
'generalConfig' => $compositeProductHelper->prepareJsonGeneralConfig()
);
foreach ($this->getProducts() as $product) {
/** @var $product Mage_Catalog_Model_Product */
/** @var Mage_Catalog_Model_Product $product */
if (!$product->getSwatchPrices()) {
continue;
}
Expand Down Expand Up @@ -91,5 +96,4 @@ protected function _toHtml()

return parent::_toHtml();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Magento
*
Expand All @@ -23,6 +24,16 @@
* @copyright Copyright (c) 2006-2019 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Class Mage_ConfigurableSwatches_Block_Catalog_Product_View_Type_Configurable_Swatches
*
* @method $this setJsonConfig(string $value)
* @method $this setSwatchInnerHeight(int $value)
* @method $this setSwatchInnerWidth(int $value)
* @method $this setSwatchOuterHeight(int $value)
* @method $this setSwatchOuterWidth(int $value)
*/
class Mage_ConfigurableSwatches_Block_Catalog_Product_View_Type_Configurable_Swatches extends Mage_Core_Block_Template
{
protected $_initDone = false;
Expand Down Expand Up @@ -57,13 +68,17 @@ protected function _init($jsonConfig)

$dimHelper = Mage::helper('configurableswatches/swatchdimensions');
$this->setSwatchInnerWidth(
$dimHelper->getInnerWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_DETAIL));
$dimHelper->getInnerWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_DETAIL)
);
$this->setSwatchInnerHeight(
$dimHelper->getInnerHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_DETAIL));
$dimHelper->getInnerHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_DETAIL)
);
$this->setSwatchOuterWidth(
$dimHelper->getOuterWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_DETAIL));
$dimHelper->getOuterWidth(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_DETAIL)
);
$this->setSwatchOuterHeight(
$dimHelper->getOuterHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_DETAIL));
$dimHelper->getOuterHeight(Mage_ConfigurableSwatches_Helper_Swatchdimensions::AREA_DETAIL)
);

$this->_initDone = true;
}
Expand Down
7 changes: 4 additions & 3 deletions app/code/core/Mage/ConfigurableSwatches/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ public function getHyphenatedString($str)
* Trims and lower-cases strings used as array indexes in json and for string matching in a
* multi-byte compatible way if the mbstring module is available.
*
* @param $key
* @param string $key
* @return string
*/
public static function normalizeKey($key) {
public static function normalizeKey($key)
{
if (function_exists('mb_strtolower')) {
return trim(mb_strtolower($key, 'UTF-8'));
}
Expand Down Expand Up @@ -123,7 +124,7 @@ public function attrIsSwatchType($attr)
public function getSwatchesProductJs()
{
/**
* @var $product Mage_Catalog_Model_Product
* @var Mage_Catalog_Model_Product $product
*/
$product = Mage::registry('current_product');
if ($this->isEnabled() && $product) {
Expand Down
83 changes: 41 additions & 42 deletions app/code/core/Mage/ConfigurableSwatches/Helper/List/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,51 +48,51 @@ public function attachConfigurableProductChildrenPricesMapping(array $products,
$listSwatchAttrId = Mage::helper('configurableswatches/productlist')->getSwatchAttributeId();
$result = array();

foreach ($products as $product) {
/** @var $product Mage_Catalog_Model_Product */
if ($product->getTypeId() !== Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE
foreach ($products as $product) {
/** @var Mage_Catalog_Model_Product $product */
if ($product->getTypeId() !== Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE
&& !is_array($product->getChildrenProducts())
) {
continue;
}
) {
continue;
}

/** @var Mage_Catalog_Model_Product_Type_Configurable $typeInstance */
$typeInstance = $product->getTypeInstance();
$allowedAttributes = $typeInstance->getConfigurableAttributeCollection($product);
foreach ($allowedAttributes as $attribute) {
/** @var $attribute Mage_Catalog_Model_Product_Type_Configurable_Attribute */
if ($attribute->getAttributeId() !== $listSwatchAttrId) {
continue;
}
/** @var Mage_Catalog_Model_Product_Type_Configurable $typeInstance */
$typeInstance = $product->getTypeInstance();
$allowedAttributes = $typeInstance->getConfigurableAttributeCollection($product);
foreach ($allowedAttributes as $attribute) {
/** @var Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute */
if ($attribute->getAttributeId() !== $listSwatchAttrId) {
continue;
}

foreach ($attribute->getPrices() as $attributePrice) {
$product->setConfigurablePrice(
$this->_getHelper()->preparePrice(
$product,
$attributePrice['pricing_value'],
$attributePrice['is_percent'],
$storeId
)
);
Mage::dispatchEvent(
'catalog_product_type_configurable_price',
array('product' => $product)
);
$configurablePrice = $product->getConfigurablePrice();
$cofigurableSwatchesHelper = Mage::helper('configurableswatches');
$result[$cofigurableSwatchesHelper::normalizeKey($attributePrice['store_label'])] = array(
foreach ($attribute->getPrices() as $attributePrice) {
$product->setConfigurablePrice(
$this->_getHelper()->preparePrice(
$product,
$attributePrice['pricing_value'],
$attributePrice['is_percent'],
$storeId
)
);
Mage::dispatchEvent(
'catalog_product_type_configurable_price',
array('product' => $product)
);
$configurablePrice = $product->getConfigurablePrice();
$cofigurableSwatchesHelper = Mage::helper('configurableswatches');
$result[$cofigurableSwatchesHelper::normalizeKey($attributePrice['store_label'])] = array(
'price' => $configurablePrice,
'oldPrice' => $this->_getHelper()->prepareOldPrice(
$product,
$attributePrice['pricing_value'],
$attributePrice['is_percent'],
$storeId
),
);
}
}
$product->setSwatchPrices($result);
}
'oldPrice' => $this->_getHelper()->prepareOldPrice(
$product,
$attributePrice['pricing_value'],
$attributePrice['is_percent'],
$storeId
),
);
}
}
$product->setSwatchPrices($result);
}
}

/**
Expand All @@ -114,5 +114,4 @@ public function isEnabled()
{
return Mage::getStoreConfigFlag(self::XML_PATH_SWATCH_PRICE);
}

}
Loading