I am currently using magento 1.9.2.4 and i built the custom theme
I am using custom made configurable swatches color then I did some little hack it was working
I made custom radio button with the product super attr in array then i made size configurable now when i click on add to cart it asks me for the:
Please specify the product option
As both are ticked I can check by dumping and when i create product without size it works.
Here is my whole code for colour and size as i have written custom js for colour switch
<h3>select a colour</h3>
<?php if ($_product->isConfigurable()): ?>
<?php $attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product) ?>
<?php if (count($attributes)): ?>
<?php
$counter = 0;
foreach ($attributes as $att): ?>
<!-- <?php var_dump($att->debug()); ?> -->
<?php $pAtt = $att->getProductAttribute();
//get the child products
// var_dump($pAtt->getAttributeCode());
if ($pAtt->getAttributeCode() == 'color'):
$allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
$frontValues = array() ?>
<ul>
<?php
$count = 1;
foreach ($allProducts as $p): ?>
<?php if (!$p->isSaleable()) continue;
?>
<?php $out = $p->getAttributeText($pAtt->getName()); ?>
<li>
<figure class="option-click swatches1" data-id="<?php echo $p->getEntityId(); ?>"
data-url="<?php echo $actualImage[strtolower($out)] ?>">
<img src="<?php echo $swatches[strtolower($out)]; ?>" alt="">
</figure>
<input type="radio" name="super_attribute[<?php echo $att->getAttributeId(); ?>]"
value="<?php echo $p->getColor(); ?>" <?php if ($count == 1) echo "checked"; ?>> <?php echo $out; ?>
<br>
</li>
<?php $counter++;
$count;endforeach; ?>
</ul>
<?php endif; ?>
<?php if ($pAtt->getAttributeCode() == 'size'): ?>
<h3>select a size</h3>
<ul>
<?php
$count = 1;
foreach ($allProducts as $p): ?>
<?php if (!$p->isSaleable()) continue;
?>
<?php $out = $p->getAttributeText($pAtt->getName()); ?>
<li>
<figure>
<img src="<?php echo $swatches[strtolower($out)]; ?>" alt="">
</figure>
<input type="radio" name="super_attribute[<?php echo $att->getAttributeId(); ?>]"
value="<?php echo $p->getColor(); ?>" <?php if ($count == 1) echo "checked"; ?>> <?php echo $out; ?>
<br>
</li>
<?php $counter++;
$count;endforeach; ?>
</ul>
<?php endif;
endforeach; ?>
<?php endif; ?>
<?php endif; ?>
Best Answer
Well, your problem is a simple typo.
As you said, the problem is with your size attribute as without size it works well.
And you said that Magento thinks one attribute is missing so the size attribute is missing.
Let's inspect your code that handles the size attribute:
Notice that your
foreach
statement is looping on a$p
variable.However, your input is generated like this:
Instead of displaying the attribute id from
$p
you're displaying the attribute id from$att
which is the variable from the colour foreach loop before the size foreach loop.On top of that you're still using
getColor
whereas it should begetSize
To fix your code, you need to replace the size input I pasted above with: