1

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; ?>
4
+100

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:

<?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; ?>

Notice that your foreach statement is looping on a $p variable.

However, your input is generated like this:

<input type="radio" name="super_attribute[<?php echo $att->getAttributeId(); ?>]" value="<?php echo $p->getColor(); ?>" <?php if($count == 1) echo "checked"; ?>>

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 be getSize

To fix your code, you need to replace the size input I pasted above with:

<input type="radio" name="super_attribute[<?php echo $p->getAttributeId(); ?>]" value="<?php echo $p->getSize(); ?>" <?php if($count == 1) echo "checked"; ?>>
1
  • 1
    Thank you sir for drawing the attension thank you +1 for the help – ujwal dhakal May 27 '16 at 9:27
2

Thanks every one i sorted on my own thanks to @Raphael at Digital Pianism for drawing attention and the simple solution was

 <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>

i copied same code for two loops one was for colour and one was for the size and i didnt change the value="<?php echo $p->getColor(); ?> to the value="<?php echo $p->getSize(); ?>

 <input type="radio" name="super_attribute[<?php echo $att->getAttributeId(); ?>]" value="<?php echo $p->getSize(); ?>" <?php if($count == 1) echo "checked"; ?>> <?php echo $out; ?><br>
6
  • 1
    If an answer solved your problem, you should mark it as accepted instead of duplicating it as your own answer. As a bonus, you get 2 points for accepting someone else's answer. – Marius May 27 '16 at 11:39
  • but i found it myself ? – ujwal dhakal May 27 '16 at 11:42
  • Haha yeah I ended up finding out that something else was wrong I edited my answer earlier today but didn't see you found it too ^^ – Raphael at Digital Pianism May 27 '16 at 11:45
  • @ujwaldhakal. OK. It looked to me like you copied it from the other answer. Sorry. Carry on. – Marius May 27 '16 at 11:46
  • BTW, your solution does not work for me. Using $att->getAttributeId() instead of what I used in my answer $p->getAttributeId() breaks the add to cart. – Raphael at Digital Pianism May 27 '16 at 11:48
1

A common cause of this, is that a redirect from http to https can cause the request to lose the headers containing the custom options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.