0

I'm trying to create a custom list.phtml template for one particular category that will function as a way for a wholesaler to quickly add lots of products tot he cart at once.

I have the attached code that is listing out all of the simple products (because these are hidden on other category pages by default). I have added a qty input for each product but no matter what number i enter, it only ever adds a qty of 1 so I would like to get this working.

I also want to have a button that will enable the user to add multiple products at once by entering qty for each item they would like to order and then click the 'add all products' button. I wondered if someone might be able to help with this?

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');

    $setting = Mage::helper('em0113settings');
?>

<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">

    <?php // List mode ?>

    <?php $_iterator = 0; ?>

    <ol class="products-list" id="products-list">
    <?php foreach ($_productCollection as $_product): ?>

        <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">

            <?php if ($_product->isConfigurable()): ?>

                <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                <!--product name-->
                <?php if ($setting->getProductsList_ShowProductName()):?>
                    <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h3>
                <?php endif ?>

            <div class="product-shop">
                <div class="f-fix">

                <?php $simpleProducts = Mage::getModel('catalog/product_type_configurable')
                ->getUsedProducts(null,$_product); ?>

                    <ul>
                <?php foreach ($simpleProducts as $simpleProduct): ?>
<li>
                    <?php $_simpleProductNameStripped = $this->stripTags($simpleProduct->getName(), null, true); ?>
                    <!--product name-->
                    <?php if ($setting->getProductsList_ShowProductName()):?>
                        <p><a href="<?php echo $simpleProduct->getProductUrl() ?>" title="<?php echo $_simpleProductNameStripped; ?>"><?php echo $_helper->productAttribute($simpleProduct, $simpleProduct->getName() , 'name'); ?></a></p>
                    <?php endif ?>

                    <!--product sku-->
                    <?php if ($setting->getProductsList_ShowSku()):?>
                        <p class="sku"><?php echo $simpleProduct->getSKU()?></p>
                    <?php endif ?>

                    <?php if ($setting->getProductsList_ShowSaleables()):?>
                        <?php if($simpleProduct->isSaleable()): ?>
                            <p class="availability in-stock"><span><?php echo $this->__('In stock') ?></span></p>
                        <?php else: ?>
                            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                    <?php endif; ?>

                    <!--product price-->
                    <?php if ($setting->getProductsList_ShowPrice()): ?>
                        <?php echo $this->getPriceHtml($simpleProduct, true) ?>
                    <?php endif; ?>

                    <!--show button add to cart-->
                    <?php if ($setting->getProductsList_ShowAddtocart()): ?>
                        <?php if($simpleProduct->isSaleable()): ?>

        <input type="number" name="qty" id="qty" maxlength="12" value="" class="input-text qty"/>
                            <button type="button" title="<?php echo $this->__('Add to Basket') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($simpleProduct) ?>')"><span><span><?php echo $this->__('Add to Basket') ?></span></span></button>

                        <?php else: ?>
                            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                    <?php endif; ?>
</li>
                <?php endforeach ?>
                    </ul>

                </div>
            </div>

            <?php else: ?>

                <?php // Product description ?>
                <div class="product-shop">
                    <div class="f-fix">
                        <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                        <!--product name-->
                        <?php if ($setting->getProductsList_ShowProductName()):?>
                            <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h3>
                        <?php endif ?>

                        <!--product sku-->
                        <?php if ($setting->getProductsList_ShowSku()):?>
                            <p class="sku"><?php echo $_product->getSKU()?></p>
                        <?php endif ?>

                        <?php if ($setting->getProductsList_ShowSaleables()):?>
                            <?php if($_product->isSaleable()): ?>
                                <p class="availability in-stock"><span><?php echo $this->__('In stock') ?></span></p>
                            <?php else: ?>
                                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                            <?php endif; ?>
                        <?php endif; ?>

                        <!--product price-->
                        <?php if ($setting->getProductsList_ShowPrice()): ?>
                            <?php echo $this->getPriceHtml($_product, true) ?>
                        <?php endif; ?>

                        <!--show button add to cart-->
                        <?php if ($setting->getProductsList_ShowAddtocart()): ?>
                            <?php if($_product->isSaleable()): ?>
                                <form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
                                    <input type="number" name="qty" id="qty" maxlength="12" value="" class="input-text qty"/>
                                <button type="button" title="<?php echo $this->__('Add to Basket') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Basket') ?></span></span></button>
                                </form>
                            <?php else: ?>
                                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                            <?php endif; ?>
                        <?php endif; ?>

                    </div>
                </div>


            <?php endif ?>

        </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

    <div class="toolbar-bottom">
        <?php echo $this->getToolbarHtml() ?>
    </div>
</div>
<?php endif; ?>
0

Did you manage to get it working?? I added the code below and it's supposed to work.

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
     <?php if(!$_product->isGrouped()): ?>
     <label for="qty"><?php echo $this->__('Qty') ?>:</label>
    <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
    <?php endif; ?>
    <button type="button" class="button btn-cart" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>

In fact it worked to me with a magento 1.9.3.10 version but now I'm working with a magento 1.9.4 version and it always add just one product to the cart.

thanks!

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.