0

I have a multistory website as Retail-Website and Wholesale-Website

Configuration with fresh Magneto2.2 at Store >> Configuration >> Customer Configuration >> Show Tax/VAT Number

Retail-Website enter image description here

Wholesale-Website enter image description here

When I check the front-end of customer registration the configuration dint apply I did cache clean, I tried different combination of the setup dint work.

In Table customer_eav_attribute_website I can see the configuration is correctly added.

I tried this in version 2.2 and in 2.5 fresh project.

Scenarios 1

Admin Input

    webA >> required

    webB >> optional

Store output

    webA >> required

    webB >> required

After flush cache Store output

    webA >> optional

    webB >> optional

Scenarios 2

Admin Input

    webA >> required

    webB >> required

Store output

    webA >> required

    webB >> required

After flush cache Store output

    webA >> required

    webB >> required

Scenarios 3

Admin Input

    webA >> optional

    webB >> required

Store output

    webA >> optional

    webB >> optional

After flush cache Store output

    webA >> optional

    webB >> optional
1
  • Any Help facing this issue for a long time, With 2.4 I have the same issue.
    – fernandus
    Commented Jan 29, 2021 at 7:08

1 Answer 1

0

This is bug. Try following way to fix:

app/code/SR/MagentoCommunity/etc/frontend/di.xml

<?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\Checkout\Block\Checkout\AttributeMerger">
        <plugin name="sr_vat_id_fix"
                type="SR\MagentoCommunity\Plugin\Checkout\Block\Checkout\AttributeMerger" sortOrder="1"/>
    </type>
</config>

app/code/SR/MagentoCommunity/Plugin/Checkout/Block/Checkout/AttributeMerger.php

<?php
namespace SR\MagentoCommunity\Plugin\Checkout\Block\Checkout;

use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\StoreManagerInterface;

class AttributeMerger
{
    /**
     * @var ScopeConfigInterface
     */
    private $scopeConfig;

    /**
     * @var StoreManagerInterface
     */
    private $storeManager;

    /**
     * AttributeMerger constructor.
     *
     * @param ScopeConfigInterface $scopeConfig
     * @param StoreManagerInterface $storeManager
     */
    public function __construct(
        ScopeConfigInterface $scopeConfig,
        StoreManagerInterface $storeManager
    ) {
        $this->scopeConfig = $scopeConfig;
        $this->storeManager = $storeManager;
    }

    public function afterMerge(
        \Magento\Checkout\Block\Checkout\AttributeMerger $subject,
        $fields
    ) {
        foreach ($fields as $field => $fieldConfig) {
            if ($field == 'vat_id') {
                $store = $this->storeManager->getStore();
                $taxvatShow = $this->scopeConfig->getValue(
                    'customer/address/taxvat_show',
                    ScopeInterface::SCOPE_STORE,
                    $store->getId()
                );
                if ($taxvatShow == 'req') {
                    $fields[$field]['validation'] = array_merge(['required-entry' => true], $fields[$field]['validation']);
                } else {
                    $fields[$field]['validation'] = array_merge(['required-entry' => false], $fields[$field]['validation']);
                }
            }
        }

        return $fields;
    }
}
7
  • I tried this but its not working I am using magento2.2
    – fernandus
    Commented May 20, 2019 at 12:15
  • This is tested code, don't know how you tried.
    – Sohel Rana
    Commented May 20, 2019 at 13:11
  • I created a new module with the same folder path app/code/SR/MagentoCommunity, Then I did the configuration Website1 tax required, Website2 optional, Default required. Output: But in front end for both Website1 Website2 I got required. Expected Output: Website1 required, Website2 optional.
    – fernandus
    Commented May 20, 2019 at 13:32
  • Can you check updated answer?
    – Sohel Rana
    Commented May 20, 2019 at 13:34
  • Its not working, I have check the configurations and added print to Magento\Customer\Model\Data\AttributeMetadata Object its returns required for both Website1 Website2
    – fernandus
    Commented May 20, 2019 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.