문제

I remove price from product view page using below line of code

  <referenceBlock name="product.info.price" remove="true" />

This is working perfectly.but i need to show price in only simple product on product view page and did not show in configurable,bundle,grouped,virtual product.

can someone help to achieve this solution?

도움이 되었습니까?

해결책

Override the below file

catalog_product_view_type_simple.xml

<referenceBlock name="product.info.price" remove="false" />

Use the above code to show the price only in the simple product on product view page

다른 팁

Using Preference:-

app/code/Vendor/Module/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Pricing\Render\FinalPriceBox" type="Vendor\Module\Pricing\Render\FinalPriceBox" />
</config>

app/code/Vendor/Module/Pricing/Render/FinalPriceBox.php

<?php

namespace Vendor\Module\Pricing\Render;


use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\View\Element\Template\Context;

class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
    protected $registry;

    protected $helperData;

    public function __construct(Context $context, SaleableInterface $saleableItem, PriceInterface $price, RendererPool $rendererPool, array $data = [], SalableResolverInterface $salableResolver = null, MinimalPriceCalculatorInterface $minimalPriceCalculator = null,\Magento\Framework\Registry $registry,\Shineretrofits\CallForPrice\Helper\Data $helperData)
    {
        $this->registry = $registry;
        $this->helperData = $helperData;
        parent::__construct($context, $saleableItem, $price, $rendererPool, $data, $salableResolver, $minimalPriceCalculator);
    }

    protected function wrapResult($html)
    {
        $current_product = $this->registry->registry('current_product');

        if($current_product->getTypeId() == 'simple')
        {
                $result = parent::wrapResult($html);
        }else{
            $result = '';
        }

        return $result;
    }

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top