Add attribute data to product listing

Posted: November 13, 2014 in How To?, Magento

Suppose you want to go from the default magento product listing…

qt_before

to a new one where you include the Sku, Brand and add an input field to allow additional quantities added to the cart.

qt_after

How can you do that?

  1. Edit app/design/frontend/<your theme>/<your theme folder>/template/catalog/product/list.phtml
  2. Add
    <?php echo $_product->getSku(); ?>

    to insert the sku (the attribute must be set to visible on product listing under Manage Attributes).

  3. Add
    <?php echo $_product->getAttributeText('manufacturer'); ?>

    to insert the brand (the attribute must be set to visible on product listing under Manage Attributes)

  4. Add the code to insert the input field
    <div class="qty-wrapper">
     <label for="qty">Qty:</label>
     <input type="text" name="qty" id="qty_<?php echo $_product->getId() ?>" maxlength="12" value="1" title="Qty">
     </div>
  5. On the Add to Cart button insert the following field
    onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>qty/'+(document.getElementById('qty_<?php echo $_product->getId() ?>').value)+'/')"
  6. Enjoy :)!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s