【问题标题】:Magento: Add multiple add to cart buttons and qty fields to product view pageMagento:将多个添加到购物车按钮和数量字段添加到产品视图页面
【发布时间】:2013-02-25 11:42:28
【问题描述】:

我目前正在使用以下方法在产品视图页面上对名称相似的产品进行分组:



    $model =Mage::getModel('catalog/product');
    $collection = $model->getCollection();;

    $currentProduct = Mage::registry('current_product');
    $collection->addAttributeToFilter('name', $currentProduct->getName());

    echo "<table>";
    foreach($collection as $product){
    echo '<tr>';
    echo '<td>'.$product->getSKU().'</td>';
    echo '<td>'.$product->getName().'</td>';
    echo '<td><a href="'.$product->getProductUrl().'">VIEW THIS PRODUCT</td>';
    echo '</tr>';

    }
    echo "</table>";

但是,我需要将“查看此产品”链接替换为添加到购物车按钮和数量输入字段。这甚至可以通过仅编辑 product/view.phtml 来实现吗?

感谢您的帮助

【问题讨论】:

    标签: php magento e-commerce


    【解决方案1】:

    假设您只添加简单的产品而没有任何选项

    .....
    foreach($collection as $product){
      <form action="/path/to/app/checkout/cart/add" method="get">
       <input type="hidden" name="product" value="<?php echo $product->getId() ?>" />
    
        echo $product->getSKU();
        echo $product->getName();
    
       <input type="text" name="qty" value="1" />
       <input type="submit" name="submit" value="Add to cart" />
      </form>
    }
    

    Adding a Product to the Cart via Querystring

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 1970-01-01
      • 2023-03-10
      相关资源
      最近更新 更多