Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Product Options in Listing Page? 
 
erictr1ck
Member
 
Total Posts:  56
Joined:  2009-02-12
 

Im am trying to show all the required product options on the catalog category listing page so people can actually buy the products from the listing page instead of having to go to the individual product page to select the options. I kind of have it working with the followign code in list.phtml:

<form action="<?php echo Mage::getBaseUrl(); ?>checkout/cart/add/” method="post">

<?php

$product = Mage::getModel('catalog/product');
$product->load($_product->getId());

$attVal = $product->getOptions();

$optStr = "";

// loop through the options
foreach($attVal as $optionKey => $optionVal) {

$optStr .= "<br/>";

$optStr .= $optionVal->getTitle().": ";

$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 );

?>

<input type="hidden" name="product" value="<?php echo($_product->getId()); ?>” />

<button class="form-button" type="submit"><span><?php echo $this->__('Add to Cart') ?></span></button>

</form>

This is obviously a pretty nasty hack and it also doesnt show the options for configurable products. Anyone have any suggestions or better ways to do this? Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
erictr1ck
Member
 
Total Posts:  56
Joined:  2009-02-12
 

well, after more and more searching i have yet to find a good answer for this. im sure there is an easy way to do this, but im not that great with magento so i gave it my best shot. there seems to be a LOT of people asking how to do this so i’ll post my final attempt. this seems to work with all product types, including configurable. just replace the add to cart button code in list.phtml with this:

<form action="<?php echo Mage::getBaseUrl(); ?>checkout/cart/add/” method="post" style="display:block; clear:both;">

<?php

$product = Mage::getModel('catalog/product');
$product->load($_product->getId());

//print_r($product);
//exit();

$xml = "";
$hasAtts = 0;

// configurable products
$productType = $product->getTypeId();

if($productType == "configurable") {

// configurable products
$attValConfig = $product->getTypeInstance()->getConfigurableAttributesAsArray();

if(sizeof($attValConfig)) {

$hasAtts++;

foreach($attValConfig as $attValConfigSingle) {

$xml .= $attValConfigSingle['frontend_label'].": ";

$xml .= "<select style='display:block; clear:both; margin-bottom:10px;' name='super_attribute[".$attValConfigSingle['attribute_id']."]'>";

foreach($attValConfigSingle['values'] as $attValConfigSingleVal) {
$xml .= "<option value='".$attValConfigSingleVal['value_index']."'>".$attValConfigSingleVal['label']."</option>";
}

$xml .= "</select>";

}

}


}
// end configurable products

$attVal = $product->getOptions();

if(sizeof($attVal)) {

$hasAtts++;

foreach($attVal as $optionVal) {

$xml .= $optionVal->getTitle().": ";

$xml .= "<select style='display:block; clear:both; margin-bottom:10px;' name='options[".$optionVal->getId()."]'>";

foreach($optionVal->getValues() as $valuesKey => $valuesVal) {
$xml .= "<option value='".$valuesVal->getId()."'>".$valuesVal->getTitle()."</option>";
}

$xml .= "</select>";

}

}

$xml .= "qty: <input style='display:block; clear:both; margin-bottom:20px;' id='qty' class='input-text qty' type='text' value='' maxlength='12' name='qty'/>";

echo($xml);

?>

<input type="hidden" name="product" value="<?php echo($_product->getId()); ?>” />
<button class="form-button" type="submit"><span><?php echo $this->__('Add to Cart') ?></span></button>

</form>

again, this is a quick hack to get it working and i spent no time as far as design goes so feel free to improve and post!

 
Magento Community Magento Community
Magento Community
Magento Community
 
loeffel
Guru
 
Avatar
Total Posts:  427
Joined:  2009-02-03
 

Exactly what I was looking for! I modified the add to cart link to make it work with my version:

<p><button class="button" input type="hidden" name="product" value="<?php echo($_product->getId()); ?>” onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>'"><span><?php echo $this->__('Add to Cart') ?></span></button></p>

Now hopefully I can combine this with the Color Switcher for Configurable Products to make the images change in category listing according to the option I select. That would be perfect!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ModifyMage
Sr. Member
 
Avatar
Total Posts:  84
Joined:  2008-10-15
 

Brilliant! Thank you so much for posting this solution. The key to it for me was discovering that the product object returned by:

<?php foreach ($_productCollection as $_product): ?>

is not the same as the one returned by:

$product Mage::getModel('catalog/product'); 
$product->load($_product->getId());

That knowledge will probably come in handy again.

Thanks again.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

I would like to see an example of this working, the module I wrote only requires a couple of lines of code on the list page and the view page

http://www.magentocommerce.com/boards/viewthread/21039/P45/

This for the product Link

<?php echo $Wdc_Helper->getProductHtmlUrl($_product->getId()) ?>

and this for the price and options (or configurables or grouped)

<?php echo $Wdc_Helper->drawOptionsContainer($_product->getId())?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
loeffel
Guru
 
Avatar
Total Posts:  427
Joined:  2009-02-03
 

Sorry to resurrect this thread but I recently realized that this will display the product options in listview even if that product isn’t on stock and should therefore not be included in options (just like it is the case with productview)
Did somebody find a fix for this? Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

If you load the product you can ask if it is saleable.

My current module uses a hack to get around this by looking up the product, my new version will load the product like the view.phtml page so you can use is saleable.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ch40s
Jr. Member
 
Total Posts:  7
Joined:  2010-04-26
 

How can I display special prices in the product options? I have an price impact on each option. Please help me guys!

 
Magento Community Magento Community
Magento Community
Magento Community
 
tonyshanks
Jr. Member
 
Total Posts:  4
Joined:  2010-02-22
 

Hey guys, this is an awesome workaround, but it doesn’t pass the parameters to the shopping cart. So, how can that happen? Any ideas? Thanks!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
point4design
Sr. Member
 
Total Posts:  104
Joined:  2008-07-31
 

This code seems to be working good for me. But it shows options even if they’re out of stock. How can I hide options that aren’t in stock?

 
Magento Community Magento Community
Magento Community
Magento Community
 
erictr1ck
Member
 
Total Posts:  56
Joined:  2009-02-12
 

UPDATE by gjindancer :

http://www.magentocommerce.com/boards/viewthread/223170/

 
Magento Community Magento Community
Magento Community
Magento Community
 
mymagentohelp
Jr. Member
 
Total Posts:  4
Joined:  2013-06-04
 

There is great soution for this. may be help someone else.
option in listing page in magento

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
carlosrob4
Member
 
Total Posts:  67
Joined:  2012-10-28
 

You can list all of your product option by using this Magento product options extension by fme. View Demo

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top