Step  1
app\design\frontend\base\default\template\catalog\product\list.phtml
<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>
<?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 echo $this->getToolbarHtml() ?>
    <!-- junpeng add start -->
   
<form action="<?php echo
$this->helper('multiadd/cart')->getAddToCartUrl() ?>"
method="post" id="productAddToCartForm">
    <!-- junpeng end end -->

<?php // List mode ?>
    <?php if($this->getMode()!='grid'): ?>
    <?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 // Product Image ?>
           
<a href="http://zjp2230987.blog.163.com/blog/<?php echo $_product->getProductUrl() ?>"
title="<?php echo
$this->stripTags($this->getImageLabel($_product, 'small_image'),
null, true) ?>" class="product-image"><img src="http://zjp2230987.blog.163.com/blog/<?php echo
$this->helper('catalog/image')->init($_product,
'small_image')->resize(135); ?>" width="135" height="135"
alt="<?php echo
$this->stripTags($this->getImageLabel($_product, 'small_image'),
null, true) ?>" /></a>
            <?php // Product description ?>
            <div class="product-shop">
                <div class="f-fix">
                    <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                   
<h2 class="product-name"><a href="http://zjp2230987.blog.163.com/blog/<?php echo
$_product->getProductUrl() ?>" title="<?php echo
$_productNameStripped; ?>"><?php echo
$_helper->productAttribute($_product, $_product->getName() ,
'name'); ?></a></h2>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product) ?>
                    <?php endif; ?>
                    <!-- junpeng add start -->
                    <?php if(Mage::getSingleton('customer/session')->isLoggedIn()):?>
                        <?php echo $this->getPriceHtml($_product, true) ?>
                        <?php if($_product->isSaleable()): ?>
                             <?php if(!$_product->isGrouped()): ?>
                                <input type="hidden" name="products[]" value="<?php echo $_product->getId()?>" />
                               
<label for="qty<?php echo $_product->getId()?>"><?php
echo $this->__('Qty') ?>:</label>
                               
<input type="text" name="qty<?php echo
$_product->getId()?>" id="qty<?php echo
$_product->getId()?>" maxlength="12" value="<?php echo
($this->getMinimalQty($_product)?$this->getMinimalQty($_product):0)
?>" class="input-text qty" />
                             <?php endif; ?>
                        <?php else: ?>
                           
<p class="availability out-of-stock"><span><?php echo
$this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                   <?php else: ?>
                       
<p><a href="http://zjp2230987.blog.163.com/blog/<?php echo
Mage::helper('customer')->getLoginUrl(); ?>"><?php echo
$this->__('Login to view pricing') ?></a></p>
                    <?php endif; ?>
                    <!-- junpeng add end -->
                    <div class="desc std">
                       
<?php echo $_helper->productAttribute($_product,
$_product->getShortDescription(), 'short_description') ?>
                       
<a href="http://zjp2230987.blog.163.com/blog/<?php echo $_product->getProductUrl() ?>"
title="<?php echo $_productNameStripped ?>"
class="link-learn"><?php echo $this->__('Learn More')
?></a>
                    </div>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                           
<li><a href="http://zjp2230987.blog.163.com/blog/<?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="http://zjp2230987.blog.163.com/blog/<?php echo $_compareUrl ?>" class="link-compare"><?php
echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
            </div>
        </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

<?php else: ?>

<?php // Grid Mode ?>

<?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif ?>
           
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="http://zjp2230987.blog.163.com/blog/<?php echo
$_product->getProductUrl() ?>" title="<?php echo
$this->stripTags($this->getImageLabel($_product, 'small_image'),
null, true) ?>" class="product-image"><img src="http://zjp2230987.blog.163.com/blog/<?php echo
$this->helper('catalog/image')->init($_product,
'small_image')->resize(135); ?>" width="135" height="135"
alt="<?php echo
$this->stripTags($this->getImageLabel($_product, 'small_image'),
null, true) ?>" /></a>
                <h2
