Magento2 目前正在尝试在可配置产品的清单页面magento 2上显示常规和特殊价格

Magento2 目前正在尝试在可配置产品的清单页面magento 2上显示常规和特殊价格,magento2,Magento2,目前正在尝试在可配置产品的清单页面magento 2上显示常规价格和特殊价格,其工作正常,但如果我们应用目录价格规则,则不会按照我的条件显示可配置的简单产品是否有特殊价格,是否有任何方法可以确定产品是否符合目录价格规则 public function checkIfSpecialPriceExist() { $specialChildProductPrice = []; $specialChildProduct = $this->getUsedProducts();

目前正在尝试在可配置产品的清单页面magento 2上显示常规价格和特殊价格,其工作正常,但如果我们应用目录价格规则,则不会按照我的条件显示可配置的简单产品是否有特殊价格,是否有任何方法可以确定产品是否符合目录价格规则

public function checkIfSpecialPriceExist()
{
    $specialChildProductPrice = [];
    $specialChildProduct = $this->getUsedProducts();
    foreach ($specialChildProduct as $child) {
        $specialPrice = $child->getSpecialPrice();
        if ($specialPrice !=0 and !is_null($specialPrice)) {
            $specialPrice = number_format($specialPrice, 2, '.', '');
            $specialChildProductPrice[] = array(
                'special_price' => $specialPrice,
                'price' => $child->getPrice(),
                'specialfromdate' => $child->getSpecialFromDate(),
                'specialtodate' => $child->getSpecialToDate()
            );
        }
    }

    if(count($specialChildProductPrice) > 0){
        return true;
    }
    else{
        return false;
    }
}

    <?php
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */

    // @codingStandardsIgnoreFile

    ?>

    <?php
    /** @var \Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox$block */

    /** @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
    $priceModel = $block->getPriceType('regular_price');

    /** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
    $finalPriceModel = $block->getPriceType('final_price');
    $idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
    $schema = ($block->getZone() == 'item_view') ? true : false;
    ?>
    <span class="normal-price">
        <?php
        $arguments = [
          // 'display_label' => __('As low as'),
           // 'display_label' => __(''),
            'price_id' => $block->getPriceId('product-price-' . $idSuffix),
            'price_type' => 'finalPrice',
            'include_container' => true,
            'schema' => $schema,
        ];
        /* @noEscape */ echo $block->renderAmount($finalPriceModel->getAmount(), $arguments);
        ?>
    </span>

    <?php if (!$block->isProductList() && $block->hasSpecialPrice()): ?>
        <span class="old-price sly-old-price no-display">
            <?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
                'display_label'     => __('Regular Price'),
                'price_id'          => $block->getPriceId('old-price-' . $idSuffix),
                'price_type'        => 'oldPrice',
                'include_container' => true,
                'skip_adjustments'  => true
            ]); ?>
        </span>
    <?php endif; ?>

    <?php if ($block->isProductList() && $finalPriceModel->getAmount() < $priceModel->getMaxRegularAmount() && !$schema && $priceModel->checkIfSpecialPriceExist()): ?>
        <span class="old-price sly-old-price no-display abcd1234">
            <?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getMaxRegularAmount(), [
                'display_label'     => __('Regular Price'),
                'price_id'          => $block->getPriceId('old-price-' . $idSuffix),
                'price_type'        => 'oldPrice',
                'include_container' => true,
                'skip_adjustments'  => true
            ]); ?>
        </span>
    <?php endif; ?>


    <?php if ($block->showMinimalPrice()): ?>
        <?php if ($block->getUseLinkForAsLowAs()):?>
            <a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
                <?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
            </a>
        <?php else:?>
            <span class="minimal-price-link">
                <?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
            </span>
        <?php endif?>
    <?php endif; ?>
公共函数checkIfSpecialPriceExist()
{
$specialChildProductPrice=[];
$specialChildProduct=$this->getUsedProducts();
foreach($specialChildProduct作为$child){
$specialPrice=$child->getSpecialPrice();
如果($specialPrice!=0且!为空($specialPrice)){
$specialPrice=数字\ U格式($specialPrice,2’,”);
$specialChildProductPrice[]=数组(
“特价”=>$specialPrice,
'price'=>$child->getPrice(),
'specialfromdate'=>$child->getSpecialFromDate(),
'specialtodate'=>$child->getSpecialToDate()
);
}
}
如果(计数($specialChildProductPrice)>0){
返回true;
}
否则{
返回false;
}
}