Situation
so I'm working at a tool for my product detail page where you are able to put the product you're looking at AND the product that has been bought together with this one the most into the cart with one click. The loading of the most relevant product works fine. But now I have following problem:
Problem
If I have a configurable product (the original or the most relevant product) I'm not able to display the product options properly. I can show the labels but no options in it.
What I've tried:
So this is what i get (opened bottom drop down, "Option wählen..." equals "Choose an Option...")
I've tried this so far (and some other ways to get the attributes). Atleast it now lists me the labels of the dropdowns. But there arent any options in it
if($_product->isConfigurable())
{
$_attributes = Mage::helper('core')->decorateArray($_product->getTypeInstance(true)->getConfigurableAttributes($_product));
echo count($_attributes);
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class=""<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<?php
$block1 = Mage::app()->getLayout()->createBlock('catalog/product_view');
$block1->setProduct($_product);
$configPrice = $block1->getJsonConfig();
?>
<script type="text/javascript">
var sp1Config = new Product.Config(<?php echo $block1->getJsonConfig() ?>);
</script>
<?php endif;
Results so far
Full html output:
<dl>
<dt><label class="required"><em>*</em>Farbe</label></dt>
<dd>
<div class="input-box">
<select name="super_attribute[155]" id="attribute155" class="required-entry super-attribute-select">
<option>Option wählen...</option>
</select>
</div>
</dd>
<dt><label class="required"><em>*</em>Größe</label></dt>
<dd class="">
<div class="input-box">
<select name="super_attribute[159]" id="attribute159" class="required-entry super-attribute-select">
<option>Option wählen...</option>
</select>
</div>
</dd>
</dl>
<script type="text/javascript">
var sp1Config = new Product.Config({"productId":"5151","priceFormat":{"pattern":"%s\u00a0\u20ac","precision":2,"requiredPrecision":2,"decimalSymbol":",","groupSymbol":".","groupLength":3,"integerRequired":1},"includeTax":"true","showIncludeTax":true,"showBothPrices":false,"productPrice":44.98,"productOldPrice":44.98,"skipCalculate":1,"defaultTax":19,"currentTax":19,"idSuffix":"_clone","oldPlusDisposition":0,"plusDisposition":0,"oldMinusDisposition":0,"minusDisposition":0});
</script>
The $block1->getJsonConfig()
returns:
{
"productId":"5151",
"priceFormat":{
"pattern":"%s\u00a0\u20ac",
"precision":2,
"requiredPrecision":2,
"decimalSymbol":",",
"groupSymbol":".",
"groupLength":3,
"integerRequired":1
},
"includeTax":"true",
"showIncludeTax":true,
"showBothPrices":false,
"productPrice":44.98,
"productOldPrice":44.98,
"skipCalculate":1,
"defaultTax":19,
"currentTax":19,
"idSuffix":"_clone",
"oldPlusDisposition":0,
"plusDisposition":0,
"oldMinusDisposition":0,
"minusDisposition":0
}
Following try results in just a big bunch of empty select dropdowns:
$_attributes = Mage::helper('core')->decorateArray($_c_product->getAttributes());
?>
<?php if ($_c_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class=""<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>
<?php endif;
I'm going desperate on this one..
Greetings and thanks for the help