Display Dynamic SKU on configurable product view Magento using Image SwatchConfigurable Dynamic Images: Using Multiple AttributesConfigurable swatch image changes back to default image after selecting attributeHow to stop product image changing with wrong swatch?Dynamically updating the sku on the product page of a configurable product based on selected optionsOrganic Simple Configurable Product Prices In SwatchConfigurable product image resolution issueShow simple products SKU on product page when the attributes of a configurable product is selectedMagento 2.2.6, Configurable Products: Blank Image-Area after deselecting “visual swatch” on product-pageHow to get simple product id from configurable options in Magento 2?Configurable Product Dropdown Image Switch
Breaker Mapping Questions
How does the OS tell whether an "Address is already in use"?
Why is the UK so stuck on the "backstop" when their leadership seems to think that no border will be needed in Northern Ireland?
Is it legal for source code containing undefined behavior to crash the compiler?
Unlock your Lock
Do clerics commit a sin if they do not recite the liturgy of the hours?
Dealing with stress in coding interviews
How were medieval castles built in swamps or marshes without draining them?
Why is "-ber" the suffix of the last four months of the year?
Why does matter stays collapsed following the supernova explosion?
Discussing work with supervisor in an invited dinner with his family
How to check whether a sublist exist in a huge database lists in a fast way?
Count the number of paths to n
Set orthographic view using python?
LINQ for generating all possible permutations
How many lines of code does the original TeX contain?
How do I feed my black hole?
Hangman game in Python - need feedback on the quality of code
Expressing an implication as ILP where each implication term comprises a chain of boolean ORs
Tex Quotes(UVa 272)
How do I remap "å" to type "å"?
Location of label edges in Tikz Graph
Is a memoized pure function itself considered pure?
How to use properly "sich selbst"
Display Dynamic SKU on configurable product view Magento using Image Swatch
Configurable Dynamic Images: Using Multiple AttributesConfigurable swatch image changes back to default image after selecting attributeHow to stop product image changing with wrong swatch?Dynamically updating the sku on the product page of a configurable product based on selected optionsOrganic Simple Configurable Product Prices In SwatchConfigurable product image resolution issueShow simple products SKU on product page when the attributes of a configurable product is selectedMagento 2.2.6, Configurable Products: Blank Image-Area after deselecting “visual swatch” on product-pageHow to get simple product id from configurable options in Magento 2?Configurable Product Dropdown Image Switch
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I've used the code from the answer in this thread:
https://stackoverflow.com/questions/13444995/display-dynamic-sku-on-configurable-product-view-magento
It works great when I'm using the drop down to select the simple product on the configurable product page. The issue is I'm using the image swatch feature to select the simple product instead of the dropdown.
Does anyone know of a way to accomplish this using the image swatch? I've noticed that with the dropdown it displays way more information in the DOM than it does with the image swatch.
I'm using 1.9
magento-1.9 configurable-product sku
add a comment |
I've used the code from the answer in this thread:
https://stackoverflow.com/questions/13444995/display-dynamic-sku-on-configurable-product-view-magento
It works great when I'm using the drop down to select the simple product on the configurable product page. The issue is I'm using the image swatch feature to select the simple product instead of the dropdown.
Does anyone know of a way to accomplish this using the image swatch? I've noticed that with the dropdown it displays way more information in the DOM than it does with the image swatch.
I'm using 1.9
magento-1.9 configurable-product sku
Have you find any solutions for the problem ? Anyone can post an update who solve this problem ?
by comment by Cantemir Alex
– Amit Bera♦
Apr 1 '16 at 10:23
@AmitBera I found an extension that may work, I should be installing it within the next few days and can let you know if it works.
– user3330820
Apr 5 '16 at 14:51
@user3330820 any update on this? did you find the solution? i'm looking for the solution on the same
– Guruprasad
Jun 1 '17 at 5:08
add a comment |
I've used the code from the answer in this thread:
https://stackoverflow.com/questions/13444995/display-dynamic-sku-on-configurable-product-view-magento
It works great when I'm using the drop down to select the simple product on the configurable product page. The issue is I'm using the image swatch feature to select the simple product instead of the dropdown.
Does anyone know of a way to accomplish this using the image swatch? I've noticed that with the dropdown it displays way more information in the DOM than it does with the image swatch.
I'm using 1.9
magento-1.9 configurable-product sku
I've used the code from the answer in this thread:
https://stackoverflow.com/questions/13444995/display-dynamic-sku-on-configurable-product-view-magento
It works great when I'm using the drop down to select the simple product on the configurable product page. The issue is I'm using the image swatch feature to select the simple product instead of the dropdown.
Does anyone know of a way to accomplish this using the image swatch? I've noticed that with the dropdown it displays way more information in the DOM than it does with the image swatch.
I'm using 1.9
magento-1.9 configurable-product sku
magento-1.9 configurable-product sku
edited May 23 '17 at 12:37
Community♦
1
1
asked Feb 22 '16 at 17:38
user3330820user3330820
761 silver badge8 bronze badges
761 silver badge8 bronze badges
Have you find any solutions for the problem ? Anyone can post an update who solve this problem ?
by comment by Cantemir Alex
– Amit Bera♦
Apr 1 '16 at 10:23
@AmitBera I found an extension that may work, I should be installing it within the next few days and can let you know if it works.
– user3330820
Apr 5 '16 at 14:51
@user3330820 any update on this? did you find the solution? i'm looking for the solution on the same
– Guruprasad
Jun 1 '17 at 5:08
add a comment |
Have you find any solutions for the problem ? Anyone can post an update who solve this problem ?
by comment by Cantemir Alex
– Amit Bera♦
Apr 1 '16 at 10:23
@AmitBera I found an extension that may work, I should be installing it within the next few days and can let you know if it works.
– user3330820
Apr 5 '16 at 14:51
@user3330820 any update on this? did you find the solution? i'm looking for the solution on the same
– Guruprasad
Jun 1 '17 at 5:08
Have you find any solutions for the problem ? Anyone can post an update who solve this problem ?
by comment by Cantemir Alex– Amit Bera♦
Apr 1 '16 at 10:23
Have you find any solutions for the problem ? Anyone can post an update who solve this problem ?
by comment by Cantemir Alex– Amit Bera♦
Apr 1 '16 at 10:23
@AmitBera I found an extension that may work, I should be installing it within the next few days and can let you know if it works.
– user3330820
Apr 5 '16 at 14:51
@AmitBera I found an extension that may work, I should be installing it within the next few days and can let you know if it works.
– user3330820
Apr 5 '16 at 14:51
@user3330820 any update on this? did you find the solution? i'm looking for the solution on the same
– Guruprasad
Jun 1 '17 at 5:08
@user3330820 any update on this? did you find the solution? i'm looking for the solution on the same
– Guruprasad
Jun 1 '17 at 5:08
add a comment |
1 Answer
1
active
oldest
votes
You can follow below code for swatches:
app/design/frontend/rwd/my_theme/template/configurableswatches/catalog/product/view/type/options/configurable/swatches.phtml
<?php
$_product = $this->getProduct();
$_attribute = $this->getAttributeObj();
$_jsonConfig = $this->getJsonConfig();
$_config = json_decode($_jsonConfig);
$_swatchInnerWidth = $this->getSwatchInnerWidth();
$_swatchInnerHeight = $this->getSwatchInnerHeight();
$_swatchOuterWidth = $this->getSwatchOuterWidth();
$_swatchOuterHeight = $this->getSwatchOuterHeight();
$_attr = $_attribute->getProductAttribute();
$_attrCode = $_attr->getAttributeCode();
$_id = $_attribute->getAttributeId();
$_swatchArray = $_config->attributes->$_id;
?>
<dt class="swatch-attr abc">
<label id="<?php echo $_attrCode ?>_label" class="required">
<?php echo $_attribute->getLabel() ?>:<em>*</em>
</label>
</dt>
<dd class="clearfix swatch-attr bc <?php if ($_attribute->decoratedIsLast) echo ' last'; ?>">
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select no-display swatch-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
<ul id="configurable_swatch_<?php echo $_attrCode ?>" class="configurable-swatch-list clearfix">
<?php foreach ($_swatchArray->options as $_option): ?>
<?php
$_optionCode = Mage::helper('configurableswatches')->getHyphenatedString($_option->label);
$_swatchUrl = Mage::helper('configurableswatches/productimg')->getSwatchUrl($_product, $_option->label, $_swatchInnerWidth, $_swatchInnerHeight, $_swatchType);
$_hasImage = !empty($_swatchUrl);
$_liClass = '';
$_aClass = 'swatch-link swatch-link-' . $_attribute->getAttributeId();
if ($_hasImage)
$_liClass .= $_swatchType == 'media' ? ' is-media' : '';
$_aClass .= ' has-image';
elseif (strlen($_option->label) > 3)
$_liClass .= ' wide-swatch';
?>
<li class="option-<?php echo $_optionCode; ?><?php echo $_liClass; ?>" id="option<?php echo $_option->id; ?>">
<a onclick="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this, <?php echo $_option->id; ?>);" href="javascript:void(0)" name="<?php echo $_optionCode; ?>" id="swatch<?php echo $_option->id; ?>" class="<?php echo $_aClass ?>" title="<?php echo $_option->label; ?>"
style="height: <?php echo $_swatchOuterHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchOuterWidth ?>px;">
<span class="swatch-label" style="height: <?php echo $_swatchInnerHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchInnerWidth ?>px; line-height: <?php echo $_swatchInnerHeight ?>px;">
<?php if ($_hasImage): ?>
<img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_option->label; ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />
<?php else: ?>
<?php echo $_option->label; ?>
<?php endif; ?>
</span>
<span class="x">X</span>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</dd>
<div id="sku-container"></div>
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$productMap = array();
$atLable = array();
$unitLabel = '';
foreach($col as $simpleProduct)
$productMap[$simpleProduct->getId()] = $simpleProduct->getSku();
?>
<script type="text/javascript">
function changeSku(confAttributeId, sel, pid)
var productMap = <?php echo Mage::helper('core')->jsonEncode($productMap);?>;
var selectedAttributeId = pid;
if (selectedAttributeId)
var options = spConfig.config.attributes[confAttributeId].options;
var productId = options.find(function (option) return option.id == selectedAttributeId).products[0]
$("sku-container").update("<strong>Product Id: </strong>" + productMap[productId]);
else
$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");
</script>
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f102850%2fdisplay-dynamic-sku-on-configurable-product-view-magento-using-image-swatch%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can follow below code for swatches:
app/design/frontend/rwd/my_theme/template/configurableswatches/catalog/product/view/type/options/configurable/swatches.phtml
<?php
$_product = $this->getProduct();
$_attribute = $this->getAttributeObj();
$_jsonConfig = $this->getJsonConfig();
$_config = json_decode($_jsonConfig);
$_swatchInnerWidth = $this->getSwatchInnerWidth();
$_swatchInnerHeight = $this->getSwatchInnerHeight();
$_swatchOuterWidth = $this->getSwatchOuterWidth();
$_swatchOuterHeight = $this->getSwatchOuterHeight();
$_attr = $_attribute->getProductAttribute();
$_attrCode = $_attr->getAttributeCode();
$_id = $_attribute->getAttributeId();
$_swatchArray = $_config->attributes->$_id;
?>
<dt class="swatch-attr abc">
<label id="<?php echo $_attrCode ?>_label" class="required">
<?php echo $_attribute->getLabel() ?>:<em>*</em>
</label>
</dt>
<dd class="clearfix swatch-attr bc <?php if ($_attribute->decoratedIsLast) echo ' last'; ?>">
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select no-display swatch-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
<ul id="configurable_swatch_<?php echo $_attrCode ?>" class="configurable-swatch-list clearfix">
<?php foreach ($_swatchArray->options as $_option): ?>
<?php
$_optionCode = Mage::helper('configurableswatches')->getHyphenatedString($_option->label);
$_swatchUrl = Mage::helper('configurableswatches/productimg')->getSwatchUrl($_product, $_option->label, $_swatchInnerWidth, $_swatchInnerHeight, $_swatchType);
$_hasImage = !empty($_swatchUrl);
$_liClass = '';
$_aClass = 'swatch-link swatch-link-' . $_attribute->getAttributeId();
if ($_hasImage)
$_liClass .= $_swatchType == 'media' ? ' is-media' : '';
$_aClass .= ' has-image';
elseif (strlen($_option->label) > 3)
$_liClass .= ' wide-swatch';
?>
<li class="option-<?php echo $_optionCode; ?><?php echo $_liClass; ?>" id="option<?php echo $_option->id; ?>">
<a onclick="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this, <?php echo $_option->id; ?>);" href="javascript:void(0)" name="<?php echo $_optionCode; ?>" id="swatch<?php echo $_option->id; ?>" class="<?php echo $_aClass ?>" title="<?php echo $_option->label; ?>"
style="height: <?php echo $_swatchOuterHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchOuterWidth ?>px;">
<span class="swatch-label" style="height: <?php echo $_swatchInnerHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchInnerWidth ?>px; line-height: <?php echo $_swatchInnerHeight ?>px;">
<?php if ($_hasImage): ?>
<img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_option->label; ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />
<?php else: ?>
<?php echo $_option->label; ?>
<?php endif; ?>
</span>
<span class="x">X</span>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</dd>
<div id="sku-container"></div>
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$productMap = array();
$atLable = array();
$unitLabel = '';
foreach($col as $simpleProduct)
$productMap[$simpleProduct->getId()] = $simpleProduct->getSku();
?>
<script type="text/javascript">
function changeSku(confAttributeId, sel, pid)
var productMap = <?php echo Mage::helper('core')->jsonEncode($productMap);?>;
var selectedAttributeId = pid;
if (selectedAttributeId)
var options = spConfig.config.attributes[confAttributeId].options;
var productId = options.find(function (option) return option.id == selectedAttributeId).products[0]
$("sku-container").update("<strong>Product Id: </strong>" + productMap[productId]);
else
$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");
</script>
add a comment |
You can follow below code for swatches:
app/design/frontend/rwd/my_theme/template/configurableswatches/catalog/product/view/type/options/configurable/swatches.phtml
<?php
$_product = $this->getProduct();
$_attribute = $this->getAttributeObj();
$_jsonConfig = $this->getJsonConfig();
$_config = json_decode($_jsonConfig);
$_swatchInnerWidth = $this->getSwatchInnerWidth();
$_swatchInnerHeight = $this->getSwatchInnerHeight();
$_swatchOuterWidth = $this->getSwatchOuterWidth();
$_swatchOuterHeight = $this->getSwatchOuterHeight();
$_attr = $_attribute->getProductAttribute();
$_attrCode = $_attr->getAttributeCode();
$_id = $_attribute->getAttributeId();
$_swatchArray = $_config->attributes->$_id;
?>
<dt class="swatch-attr abc">
<label id="<?php echo $_attrCode ?>_label" class="required">
<?php echo $_attribute->getLabel() ?>:<em>*</em>
</label>
</dt>
<dd class="clearfix swatch-attr bc <?php if ($_attribute->decoratedIsLast) echo ' last'; ?>">
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select no-display swatch-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
<ul id="configurable_swatch_<?php echo $_attrCode ?>" class="configurable-swatch-list clearfix">
<?php foreach ($_swatchArray->options as $_option): ?>
<?php
$_optionCode = Mage::helper('configurableswatches')->getHyphenatedString($_option->label);
$_swatchUrl = Mage::helper('configurableswatches/productimg')->getSwatchUrl($_product, $_option->label, $_swatchInnerWidth, $_swatchInnerHeight, $_swatchType);
$_hasImage = !empty($_swatchUrl);
$_liClass = '';
$_aClass = 'swatch-link swatch-link-' . $_attribute->getAttributeId();
if ($_hasImage)
$_liClass .= $_swatchType == 'media' ? ' is-media' : '';
$_aClass .= ' has-image';
elseif (strlen($_option->label) > 3)
$_liClass .= ' wide-swatch';
?>
<li class="option-<?php echo $_optionCode; ?><?php echo $_liClass; ?>" id="option<?php echo $_option->id; ?>">
<a onclick="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this, <?php echo $_option->id; ?>);" href="javascript:void(0)" name="<?php echo $_optionCode; ?>" id="swatch<?php echo $_option->id; ?>" class="<?php echo $_aClass ?>" title="<?php echo $_option->label; ?>"
style="height: <?php echo $_swatchOuterHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchOuterWidth ?>px;">
<span class="swatch-label" style="height: <?php echo $_swatchInnerHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchInnerWidth ?>px; line-height: <?php echo $_swatchInnerHeight ?>px;">
<?php if ($_hasImage): ?>
<img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_option->label; ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />
<?php else: ?>
<?php echo $_option->label; ?>
<?php endif; ?>
</span>
<span class="x">X</span>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</dd>
<div id="sku-container"></div>
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$productMap = array();
$atLable = array();
$unitLabel = '';
foreach($col as $simpleProduct)
$productMap[$simpleProduct->getId()] = $simpleProduct->getSku();
?>
<script type="text/javascript">
function changeSku(confAttributeId, sel, pid)
var productMap = <?php echo Mage::helper('core')->jsonEncode($productMap);?>;
var selectedAttributeId = pid;
if (selectedAttributeId)
var options = spConfig.config.attributes[confAttributeId].options;
var productId = options.find(function (option) return option.id == selectedAttributeId).products[0]
$("sku-container").update("<strong>Product Id: </strong>" + productMap[productId]);
else
$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");
</script>
add a comment |
You can follow below code for swatches:
app/design/frontend/rwd/my_theme/template/configurableswatches/catalog/product/view/type/options/configurable/swatches.phtml
<?php
$_product = $this->getProduct();
$_attribute = $this->getAttributeObj();
$_jsonConfig = $this->getJsonConfig();
$_config = json_decode($_jsonConfig);
$_swatchInnerWidth = $this->getSwatchInnerWidth();
$_swatchInnerHeight = $this->getSwatchInnerHeight();
$_swatchOuterWidth = $this->getSwatchOuterWidth();
$_swatchOuterHeight = $this->getSwatchOuterHeight();
$_attr = $_attribute->getProductAttribute();
$_attrCode = $_attr->getAttributeCode();
$_id = $_attribute->getAttributeId();
$_swatchArray = $_config->attributes->$_id;
?>
<dt class="swatch-attr abc">
<label id="<?php echo $_attrCode ?>_label" class="required">
<?php echo $_attribute->getLabel() ?>:<em>*</em>
</label>
</dt>
<dd class="clearfix swatch-attr bc <?php if ($_attribute->decoratedIsLast) echo ' last'; ?>">
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select no-display swatch-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
<ul id="configurable_swatch_<?php echo $_attrCode ?>" class="configurable-swatch-list clearfix">
<?php foreach ($_swatchArray->options as $_option): ?>
<?php
$_optionCode = Mage::helper('configurableswatches')->getHyphenatedString($_option->label);
$_swatchUrl = Mage::helper('configurableswatches/productimg')->getSwatchUrl($_product, $_option->label, $_swatchInnerWidth, $_swatchInnerHeight, $_swatchType);
$_hasImage = !empty($_swatchUrl);
$_liClass = '';
$_aClass = 'swatch-link swatch-link-' . $_attribute->getAttributeId();
if ($_hasImage)
$_liClass .= $_swatchType == 'media' ? ' is-media' : '';
$_aClass .= ' has-image';
elseif (strlen($_option->label) > 3)
$_liClass .= ' wide-swatch';
?>
<li class="option-<?php echo $_optionCode; ?><?php echo $_liClass; ?>" id="option<?php echo $_option->id; ?>">
<a onclick="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this, <?php echo $_option->id; ?>);" href="javascript:void(0)" name="<?php echo $_optionCode; ?>" id="swatch<?php echo $_option->id; ?>" class="<?php echo $_aClass ?>" title="<?php echo $_option->label; ?>"
style="height: <?php echo $_swatchOuterHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchOuterWidth ?>px;">
<span class="swatch-label" style="height: <?php echo $_swatchInnerHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchInnerWidth ?>px; line-height: <?php echo $_swatchInnerHeight ?>px;">
<?php if ($_hasImage): ?>
<img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_option->label; ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />
<?php else: ?>
<?php echo $_option->label; ?>
<?php endif; ?>
</span>
<span class="x">X</span>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</dd>
<div id="sku-container"></div>
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$productMap = array();
$atLable = array();
$unitLabel = '';
foreach($col as $simpleProduct)
$productMap[$simpleProduct->getId()] = $simpleProduct->getSku();
?>
<script type="text/javascript">
function changeSku(confAttributeId, sel, pid)
var productMap = <?php echo Mage::helper('core')->jsonEncode($productMap);?>;
var selectedAttributeId = pid;
if (selectedAttributeId)
var options = spConfig.config.attributes[confAttributeId].options;
var productId = options.find(function (option) return option.id == selectedAttributeId).products[0]
$("sku-container").update("<strong>Product Id: </strong>" + productMap[productId]);
else
$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");
</script>
You can follow below code for swatches:
app/design/frontend/rwd/my_theme/template/configurableswatches/catalog/product/view/type/options/configurable/swatches.phtml
<?php
$_product = $this->getProduct();
$_attribute = $this->getAttributeObj();
$_jsonConfig = $this->getJsonConfig();
$_config = json_decode($_jsonConfig);
$_swatchInnerWidth = $this->getSwatchInnerWidth();
$_swatchInnerHeight = $this->getSwatchInnerHeight();
$_swatchOuterWidth = $this->getSwatchOuterWidth();
$_swatchOuterHeight = $this->getSwatchOuterHeight();
$_attr = $_attribute->getProductAttribute();
$_attrCode = $_attr->getAttributeCode();
$_id = $_attribute->getAttributeId();
$_swatchArray = $_config->attributes->$_id;
?>
<dt class="swatch-attr abc">
<label id="<?php echo $_attrCode ?>_label" class="required">
<?php echo $_attribute->getLabel() ?>:<em>*</em>
</label>
</dt>
<dd class="clearfix swatch-attr bc <?php if ($_attribute->decoratedIsLast) echo ' last'; ?>">
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select no-display swatch-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
<ul id="configurable_swatch_<?php echo $_attrCode ?>" class="configurable-swatch-list clearfix">
<?php foreach ($_swatchArray->options as $_option): ?>
<?php
$_optionCode = Mage::helper('configurableswatches')->getHyphenatedString($_option->label);
$_swatchUrl = Mage::helper('configurableswatches/productimg')->getSwatchUrl($_product, $_option->label, $_swatchInnerWidth, $_swatchInnerHeight, $_swatchType);
$_hasImage = !empty($_swatchUrl);
$_liClass = '';
$_aClass = 'swatch-link swatch-link-' . $_attribute->getAttributeId();
if ($_hasImage)
$_liClass .= $_swatchType == 'media' ? ' is-media' : '';
$_aClass .= ' has-image';
elseif (strlen($_option->label) > 3)
$_liClass .= ' wide-swatch';
?>
<li class="option-<?php echo $_optionCode; ?><?php echo $_liClass; ?>" id="option<?php echo $_option->id; ?>">
<a onclick="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this, <?php echo $_option->id; ?>);" href="javascript:void(0)" name="<?php echo $_optionCode; ?>" id="swatch<?php echo $_option->id; ?>" class="<?php echo $_aClass ?>" title="<?php echo $_option->label; ?>"
style="height: <?php echo $_swatchOuterHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchOuterWidth ?>px;">
<span class="swatch-label" style="height: <?php echo $_swatchInnerHeight ?>px; <?php if (!$_hasImage): ?>min-<?php endif; ?>width: <?php echo $_swatchInnerWidth ?>px; line-height: <?php echo $_swatchInnerHeight ?>px;">
<?php if ($_hasImage): ?>
<img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_option->label; ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />
<?php else: ?>
<?php echo $_option->label; ?>
<?php endif; ?>
</span>
<span class="x">X</span>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</dd>
<div id="sku-container"></div>
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$productMap = array();
$atLable = array();
$unitLabel = '';
foreach($col as $simpleProduct)
$productMap[$simpleProduct->getId()] = $simpleProduct->getSku();
?>
<script type="text/javascript">
function changeSku(confAttributeId, sel, pid)
var productMap = <?php echo Mage::helper('core')->jsonEncode($productMap);?>;
var selectedAttributeId = pid;
if (selectedAttributeId)
var options = spConfig.config.attributes[confAttributeId].options;
var productId = options.find(function (option) return option.id == selectedAttributeId).products[0]
$("sku-container").update("<strong>Product Id: </strong>" + productMap[productId]);
else
$("sku-container").update("<strong>Product Id: </strong> Select an option to display Product Id");
</script>
answered Aug 14 at 12:40
Ravi SoniRavi Soni
1,2266 silver badges19 bronze badges
1,2266 silver badges19 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f102850%2fdisplay-dynamic-sku-on-configurable-product-view-magento-using-image-swatch%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you find any solutions for the problem ? Anyone can post an update who solve this problem ?
by comment by Cantemir Alex– Amit Bera♦
Apr 1 '16 at 10:23
@AmitBera I found an extension that may work, I should be installing it within the next few days and can let you know if it works.
– user3330820
Apr 5 '16 at 14:51
@user3330820 any update on this? did you find the solution? i'm looking for the solution on the same
– Guruprasad
Jun 1 '17 at 5:08