b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Geissweb / Euvat / Plugin /
Filename/home/dev2.destoffenstraat.com/app/code/Geissweb/Euvat/Plugin/CustomerRepository.php
Size5.77 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified09-Jul-2024 08:40
Last accessed21-Aug-2025 02:07
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* ||GEISSWEB| EU VAT Enhanced
*
* NOTICE OF LICENSE
*
* This source file is subject to the GEISSWEB End User License Agreement
* that is available through the world-wide-web at this URL: https://www.geissweb.de/legal-information/eula
*
* DISCLAIMER
*
* Do not edit this file if you wish to update the extension in the future. If you wish to customize the extension
* for your needs please refer to our support for more information.
*
* @copyright Copyright (c) 2015 GEISS Weblösungen (https://www.geissweb.de)
* @license https://www.geissweb.de/legal-information/eula GEISSWEB End User License Agreement
*/
declare(strict_types=1);

namespace Geissweb\Euvat\Plugin;

use Geissweb\Euvat\Helper\Configuration;
use Geissweb\Euvat\Helper\Functions;
use Geissweb\Euvat\Logger\Logger;
use Geissweb\Euvat\Model\ValidationFactory;
use Geissweb\Euvat\Model\ValidationRepository;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Model\ResourceModel\CustomerRepository as ResourceModelCustomerRepository;
use Magento\Customer\Model\Session;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;

/**
* Assigns customer group
* Class CustomerRepository
*/
class CustomerRepository
{
/**
* @var Configuration
*/
public $configHelper;

/**
* @var Functions
*/
public $functionsHelper;

/**
* @var ValidationRepository
*/
public $validationRepository;

/**
* @var AddressRepositoryInterface
*/
public $addressRepository;

/**
* @var Logger
*/
public $logger;

/**
* @var ValidationFactory
*/
public $validationFactory;

/**
* @var Registry
*/
private $registry;
/**
* @var Session
*/
private $customerSession;

/**
* Constructor
*
* @param Configuration $configHelper
* @param Functions $functionsHelper
* @param ValidationRepository $validationRepository
* @param ValidationFactory $validationFactory
* @param AddressRepositoryInterface $addressRepository
* @param Registry $registry
* @param Session $customerSession
* @param Logger $logger
*/
public function __construct(
Configuration $configHelper,
Functions $functionsHelper,
ValidationRepository $validationRepository,
ValidationFactory $validationFactory,
AddressRepositoryInterface $addressRepository,
Registry $registry,
Session $customerSession,
Logger $logger
) {
$this->configHelper = $configHelper;
$this->functionsHelper = $functionsHelper;
$this->validationRepository = $validationRepository;
$this->validationFactory = $validationFactory;
$this->addressRepository = $addressRepository;
$this->logger = $logger;
$this->registry = $registry;
$this->customerSession = $customerSession;
}

/**
* Before we save the customer, set the correct group!
*
* @param ResourceModelCustomerRepository $subject
* @param CustomerInterface $customer
* @param string|null $passwordHash
*
* @return array<mixed>
*/
public function beforeSave(
ResourceModelCustomerRepository $subject,
CustomerInterface $customer,
string $passwordHash = null
): array {
$this->logger->customLog("[CustomerRepository::beforeSave] START");
$this->logger->customLog(
"[CustomerRepository::beforeSave] getUseGroupAssignment: "
. (int)$this->configHelper->getUseGroupAssignment()
);
if ((int)$customer->getDefaultBilling() > 0
&& $this->configHelper->getUseGroupAssignment()
&& !$this->registry->registry('euvat_groupassign_customersave')
) {
$this->logger->customLog("[CustomerRepository::beforeSave] defaultBilling: "
. $customer->getDefaultBilling());
try {
$billingAddress = $this->addressRepository->getById((int)$customer->getDefaultBilling());
$vatId = $billingAddress->getVatId();
$vatValidation = false;
if ($vatId !== null) {
$vatValidation = $this->validationRepository->getByVatId($vatId);
}
if ($vatValidation === false) {
$vatValidation = $this->validationFactory->create();
}

$isDAGC = $customer->getDisableAutoGroupChange();
$isExcludedGroup = $this->configHelper->isExcludedGroup((int)$customer->getGroupId());
$this->logger->customLog("Current customer group: " . $customer->getGroupId());
if (!$isDAGC && !$isExcludedGroup) {
$groupId = $this->functionsHelper->getCustomerGroup($billingAddress, $vatValidation);
$this->logger->customLog("Assigning group $groupId");
$this->registry->register('euvat_groupassign_customersave', true);
$customer->setGroupId($groupId);
$this->customerSession->setCustomerGroupId($groupId);
} else {
$this->logger->customLog("No assignment.");
$this->logger->customLog("auto group change is disabled: " . $isDAGC);
$this->logger->customLog("group is excluded: " . $isExcludedGroup);
}
} catch (LocalizedException $e) {
$this->logger->customLog($e->getMessage());
}
}
$this->logger->customLog("[CustomerRepository::beforeSave] END");
return [$customer, $passwordHash];
}
}