如何在 Magento 结账流程的每个选项卡中显示购物车内容?

发布于 2024-10-31 22:47:21 字数 308 浏览 2 评论 0原文

客户希望结帐过程看起来像每个步骤(登录/注册、计费、运输等)的独立页面,因此我修改了模板,使其看起来像这样,并且一切正常。然而,现在他们希望每一步都显示购物车内容。

我想我可以使用购物车侧边栏模块,但我无法让它正确显示。

我部分怀疑这是因为我不理解 Magento 使用的一些模块/块配置。我尝试阅读它,但就像 Magento 的所有内容一样,它非常不清楚。

那么,如何将购物车内容插入到 custom/template/checkout/onepage/billing.phtml 的模板中?我确信有多种方法可以做到这一点,而我只是在寻找最简单的方法。

The client wants the checkout process to look like discrete pages for each step (login/register, billing, shipping, etc.), so I've modified the template to look like that and everything works fine. However, now they want to display the cart contents with every step.

I presume I would be able to use the shopping cart sidebar module, but I can't get it to display properly.

Partially I suspect this is because I don't understand some of the module/block configuration that Magento uses. I've tried reading up on it, but like everything Magento, it's remarkably unclear.

So, how would I insert the cart contents into the template at custom/template/checkout/onepage/billing.phtml? I'm sure there are multiple ways to do this, and I'm just looking for the simplest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒几许 2024-11-07 22:47:21

这应该适用于任何地方,而不仅仅是在计费阶段:

$quote = Mage::helper('checkout')->getQuote();
foreach ($quote->getItemsCollection() as $item) {
    // output details of an item.
    echo $item->getName();
}

每个 $item 都是一个 Mage_Sales_Model_Quote_Item

附注
听起来您正在尝试重新创建在引入单页结帐之前存在的旧的多发货结帐。可以使用系统>中的第一个设置重新激活此功能。配置>结帐>结帐选项

This should work anywhere, not just in the billing phase:

$quote = Mage::helper('checkout')->getQuote();
foreach ($quote->getItemsCollection() as $item) {
    // output details of an item.
    echo $item->getName();
}

Each $item is a Mage_Sales_Model_Quote_Item.

PS.
It sounds like you're trying to recreate the old multishipping checkout that existed before onepage checkout was introduced. This can be reactivated with the first setting in System > Configuration > Checkout > Checkout Options.

悲念泪 2024-11-07 22:47:21

Clockworkgeek 让我从这个答案开始,但我还需要显示产品数量、价格以及购物车总价格。 Magento 文档充其量是密集的,所以在搜索之后,这里是在 Magento 中显示购物车内容并使用一些用于格式化的表格 HTML 的答案:

<?php $quote = Mage::helper('checkout')->getQuote(); //gets the cart contents ?>
<table>
<thead>    
<th>Product</th>
<th>Quantity</th>
<th>Price/ea.</th>
<th>Total</th>
</thead>

<?php foreach ($quote->getItemsCollection() as $item) { ?>
<tr><td><?php echo $item->getName(); ?></td>
<td><?php echo $item->getQty(); ?></td> 
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice(), 2); ?></td>
<td><?php $floatQty = floatval($item->getQty());
$total = $floatQty * $item->getPrice();
echo $this->helper('checkout')->formatPrice($total, 2); //multiply the quantity by the price and convert/format ?></td>
</tr>       
<?php  } ?>

<tfoot>
<td></td>
<td></td>
<td></td>
<td><?php echo $this->helper('checkout')->formatPrice($quote->getGrandTotal()); ?></td>
</tfoot>
</table>

这可能是一些非常丑陋的代码,包括查找每个 $item 总数的粗略方法,但它有效。我确信有更好的方法来获取 $item 总计(calcRowTotal 似乎从来没有工作过),但它可以完成工作。

感谢 Clockworkgeek 让我走上了正确的道路。

clockworkgeek got me started here with that answer, but I needed to also display product quantity, price and then the total cart price as well. The Magento documentation is dense at best, so after searching around, here is the answer to display cart contents in Magento with some table HTML for formatting:

<?php $quote = Mage::helper('checkout')->getQuote(); //gets the cart contents ?>
<table>
<thead>    
<th>Product</th>
<th>Quantity</th>
<th>Price/ea.</th>
<th>Total</th>
</thead>

<?php foreach ($quote->getItemsCollection() as $item) { ?>
<tr><td><?php echo $item->getName(); ?></td>
<td><?php echo $item->getQty(); ?></td> 
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice(), 2); ?></td>
<td><?php $floatQty = floatval($item->getQty());
$total = $floatQty * $item->getPrice();
echo $this->helper('checkout')->formatPrice($total, 2); //multiply the quantity by the price and convert/format ?></td>
</tr>       
<?php  } ?>

<tfoot>
<td></td>
<td></td>
<td></td>
<td><?php echo $this->helper('checkout')->formatPrice($quote->getGrandTotal()); ?></td>
</tfoot>
</table>

That may be some very ugly code, including the rough way to find the total for each $item, but it works. I'm sure there's a better way to get the $item total (calcRowTotal never seemed to work), but it gets the job done.

And thanks to clockworkgeek for sending me down the right path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文