带有“添加到购物车”按钮的分组产品(Magento)

时间:2013-03-06 21:30:58

标签: php magento

我正在尝试在Magento中设置分组产品。 我想要完成的是添加“添加到购物车” - 每个分组选项后面的按钮,仅将此产品添加到购物车而不是孔分组产品。

我已经设法获得“阅读更多”但是可以使用

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

这将显示产品。

问题是,当我添加“添加到购物车”但它显示错误,因为我还没有选择数量。 (请在添加到购物车前选择金额)

是否可以为分组产品设置默认金额= 1,然后为每个产品添加“添加到购物车”按钮?正如我对“阅读更多”所做的那样?

更新
这就是我的groups.phtml看起来的样子:     

?>
<?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>

2 个答案:

答案 0 :(得分:0)

修改

<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)) ?>')"/>

答案 1 :(得分:0)

数组(&#39;产品&#39; =&gt; $ _ item-&gt; getId(),&#39; qty&#39; =&gt; 1))?&gt;&#39;)&#34 ;