class="product-name"><a href="http://zjp2230987.blog.163.com/blog/<?php echo
$_product->getProductUrl() ?>" title="<?php echo
$this->stripTags($_product->getName(), null, true)
?>"><?php echo $_helper->productAttribute($_product,
$_product->getName(), 'name') ?></a></h2>
                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>
                <!-- junpeng add start -->
                <?php if(Mage::getSingleton('customer/session')->isLoggedIn()):?>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                <?php endif; ?>
                <!-- junpeng add end -->
                <div class="actions">
                    <!-- junpeng add start -->
                    <?php if(Mage::getSingleton('customer/session')->isLoggedIn()):?>
                        <?php if($_product->isSaleable()): ?>
                             <?php if(!$_product->isGrouped()): ?>
                                <input type="hidden" name="products[]" value="<?php echo $_product->getId()?>" />
                           
    <label for="qty<?php echo
$_product->getId()?>"><?php echo $this->__('Qty')
?>:</label>
                                <input
type="text" name="qty<?php echo $_product->getId()?>"
id="qty<?php echo $_product->getId()?>" maxlength="12"
value="<?php echo
($this->getMinimalQty($_product)?$this->getMinimalQty($_product):0)
?>" class="input-text qty" />
                             <?php endif; ?>
                        <?php else: ?>
                           
<p class="availability out-of-stock"><span><?php echo
$this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                    <?php else: ?>
                       
<p><a href="http://zjp2230987.blog.163.com/blog/<?php echo
Mage::helper('customer')->getLoginUrl(); ?>"><?php echo
$this->__('Login to view pricing') ?></a></p>
                    <?php endif; ?>
                    <!-- junpeng add end -->
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                           
<li><a href="http://zjp2230987.blog.163.com/blog/<?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="http://zjp2230987.blog.163.com/blog/<?php echo $_compareUrl ?>" class="link-compare"><?php
echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
       
<script
type="text/javascript">decorateGeneric($$('ul.products-grid'),
['odd','even','first','last'])</script>
    <?php endif; ?>

<div class="toolbar-bottom">
        <!-- junpeng add start -->
        <?php if(Mage::getSingleton('customer/session')->isLoggedIn()):?>
            <div style="text-align:center;">
               
<button class="button btn-cart" type="button"
onclick="productAddToCartForm.submit()"><span><span><?php
echo $this->__('Add to Cart')
?></span></span></button>
            </div>
            <br>
        </form>
        <?php endif; ?>
        <!-- junpeng end start -->
        <?php echo $this->getToolbarHtml() ?>
    </div>
</div>
<?php endif; ?>

Step  2

app\code\local\Perpetual\MultiAdd\controllers\Checkout\CartController.php
<?php
require_once('Mage/Checkout/controllers/CartController.php');
class Perpetual_MultiAdd_Checkout_CartController extends Mage_Checkout_CartController
{
    public function addmultipleAction()
    {
        $productIds = $this->getRequest()->getParam('products');
        if (!is_array($productIds)) {
            $this->_goBack();
            return;
        }

foreach( $productIds as $productId) {
            try {
                $qty = $this->getRequest()->getParam('qty' . $productId, 0);
                if ($qty <= 0) continue; // nothing to add
                $cart = $this->_getCart();
                $product = Mage::getModel('catalog/product')
                    ->setStoreId(Mage::app()->getStore()->getId())
                    ->load($productId)
                    ->setConfiguredAttributes($this->getRequest()->getParam('super_attribute'))
                    ->setGroupedProducts($this->getRequest()->getParam('super_group', array()));
                $eventArgs = array(
                    'product' => $product,
                    'qty' => $qty,
                    'request' => $this->getRequest(),
                    'response' => $this->getResponse(),
                );
                Mage::dispatchEvent('checkout_cart_before_add', $eventArgs);
               
                $cart = Mage::getModel('checkout/cart')->init();
               
                $cart->addProduct($product, $qty);
                Mage::dispatchEvent('checkout_cart_after_add', $eventArgs);
                $cart->save();
                Mage::dispatchEvent('checkout_cart_add_product', array('product'=>$product));
                $message = $this->__('%s was successfully added to your shopping cart.', $product->getName());   
                Mage::getSingleton('checkout/session')->addSuccess($message);
            }
            catch (Mage_Core_Exception $e) {
                if (Mage::getSingleton('checkout/session')->getUseNotice(true)) {
                    Mage::getSingleton('checkout/session')->addNotice($product->getName() . ': ' . $e->getMessage());
                }
                else {
                    Mage::getSingleton('checkout/session')->addError($product->getName() . ': ' . $e->getMessage());
                }
            }
            catch (Exception $e) {
                Mage::getSingleton('checkout/session')->addException($e, $this->__('Can not add item to shopping cart'));
            }
        }
        $this->_goBack();
    }
}
?>

