首页>Magento>source

我正在尝试在结帐/购物车页面上创建自定义功能块,以便我可以显示免费送货的倒计时.不过,我一直将无效块类型视为错误.

checkout_cart_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="checkout.cart.totals.container">
        <block type="checkout/cart" class="Miles\FreeShippingCountOnPage\Block\Checkout\Cart\Countdown" name="checkout.cart.miles.countdown" after="-" template="Vendor_Module::checkout/cart/countdown.phtml"/>
    </referenceContainer>
</body>
</page>

Vendor\Module\view\frontend\templates\checkout\cart\countdown.phtml

<span><?php
$_item = $block->getItem();
$product = $_item->getProduct();
$additional_data = $block->getAdditionalData();
?>
<div>
<span><?php echo $additional_data?></span>
</div>
?></span>

Vendor\Module\etc\module.xml

<?php
namespace Vendor\Module\Block\Checkout\Cart;
class Countdown extends \Magento\Framework\View\Element\Template
{
public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    array $data = []
) {
    parent::__construct($context, $data);
}

}

UPDATE

I have found an html file that looks to actually build the area I need to add the information on located in the path below that I am attempting to use/override

\vendor\magento\module-tax\view\frontend\web\template\checkout\summary\subtotal.html

<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->

<!-- ko if: isBothPricesDisplayed() -->
<tr class="totals sub excl">
    <th class="mark" scope="row">
        <span data-bind="text: title"></span>
        <span data-bind="text: excludingTaxMessage"></span>
    </th>
    <td class="amount">
        <span class="price" data-bind="text: getValue(), attr: {'data-th': excludingTaxMessage}"></span>
    </td>
</tr>
<tr class="totals sub incl">
    <th class="mark" scope="row">
        <span data-bind="text: title"></span>
        <span data-bind="text: includingTaxMessage"></span>
    </th>
    <td class="amount">
        <span class="price" data-bind="text: getValueInclTax(), attr: {'data-th': includingTaxMessage}"></span>
    </td>
</tr>
<!-- /ko -->
<!-- ko if: !isBothPricesDisplayed() && isIncludingTaxDisplayed() -->
<tr class="totals sub">
    <th data-bind="text: title" class="mark" scope="row"></th>
    <td class="amount">
        <span class="price" data-bind="text: getValueInclTax(), attr: {'data-th': title}"></span>
    </td>
</tr>
<!-- /ko -->
<!-- ko if: !isBothPricesDisplayed() && !isIncludingTaxDisplayed() -->
<tr class="totals sub">
    <th data-bind="text: title" class="mark" scope="row"></th>
    <td class="amount">
        <span class="price" data-bind="text: getValue(), attr: {'data-th': title}"></span><br/>
        <!-- ko if: getValue() >= 50 -->
        <div data-bind="text: 'This order qualifies for free shipping!'"></div>
        <!-- /ko -->
        <!-- ko ifnot: getValue() >= 50 -->
        <div data-bind="text: getValue(), html: 'You have $' + (50.00 - getValue()) + ' left until free shipping!'"></div>
        <!-- /ko -->

    </td>
</tr>
<!-- /ko -->

任何帮助都将非常感谢并提前感谢!

最新回答
  • 2019-12-5
    1 #

    您需要添加您的块的类。请尝试下面的代码

    <?xml version="1.0"?>
        <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> 
            <body> 
                <referenceContainer name="checkout.cart.totals.container"> 
                    <block class="Miles\FreeShippingCountOnPage\Block\Checkout\Cart\Countdown" name="checkout.cart.miles.countdown" after="-" template="Vendor_Module::checkout/cart/countdown.phtml"/> 
                </referenceContainer> 
            </body>
        </page>
    

  • 2019-12-5
    2 #

    我其实只是想通了.我必须将if ifnot语句中的行更新为:

    <span class="price" data-bind="text: getValue(), attr: {'data-th': title}"></span><br/>
    <!-- ko if: totals().subtotal >= 50 -->
    <div data-bind="text: 'This order qualifies for free shipping!'"></div>
    <!-- /ko -->
    <!-- ko ifnot: totals().subtotal >= 50 -->
    <div data-bind="html: 'You have $' + (50.00 - totals().subtotal) + ' left until free shipping!'"></div>
    <!-- /ko -->
    

    我只需要正确的参数/函数和变量。

  • 当子产品可见性设置为"单独不可见"时,请勿重定向到404
  • ce 1.9.0.1:创建机器人点文本