1

I have multi-store website, And I am getting an error while add customer address from admin side. It is working fine with store id 1 and website id 1. It is not working for store id 8 and website id 2. enter image description here

I'm getting this error

Exception #0 (Magento\Framework\Exception\NoSuchEntityException): The website with id 8 that was requested wasn't found. Verify the website and try again.

2 Answers 2

1

I think you have a value in the core_config_data table where scope is website and scope_id is 8. Maybe a website you had and got deleted or you somehow inserted a wrong value in the table. Look for these occurrences and delete them.

1
  • I have checked there is no entry with website and scope_id 8
    – MP Raj
    Commented Jun 27, 2023 at 8:32
1

After debuging I found a solution, I have changed from SCOPE_WEBSITE to SCOPE_STORE the in this file line no. 131

File path :vendor/magento/module-customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php

Piece of code

public function getAllOptions($withEmpty = true, $defaultValues = false)
    {
        if (!$this->options) {
            $websiteIds = [];

            if (!$this->shareConfig->isGlobalScope()) {
                $allowedCountries = [];

                foreach ($this->storeManager->getWebsites() as $website) {
                    $countries = $this->allowedCountriesReader
                        ->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $website->getId());
                    $allowedCountries[] = $countries;

                    foreach ($countries as $countryCode) {
                        $websiteIds[$countryCode][] = $website->getId();
                    }
                }

                $allowedCountries = array_unique(array_merge([], ...$allowedCountries));
            } else {
                // Address can be added only for the allowed country list.
                $storeId = null;
                $customerId = $this->request->getParam('parent_id') ?? null;
                if ($customerId) {
                    $customer = $this->customerRepository->getById($customerId);
                    $storeId = $customer->getStoreId();
                }

                $allowedCountries = $this->allowedCountriesReader->getAllowedCountries(
                    ScopeInterface::SCOPE_WEBSITE,
                    $storeId
                );
            }

            $this->options = $this->createCountriesCollection()
                ->addFieldToFilter('country_id', ['in' => $allowedCountries])
                ->toOptionArray();

            foreach ($this->options as &$option) {
                if (isset($websiteIds[$option['value']])) {
                    $option['website_ids'] = $websiteIds[$option['value']];
                }
            }
        }

        return $this->options;
    }

Replace from:-

$allowedCountries = $this->allowedCountriesReader->getAllowedCountries(
                    ScopeInterface::SCOPE_WEBSITE,
                    $storeId
                );

Replace to:-

$allowedCountries = $this->allowedCountriesReader->getAllowedCountries(
    ScopeInterface::SCOPE_STORE,
    $storeId
);

Seems to core issue

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.