Step  3
app\code\local\Perpetual\MultiAdd\etc\config.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Perpetual_MultiAdd>
            <version>0.1.0</version>
        </Perpetual_MultiAdd>
    </modules>
    <global>
        <rewrite>
            <perpetual_multiadd_checkout_cart>
                <from><![CDATA[#^/checkout/cart/addmultiple/.*$#]]></from>
                <to>/multiadd/checkout_cart/addmultiple/</to>
            </perpetual_multiadd_checkout_cart>
        </rewrite>
        <helpers>
            <multiadd>
                <class>Perpetual_MultiAdd_Helper</class>
            </multiadd>
        </helpers>
    </global>
    <frontend>
        <routers>
            <perpetual_multiadd>
                <use>standard</use>
                <args>
                    <module>Perpetual_MultiAdd</module>
                    <frontName>multiadd</frontName>
                </args>
            </perpetual_multiadd>
        </routers>
    </frontend>
</config>

Step  4
app\code\local\Perpetual\MultiAdd\Helper\Cart.php
<?php
class Perpetual_MultiAdd_Helper_Cart extends Mage_Core_Helper_Url
{
    /**
     * Return url to add multiple items to the cart
     * @return  url
     */
    public function getAddToCartUrl()
    {
        if ($currentCategory = Mage::registry('current_category')) {
            $continueShoppingUrl = $currentCategory->getUrl();
        } else {
            $continueShoppingUrl = $this->_getUrl('*/*/*', array('_current'=>true));
        }

$params = array(
           
Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED =>
Mage::helper('core')->urlEncode($continueShoppingUrl)
        );

if ($this->_getRequest()->getModuleName() == 'checkout'
            && $this->_getRequest()->getControllerName() == 'cart') {
            $params['in_cart'] = 1;
        }
        return $this->_getUrl('checkout/cart/addmultiple', $params);
    }
}
?>

Step  5
app\etc\modules\Perpetual_MultiAdd.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Perpetual_MultiAdd>
            <active>true</active>
            <codePool>local</codePool>
            <version>0.1.0</version>
        </Perpetual_MultiAdd>
    </modules>
</config>

最新文章

  1. Codeforces Round #379 (Div. 2) F. Anton and School
  2. C++中文件按行读取和逐词读取 backup
  3. java操作小技巧,遇到过的会一直更新,方便查找
  4. Task加入取消功能
  5. 使用django的ImageField和from制作上传图片页面
  6. window7 下 安装 apache24(httpd-2.4.10-x86-r2)加 php5.6(php-5.6.4-Win32-VC11-x86)加yaf(php_yaf-2.3.3-5.6-ts-vc11-x86)整合
  7. Unieap3.5-禁用Form表单中的全部标签
  8. 用Python组合Celery Redis RabbitMQ进行分布式数据抓取
  9. bzoj3083 3306
  10. WIndows系统下mysql-noinstall安装配置
  11. IDA pro 的Python环境变量设置
  12. Unknown database &#39;DB_NAME&#39;
  13. 关于O(logN)的正确理解
  14. 三十天学不会TCP,UDP/IP网络编程-UDP,从简单的开始
  15. ReactNative Android之原生UI组件动态addView不显示问题解决
  16. 教你一步步发布一个开源库到 JCenter
  17. 巡风源码阅读与分析---AddPlugin()方法
  18. MT【315】勾股数
  19. CSS高度塌陷问题解决方案
  20. 制作STM32开发板要买的电子元器件

热门文章

  1. 串口调试,提示the given port name does not start with COM/com异常解决办法,,发现是打印机在搞怪
  2. 关于python中的编码:unicode, utf-8, gb2312
  3. 一个漂亮灵活的PHP图片验证码
  4. CAP Confusion: Problems with ‘partition tolerance’
  5. Blackhat EU 2013 黑客大会(Full Schedule for Black Hat USA 2013)
  6. undefined reference to typeinfo - C++ error message
  7. USB鼠标按键驱动
  8. ICTCLA中科院分词工具用法(java)
  9. HDU 4087 三维上的平移缩放旋转矩阵变化
  10. Rhel6-lanmp架构配置文档