Skip to content
Advertisement

Grouped Products with Individual “Add To Cart” Button (Magento)

I am trying to set up a grouped product in Magento. What i am trying to accomplish is to add “add to cart” – button behind every grouped option that adds only this product to cart and not the hole grouped product.

I have managed to get “read more” buttom to work with

<?php echo $this->htmlEscape($_item->getProductUrl()) ?>

This will show product.

The problem is, when i add the “add to cart” buttom it shows error, because i havent selected amount yet. (Please select amount before adding to cart)

Is it possible to make default amount = 1 for grouped product and then add “add to cart” buttom to every product? Just as i did with “read more”?

UPDATE
This is how my grouped.phtml looks:

?>
<?php $this->setPreconfiguredValue(); ?>
<?php $_product = $this->getProduct(); ?>
<?php $_associatedProducts = $this->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<?php if ($_product->isAvailable() && $_hasAssociatedProducts): ?>
    <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
<?php else: ?>
    <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php echo $this->getChildHtml('product_type_data_extra') ?>
<table class="data-table grouped-items-table" id="responsive-table">
    <thead>
    <tr>
        <th><?php echo $this->__('Product Name') ?></th>
        <th><?php echo $this->__('Metode (hvordan)') ?></th>
        <th><?php echo $this->__('Sted (hvor)') ?></th>
        <th><?php echo $this->__('Tilgængelighed') ?></th>
        <th><?php echo $this->__('Fast Startdato') ?></th>
        <?php if ($this->getCanShowProductPrice($_product)): ?>
        <th><?php echo $this->__('Price') ?></th>
        <?php endif; ?>
        <?php if ($_product->isSaleable()): ?>
        <th><?php echo $this->__('Qty') ?></th>
        <?php endif; ?>
    </tr>
    </thead>
    <tbody>
    <?php if ($_hasAssociatedProducts): ?>
    <?php foreach ($_associatedProducts as $_item): ?>
    <?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
    <tr>
        <td data-title="Produkt navn"><?php echo $this->htmlEscape($_item->getName()) ?></td>
        <td data-title="Metode (hvordan)"><?php echo $_item->getAttributeText('prod_media'); ?></td>
        <td data-title="Sted (hvor)"><?php echo $_item->getAttributeText('prod_place_region'); ?></td>
        <td data-title="Tilgængelighed"><?php echo $_item->getAttributeText('prod_availability'); ?></td>
        <td data-title="Fast Startdato"><?php echo $this->htmlEscape($_item->getprod_date_startday()); ?></td>
        <td data-title="Pris">
        <?php if ($this->getCanShowProductPrice($_item)): ?>
        <?php echo $this->getPriceHtml($_item, true) ?>
        <?php echo $this->getTierPriceHtml($_item) ?>
        <?php endif; ?>
        </td>

        <?php echo $this->getTierPriceHtml($_item) ?></td>
        <?php if ($_product->isSaleable()): ?>
        <td>



        <button type="button" title="Læs mere" class="button " onclick="setLocation('<?php echo $this->htmlEscape($_item->getProductUrl()) ?>'); return false; "><span><span>Læs mere</span></span></button>
        <input type="button" title="<?php echo $this->__('Add to Cart') ?>" class="addtocart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$row['product_id'],'qty'=>1)) ?>')" />
        <?php if ($_item->isSaleable()) : ?>
        <input type="text" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
        <?php else: ?>
        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
        <?php endif; ?>

        </td>
        <?php endif; ?>
    </tr>
    <?php endforeach; ?>
    <?php else: ?>
       <tr>
       <td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
       </tr>
    <?php endif; ?>
    </tbody>
</table>
<script type="text/javascript">decorateTable('super-product-table')</script>

Advertisement

Answer

EDIT:

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="addtocart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$_product->getProductId(),'qty'=>1)) ?>')"/>
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement