Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 4e64212f authored by Nicolas's avatar Nicolas
Browse files

feat: Create Helper

parent 55087bfe
No related branches found
No related tags found
No related merge requests found
<?php <?php
namespace NicolasBejean\Customer\Helper; namespace NicolasBejean\Customer\Helper;
use Magento\Customer\Api\Data\AddressInterface; use Magento\Customer\Model\Address;
use Magento\Customer\Api\Data\CustomerInterface; use Magento\Customer\Model\Customer;
use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context; use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Api\WebsiteRepositoryInterface;
use Magento\Directory\Api\CountryInformationAcquirerInterface;
/** /**
* Class SendGeoLocation * Class SendGeoLocation
...@@ -17,29 +20,83 @@ use Magento\Framework\App\Helper\Context; ...@@ -17,29 +20,83 @@ use Magento\Framework\App\Helper\Context;
*/ */
class SendGeoLocation extends AbstractHelper class SendGeoLocation extends AbstractHelper
{ {
/**
* @var WebsiteRepositoryInterface
*/
private WebsiteRepositoryInterface $websiteRepositoryInterface;
/**
* @var CountryInformationAcquirerInterface
*/
private CountryInformationAcquirerInterface $countryInformationAcquirerInterface;
/** /**
* SendGeoLocation constructor. * SendGeoLocation constructor.
* @param Context $context * @param Context $context
* @param WebsiteRepositoryInterface $websiteRepositoryInterface
* @param CountryInformationAcquirerInterface $countryInformationAcquirerInterface
*/ */
public function __construct( public function __construct(
Context $context Context $context,
WebsiteRepositoryInterface $websiteRepositoryInterface,
CountryInformationAcquirerInterface $countryInformationAcquirerInterface
) { ) {
$this->websiteRepositoryInterface = $websiteRepositoryInterface;
$this->countryInformationAcquirerInterface = $countryInformationAcquirerInterface;
parent::__construct($context); parent::__construct($context);
} }
public function sendDataToApi(CustomerInterface $customer, AddressInterface $address) public function sendDataToApi(Customer $customer, Address $address)
{ {
$createdAt = $customer->getCreatedAt();
$updatedAt = $customer->getUpdatedAt();
$websiteId = $customer->getWebsiteId();
$storeId = $customer->getStoreId();
$customerId = $customer->getId(); $customerId = $customer->getId();
$groupId = $customer->getGroupId(); $websiteId = $customer->getWebsiteId();
$country = $address->getCountryId(); $countryId = $address->getCountryId();
$city = $address->getCity(); $city = $address->getCity();
$postCode = $address->getPostcode(); $postCode = $address->getPostcode();
$websiteName = $this->getWebsiteNameFromId($websiteId);
$countryName = $this->getCountryNameFromId($countryId);
$data = array(
'customerId' => $customerId,
'websiteName' => $websiteName,
'countryName' => $countryName,
'postCode' => $postCode,
'city' => $city
);
/* Instructions */
}
/**
* @param int $websiteId
* @return string
*/
private function getWebsiteNameFromId (int $websiteId): string
{
try {
$website = $this->websiteRepositoryInterface->getById($websiteId);
} catch (NoSuchEntityException $e) {
return '';
}
return $website->getName();
}
/**
* @param string $countryId
* @return string
*/
private function getCountryNameFromId (string $countryId): string
{
try {
$country = $this->countryInformationAcquirerInterface->getCountryInfo($countryId);
} catch (NoSuchEntityException $e) {
return '';
}
return $country->getFullNameLocale();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment