仍在搜索中?找到了这个:
http://www.magentocommerce.com/boards/viewthread/9797
似乎可以在当前版本中使用,尽管我尚未对其进行测试。如果你解决了它,至少未来的搜索者会知道在哪里可以找到它!
/***编辑****/
好吧,为了“不被认为是一个糟糕的答案”,这就是你应该如何实施解决方案。这些代码都不是我的工作,感谢 Uni-Man、Nexus Rex 和 Magento 论坛的人 :)
代码有据可查。它在名称空间“Company”中创建了一个完整的 Magento 扩展,名称为“Module”。
首先,在 app/code/local/Company/Module/helper/Data.php 中实现 helper:
<?php
class Company_Module_Helper_Multiple 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);
}
}
接下来,您将需要进行一些模板更改。将文件 app/design/base/default/templates/catalog/list.phtml 复制到 app/design/default/default/templates/catalog/list.phtml。这样可以确保,一旦不再需要扩展,您/您的客户无需编码即可返回正常的列表视图。修改新的list.phtml文件如下:
后
<?php echo $this->getToolbarHtml(); ?>
添加
<form action="<?php echo $this->helper( 'Module/multiple' )->getAddToCartUrl() ?>" method="post" id="product_addtocart_form">
<button class="form-button" onclick="productAddToCartForm.submit()"><span><?php echo $this->__('Add Items to Cart') ?></span></button>
(这将打开表单;以下所有项目都会添加数量输入框,因此您可以使用一个按钮将所有项目放入购物车。这里也放了。)
向下滚动,您会发现通常会生成“添加到购物车”按钮的区域:
<?php if($_product->isSaleable()): ?>
将 if 块的内容替换为:
<fieldset class="add-to-cart-box">
<input type="hidden" name="products[]" value="<?php echo $_product->getId() ?>" />
<legend><?php echo $this->__('Add Items to Cart') ?></legend>
<span class="qty-box"><label for="qty<?php echo $_product->getId() ?>"><?php echo $this->__('Qty') ?>:</label>
<input name="qty<?php echo $_product->getId() ?>" type="text" class="input-text qty" id="qty<?php echo $_product->getId() ?>" maxlength="12" value="" /></span>
</fieldset>
这是数量的输入字段。要关闭 -tag,请在之后插入
<?php echo $this->getToolbarHtml() ?>
在底部:
<button class="form-button" onclick="productAddToCartForm.submit()"><span><?php echo $this->__('Add Items to Cart') ?></span></button>
</form>
你在这里做的是: - 生成第二个“添加到购物车” - 按钮,与顶部的按钮相同 - 关闭表单
当一个项目被添加到购物车时,通常 Magento 会调用 Checkout_CartController。我们必须修改这个,以便将所有物品添加到购物车中,而不仅仅是一件,而是以应有的数量添加到购物车中。
因此,添加文件 app/code/local/Company/Module/controllers/Checkout/CartController.php 并填写:
> require_once 'Mage/Checkout/controllers/CartController.php';
>
> class Company_Module_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,
> 'additional_ids' => array(),
> 'request' => $this->getRequest(),
> 'response' => $this->getResponse(),
> );
>
> Mage::dispatchEvent('checkout_cart_before_add', $eventArgs);
>
> $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();
> } }
我们用我们自己的覆盖现有的 Mage Core 类,导致为此目的使用我们的控制器。
您还必须像往常一样在 app/code/local/Company/Module/etc/config.xml 中添加模块的 config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Company_Module>
<version>0.1.0</version>
</Company_Module>
</modules>
<global>
<rewrite>
<company_module_checkout_cart>
<from><![CDATA[#^/checkout/cart/addmultiple/.*$#]]></from>
<to>/module/checkout_cart/addmultiple/</to>
</company_module_checkout_cart>
</rewrite>
<helpers>
<Module>
<class>Company_Module_Helper</class>
</Module>
</helpers>
</global>
<frontend>
<routers>
<company_module>
<use>standard</use>
<args>
<module>Company_Module</module>
<frontName>module</frontName>
</args>
</company_module>
</routers>
</frontend>
</config>
这是做什么的: - 用调用自己的多添加控制器替换对购物车控制器的调用 - 注册助手 - 将路由器应用于前端
请告诉我是否需要更多相关文件。