Using this post you can set your product custom option on product listing page. If you want to show available product custom option on you product listing page or category page to your customer, you can easily do using this post.
You can set your custom options like color, size etc. to your product listing page or category page. You can also add your product to cart with selected option from list page. For that you just need to change in your list.phtml file of your current THEME. There is no need to change in your php file.
Our module is also available on magento connect for free. You can download here.
Check our latest module Product Custom Option (Pro)
Add following code in your list.phtml after <?php $i=0; $h=0; foreach ($_productCollection as $_product): ?> line:
<?php
//$productSku = $_product->getSku();
//$product = Mage::getModel('catalog/product');
//$productId = $product->getIdBySku( $productSku );
$product = Mage::getModel("catalog/product")->load($_product->getId());
$attVal = $product->getOptions();
$optStr = "";
?>
Replace <div class="actions"> with following code in same page.
<div class="actions">
<?php if($_product->isSaleable()):?>
<form action="<?php echo $this->helper('checkout/cart')->getAddUrl($_product)?>" method="post" id= "product_addtocart_form" <?php if($_product->getOptions()):?> enctype="multipart/form-data"<?php endif;?>>
<div style='float: left; width: 100px;'>
<?php foreach($attVal as $optionKey => $optionVal)
{
$optStr.= "<select style='display:block; clear:both;' name='options[".$optionVal->getId()."]'>"; foreach($optionVal->getValues() as $valuesKey => $valuesVal)
{
$optStr.= "<option value='".$valuesVal->getId()."'>".$valuesVal->getTitle()."</option>";
}
$optStr.= "</select>";
}
echo($optStr );?>
<!--Change click action in button -->
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="this.form.submit();"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
</div>
<?php else:?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock')?></span></p>
<?php endif;?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) :?>
<li>
<a href="<?php echo $this->helper('wishlist')->getAddUrl($_product)?>" class="link-wishlist">
<?php echo $this->__('Add to Wishlist')?>
</a>
</li>
<?php endif;?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)):?>
<li>
<span class="separator">|</span>
<a href="<?php echo $_compareUrl?>" class="link-compare"><?php echo $this->__('Add to Compare')?>
</a>
</li>
<?php endif;?>
</ul>
</form>
</div>
I would love to hear from you about this post!