Skip to content

Commit

Permalink
VIPPS-460: Remove mismatch between magento and vipps street line numb…
Browse files Browse the repository at this point in the history
…ers.

#59
  • Loading branch information
olegmalichenkoatvaimo committed Sep 17, 2024
1 parent fa1fad6 commit fd0226c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 34 deletions.
32 changes: 20 additions & 12 deletions Controller/Login/ApplyAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Psr\Log\LoggerInterface;
use Vipps\Login\Api\VippsCustomerAddressRepositoryInterface;
use Vipps\Login\Api\VippsCustomerRepositoryInterface;
use Vipps\Login\Model\ConfigInterface;
use Vipps\Login\Model\VippsAccountManagement;

/**
Expand Down Expand Up @@ -59,6 +60,7 @@ class ApplyAddress extends AccountBase
* @var RedirectFactory
*/
private $resultRedirectFactory;
private ConfigInterface $config;

/**
* ApplyAddress constructor.
Expand All @@ -73,21 +75,24 @@ class ApplyAddress extends AccountBase
* @param VippsCustomerRepositoryInterface $vippsCustomerRepository
*/
public function __construct(
RedirectFactory $resultRedirectFactory,
RequestInterface $request,
LoggerInterface $logger,
SessionManagerInterface $customerSession,
VippsAccountManagement $vippsAccountManagement,
ManagerInterface $messageManager,
RedirectFactory $resultRedirectFactory,
RequestInterface $request,
LoggerInterface $logger,
SessionManagerInterface $customerSession,
VippsAccountManagement $vippsAccountManagement,
ManagerInterface $messageManager,
VippsCustomerAddressRepositoryInterface $vippsCustomerAddressRepository,
VippsCustomerRepositoryInterface $vippsCustomerRepository
VippsCustomerRepositoryInterface $vippsCustomerRepository,
ConfigInterface $config
) {
parent::__construct($customerSession, $request, $logger);
$this->resultRedirectFactory = $resultRedirectFactory;
$this->vippsAccountManagement = $vippsAccountManagement;
$this->messageManager = $messageManager;
$this->vippsCustomerAddressRepository = $vippsCustomerAddressRepository;
$this->vippsCustomerRepository = $vippsCustomerRepository;
$this->request = $request;
$this->config = $config;
}

/**
Expand All @@ -110,12 +115,15 @@ public function execute()
$this->messageManager->addErrorMessage(__('We can\'t delete the address right now.'));
}
$this->customerSession->setAddressFormData([
'telephone' => $vippsCustomer->getTelephone(),
'postcode' => $vippsAddress->getPostalCode(),
'city' => $vippsAddress->getRegion(),
'telephone' => $vippsCustomer->getTelephone(),
'postcode' => $vippsAddress->getPostalCode(),
'city' => $vippsAddress->getRegion(),
'country_id' => $vippsAddress->getCountry(),
'street' => explode(PHP_EOL, $vippsAddress->getStreetAddress()),
'region' => $vippsAddress->getRegion()
'street' => explode(PHP_EOL,
$vippsAddress->getStreetAddress(),
$this->config->getCustomerStreetLinesNumber()
),
'region' => $vippsAddress->getRegion()
]);
$params = ['vipps_address_id' => $addressId];
} catch (NoSuchEntityException $e) {
Expand Down
5 changes: 5 additions & 0 deletions Model/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ public function getValue($path, $storeId = null)

return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
}

public function getCustomerStreetLinesNumber(): int
{
return (int)$this->scopeConfig->getValue(self::XML_CUSTOMER_STREET_NUMBER_LINES);
}
}
4 changes: 4 additions & 0 deletions Model/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ interface ConfigInterface

const VIPPS_LOGIN_VERSION = 'vipps/login/version';

const XML_CUSTOMER_STREET_NUMBER_LINES = 'customer/address/street_lines';

/**
* @param null $storeId
*
Expand Down Expand Up @@ -76,4 +78,6 @@ public function isEnabled($storeId = null);
public function getVersion(): string;

public function getTitle(): string;

public function getCustomerStreetLinesNumber(): int;
}
47 changes: 27 additions & 20 deletions Model/VippsAddressManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class VippsAddressManagement implements VippsAddressManagementInterface
* @var FormFactory
*/
private $formFactory;
private ConfigInterface $config;

