문제

In this question https://magento.stackexchange.com/a/324446/92235, there is an excellent solution related to hiding the price from a specific user group. But this one does not hide the price from the grid, how can this be implemented? enter image description here

enter image description here

도움이 되었습니까?

해결책

di.xml updated from previous question:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav">
        <plugin name="product_form_modifier" type="Mbs\HidePrice\Plugin\ProductAttributeModifier" />
    </type>
    <preference for="Magento\Catalog\Ui\Component\Listing\Columns" type="Mbs\HidePrice\Ui\Component\Listing\ProductGridColumns" />
</config>

preference as plugin is not possible on columns

<?php

namespace Mbs\HidePrice\Ui\Component\Listing;

class ProductGridColumns extends \Magento\Catalog\Ui\Component\Listing\Columns
{
    public function __construct(
        \Magento\Framework\View\Element\UiComponent\ContextInterface $context,
        \Magento\Catalog\Ui\Component\ColumnFactory $columnFactory,
        \Magento\Catalog\Ui\Component\Listing\Attribute\RepositoryInterface $attributeRepository,
        \Mbs\HidePrice\Model\AuthorisationReader $authorization,
        array $components = [],
        array $data = []
    ) {
        if (!$authorization->canShowPriceInBackend()) {
            unset($components['price']);
        }
        parent::__construct($context, $columnFactory, $attributeRepository, $components, $data);
    }
}

I have done a small refactoring and now the authorisation is made in a separate model (see below):

class AuthorisationReader
{
    /**
     * @var \Magento\Framework\AuthorizationInterface
     */
    private $authorization;

    public function __construct(
        \Magento\Framework\AuthorizationInterface $authorization
    ) {
        $this->authorization = $authorization;
    }

    /**
     * @return bool
     */
    public function canShowPriceInBackend(): bool
    {
        return $this->authorization->isAllowed('Mbs_AdminScreen::Mbs_HidePrice::AccessPrice');
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top