-1

私はマジェントにかなり慣れていないので、簡単な質問があります...

私の cart.phtml には、次のコードがあります。

<div class="cart">
    <div class="page-title">
        <h1><?php echo $this->__('Shopping Cart') ?></h1>        
    </div>
    <?php if(!$this->hasError()): ?>
    <ul class="checkout-types">
    <?php foreach ($this->getMethods('top_methods') as $method): ?>
        <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
        <li><?php echo $methodHtml; ?></li>
        <?php endif; ?>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <?php echo $this->getChildHtml('form_before') ?>
    <form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
        <fieldset>
            <table id="shopping-cart-table" class="data-table cart-table">


            <?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
                <thead>
                    <tr>
                        <th class="a-center" rowspan="<?php echo $mergedCells; ?>">&nbsp;</th>
                        <th class="a-center" rowspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Product Name') ?></span></th>
                        <th class="a-center" rowspan="<?php echo $mergedCells; ?>"></th>                        
                        <th class="a-center" colspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Unit Price') ?></span></th>
                        <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Qty') ?></th>
                        <th class="a-center" colspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Subtotal') ?></th>
                        <?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
                        <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><span class="nobr"><?php echo $this->__('Move to Wishlist') ?></span></th>
                        <?php endif ?>
                        <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Remove product') ?></th>
                    </tr>
                    <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
                    <tr>
                        <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                        <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                        <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
                        <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
                    </tr>
                    <?php endif; ?>
                </thead>
                <tbody>
                <?php foreach($this->getItems() as $_item): ?>
                    <tr>
                        <th class="a-center" rowspan="<?php echo $mergedCells; ?>">&nbsp;</th>
                        <th class="a-center" rowspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $_item->getName()?></span></th>
                        <th class="a-center" rowspan="<?php echo $mergedCells; ?>"></th>                        
                        <th class="a-center" colspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $_item->getPrice() ?></span></th>
                        <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $_item->getQty() ?></th>
                        <th class="a-center" colspan="<?php echo $mergedCells; ?>"><?php echo $_item->getPrice() * $_item->getQty() ?></th>
                        <?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
                        <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><span class="nobr"><?php echo $this->__('Move to Wishlist') ?></span></th>
                        <?php endif ?>
                        <th rowspan="<?php echo $mergedCells; ?>" class="a-center"> <button type="button" class="button btn-cart" onclick="setLocation('<?php echo $this->getDeleteUrl(); ?>')"><span><span><?php echo $this->__('Remove from Cart') ?></span></span></button>
                </th>
                    </tr>

                <?php endforeach ?>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="50" class="a-right">
                            <?php if($this->getContinueShoppingUrl()): ?>
                                <button type="button" title="<?php echo $this->__('Continue Shopping') ?>" class="button btn-continue left" onclick="setLocation('<?php echo $this->getContinueShoppingUrl() ?>')"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
                            <?php endif; ?>
                            <button type="submit" name="update_cart_action" value="update_qty" title="<?php echo $this->__('Update Shopping Cart'); ?>" class="button btn-update"><span><span><?php echo $this->__('Update Shopping Cart'); ?></span></span></button>
                            <button type="submit" name="update_cart_action" value="empty_cart" title="<?php echo $this->__('Clear Shopping Cart'); ?>" class="button btn-empty" id="empty_cart_button"><span><span><?php echo $this->__('Clear Shopping Cart'); ?></span></span></button>
                            <!--[if lt IE 8]>
                            <input type="hidden" id="update_cart_action_container" />
                            <script type="text/javascript">
                            //<![CDATA[
                                Event.observe(window, 'load', function()
                                {
                                    // Internet Explorer (lt 8) does not support value attribute in button elements
                                    $emptyCartButton = $('empty_cart_button');
                                    $cartActionContainer = $('update_cart_action_container');
                                    if ($emptyCartButton && $cartActionContainer) {
                                        Event.observe($emptyCartButton, 'click', function()
                                        {
                                            $emptyCartButton.setAttribute('name', 'update_cart_action_temp');
                                            $cartActionContainer.setAttribute('name', 'update_cart_action');
                                            $cartActionContainer.setValue('empty_cart');
                                        });
                                    }

                                });
                            //]]>
                            </script>
                            <![endif]-->
                        </td>
                    </tr>
                </tfoot>

            </table>
            <script type="text/javascript">decorateTable('shopping-cart-table')</script>
        </fieldset>
    </form>
    <div class="cart-collaterals">
        <div class="col2-set">
            <div class="col-1">
                <?php echo $this->getChildHtml('crosssell') ?>
            </div>
            <div class="col-2">
                <?php /* Extensions placeholder */ ?>
                <?php echo $this->getChildHtml('checkout.cart.extra') ?>
                <?php echo $this->getChildHtml('coupon') ?>
                <?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>
            </div>
        </div>
        <div class="totals">
            <?php echo $this->getChildHtml('totals'); ?>
            <?php if(!$this->hasError()): ?>
            <ul class="checkout-types">
            <?php foreach ($this->getMethods('methods') as $method): ?>
                <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
                <li><?php echo $methodHtml; ?></li>
                <?php endif; ?>
            <?php endforeach; ?>
            </ul>
            <?php endif; ?>
        </div>
    </div>
</div>

カートからアイテムを削除するにはどうすればよいですか? 定義済みのメソッドがあり、それを機能させるために実装する方法を教えてもらえますか?:

 <th rowspan="<?php echo $mergedCells; ?>" class="a-center"> <button type="button" class="button btn-cart" onclick="setLocation('<?php echo $this->getDeleteUrl(); ?>')"><span><span><?php echo $this->__('Remove from Cart') ?></span></span></button></th>
4

1 に答える 1

1

このテンプレートでアイテムを表示するべきではありません。あなたが使用している必要があります

<?php foreach($this->getItems() as $_item): ?>
    <?php echo $this->getItemHtml($_item) ?>
<?php endforeach ?>

/app/design/frontend/default/contempospace/template/checkout/cart/item/default.phtml を参照してください (属性を持つ製品を追加し、それらをカートに表示したい場合は、将来これを変更する必要があるかもしれません)

しかし、このようにしたい場合は、変更してください

 <?php echo $this->getDeleteUrl(); ?>

 <?php echo $this->getUrl('checkout/cart/delete', array('id' => $_item->getId())) 

例えば。

<th rowspan="<?php echo $mergedCells; ?>" class="a-center"> <button type="button" class="button btn-cart" onclick="setLocation('<?php echo $this->getUrl('checkout/cart/delete', array('id' => 'xxxx')) ?>)"><span><span><?php echo $this->__('Remove from Cart') ?></span></span></button></th>

より良い説明については、Magento でカートから製品を削除するための URL を取得する方法を参照してください。

于 2012-11-09T17:34:49.627 に答える