/**
* VippsAddressManagement constructor.
Expand All @@ -89,13 +90,14 @@ class VippsAddressManagement implements VippsAddressManagementInterface
* @param Random $mathRand
*/
public function __construct(
VippsCustomerAddressInterfaceFactory $vippsCustomerAddressFactory,
VippsCustomerAddressInterfaceFactory $vippsCustomerAddressFactory,
VippsCustomerAddressRepositoryInterface $vippsCustomerAddressRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
AddressRepositoryInterface $addressRepository,
AddressInterfaceFactory $addressDataFactory,
FormFactory $formFactory,
Random $mathRand
SearchCriteriaBuilder $searchCriteriaBuilder,
AddressRepositoryInterface $addressRepository,
AddressInterfaceFactory $addressDataFactory,
FormFactory $formFactory,
Random $mathRand,
ConfigInterface $config
) {
$this->vippsCustomerAddressFactory = $vippsCustomerAddressFactory;
$this->vippsCustomerAddressRepository = $vippsCustomerAddressRepository;
Expand All @@ -104,6 +106,7 @@ public function __construct(
$this->addressRepository = $addressRepository;
$this->addressDataFactory = $addressDataFactory;
$this->formFactory = $formFactory;
$this->config = $config;
}

/**
Expand All @@ -114,9 +117,9 @@ public function __construct(
* @throws LocalizedException
*/
public function apply(
UserInfoInterface $userInfo,
UserInfoInterface $userInfo,
VippsCustomerInterface $vippsCustomer,
CustomerInterface $customer
CustomerInterface $customer
) {
$vippsAddresses = $this->fetchAddresses($userInfo, $vippsCustomer);

Expand All @@ -139,7 +142,7 @@ public function apply(
* @return array|VippsCustomerAddressInterface[]
*/
public function fetchAddresses(
UserInfoInterface $userInfo,
UserInfoInterface $userInfo,
VippsCustomerInterface $vippsCustomer
) {
$vippsAddressResult = $this->vippsCustomerAddressRepository->getByVippsCustomer($vippsCustomer);
Expand Down Expand Up @@ -194,11 +197,11 @@ public function fetchAddresses(
* @throws LocalizedException
*/
public function convert(
CustomerInterface $customer,
VippsCustomerInterface $vippsCustomer,
CustomerInterface $customer,
VippsCustomerInterface $vippsCustomer,
VippsCustomerAddressInterface $vippsAddress,
bool $hasDefault,
bool $forceConvert
bool $hasDefault,
bool $forceConvert
) {
if (!$this->isConvertAllowed($vippsCustomer, $vippsAddress, $forceConvert)) {
return false;
Expand All @@ -218,7 +221,11 @@ public function convert(
$magentoAddress->setLastname($customer->getLastname());
$magentoAddress->setPostcode($vippsAddress->getPostalCode());

$street = explode(PHP_EOL, $vippsAddress->getStreetAddress());
$street = explode(
PHP_EOL,
$vippsAddress->getStreetAddress(),
$this->config->getCustomerStreetLinesNumber()
);

$magentoAddress->setStreet($street);
$magentoAddress->setTelephone($vippsCustomer->getTelephone());
Expand Down Expand Up @@ -252,8 +259,8 @@ public function convert(
*/
public function assign(
VippsCustomerAddressInterface $vippsAddress,
VippsCustomerInterface $vippsCustomer,
array $magentoAddresses
VippsCustomerInterface $vippsCustomer,
array $magentoAddresses
) {
if ($vippsAddress->getCustomerAddressId()) {
return true;
Expand Down Expand Up @@ -293,8 +300,8 @@ public function link(VippsCustomerAddressInterface $vippsAddress, AddressInterfa
*/
public function areTheSame(
VippsCustomerAddressInterface $vippsAddress,
VippsCustomerInterface $vippsCustomer,
AddressInterface $magentoAddress
VippsCustomerInterface $vippsCustomer,
AddressInterface $magentoAddress
) {
$street = $magentoAddress->getStreet();
if (is_array($street)) {
Expand Down Expand Up @@ -413,9 +420,9 @@ private function hasDefault(array $magentoAddresses)
* @return bool
*/
private function isConvertAllowed(
VippsCustomerInterface $vippsCustomer,
VippsCustomerInterface $vippsCustomer,
VippsCustomerAddressInterface $vippsAddress,
bool $forceConvert
bool $forceConvert
) {
if ($forceConvert) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"psr/log": "^1.0||^2.0||^3.0"
},
"type": "magento2-module",
"version": "2.5.2",
"version": "2.5.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vipps_Login" setup_version="2.4.13">
<module name="Vipps_Login" setup_version="2.5.3">
<sequence>
<module name="Magento_Customer"/>
<module name="Magento_Checkout"/>
Expand Down

0 comments on commit fd0226c

Please sign in to comment.