Skip to content

Commit

Permalink
Merge pull request #40 from Datatrics/release/1.6.7
Browse files Browse the repository at this point in the history
Release/1.6.7
  • Loading branch information
Marvin-Magmodules authored May 25, 2023
2 parents b5e2e1a + cb87556 commit bdb1acf
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Api/Profile/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function save(ProfileData $entity) : ProfileData;
* @param bool $forceUpdate
* @return mixed
*/
public function prepareProfileData($customer, bool $forceUpdate = false);
public function prepareProfileData($customer, bool $forceUpdate = false, $address = null);

/**
* @param Order $order
Expand Down
55 changes: 34 additions & 21 deletions Model/Profile/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function delete(ProfileData $entity): bool
/**
* @inheritDoc
*/
public function prepareProfileData($customer, bool $forceUpdate = false)
public function prepareProfileData($customer, bool $forceUpdate = false, $address = null)
{
$customer = $this->customer->load($customer->getId());
$storeId = (int)$customer->getStoreId();
Expand Down Expand Up @@ -218,7 +218,7 @@ public function prepareProfileData($customer, bool $forceUpdate = false)
$profile->setData(
array_merge(
$profile->getData(),
$this->collectAddressData($customer)
$this->collectAddressData($customer, $address)
)
);
/** @phpstan-ignore-next-line */
Expand Down Expand Up @@ -248,28 +248,41 @@ public function create()
* @param DataCustomer|Customer $customer
* @return array
*/
private function collectAddressData($customer): array
private function collectAddressData($customer, $address): array
{
/** @phpstan-ignore-next-line */
if (!$customer->getDefaultBilling() || !$customer->getDefaultBillingAddress()) {
return [];
if (!$address && (!$customer->getDefaultBilling() || !$customer->getDefaultBillingAddress())) {
$data = [
'firstname' => $customer->getFirstname(),
'lastname' => $customer->getLastname(),
'prefix' => $customer->getPrefix(),
'email' => $customer->getEmail(),
'gender' => $customer->getAttribute('gender')
->getSource()->getOptionText($customer->getGender())
];
} else {
if ($customer->getDefaultBillingAddress()) {
$address = $customer->getDefaultBillingAddress();
}
$data = [
'firstname' => $address->getFirstname() ?? $customer->getFirstname(),
'lastname' => $address->getLastname() ?? $customer->getLastname(),
'prefix' => $address->getPrefix() ?? $customer->getPrefix(),
'name' => $this->formatName($address),
'email' => $customer->getEmail(),
'company' => $address->getCompany(),
'country' => $address->getCountry(),
'city' => $address->getCity(),
'zip' => $address->getPostcode(),
'phone' => $address->getTelephone(),
'region' => $address->getRegion(),
'street' => $address->getStreetFull(),
'address' => $this->formatAddress($address),
'gender' => $customer->getAttribute('gender')
->getSource()->getOptionText($customer->getGender())
];
}
$address = $customer->getDefaultBillingAddress();
$data = [
'firstname' => $address->getFirstname(),
'lastname' => $address->getLastname(),
'prefix' => $address->getPrefix(),
'name' => $this->formatName($address),
'email' => $customer->getEmail(),
'company' => $address->getCompany(),
'country' => $address->getCountry(),
'city' => $address->getCity(),
'zip' => $address->getPostcode(),
'phone' => $address->getTelephone(),
'region' => $address->getRegion(),
'street' => $address->getStreetFull(),
'address' => $this->formatAddress($address)
];

return $data;
}

Expand Down
5 changes: 3 additions & 2 deletions Observer/SaveAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ public function __construct(
*/
public function execute(Observer $observer)
{
$customerId = $observer->getEvent()->getCustomerAddress()->getParentId();
$address = $observer->getEvent()->getCustomerAddress();
$customerId = $address->getParentId();
if ($customerId) {
try {
$customer = $this->customerRepository->getById($customerId);
$this->profileRepository->prepareProfileData($customer, true);
$this->profileRepository->prepareProfileData($customer, true, $address);
} catch (\Exception $e) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "datatrics/magento2-integration",
"description": "Datatrics Connect extension for Magento 2",
"type": "magento2-module",
"version": "1.6.6",
"version": "1.6.7",
"license": [
"BSD-2-Clause"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<default>
<datatrics_connect_general>
<general>
<version>v1.6.6</version>
<version>v1.6.7</version>
<enable>0</enable>
<source>Magento 2</source>
<debug>0</debug>
Expand Down
6 changes: 5 additions & 1 deletion etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@
length="255"
nullable="true"
comment="Street"/>

<column name="gender"
xsi:type="varchar"
length="10"
nullable="true"
comment="Gender"/>
<column name="created_at"
xsi:type="timestamp"
on_update="false"
Expand Down
5 changes: 3 additions & 2 deletions etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"updated_at": true,
"update_msg": true,
"update_attempts": true,
"status": true
"status": true,
"gender": true
},
"index": {
"DATATRICS_PROFILE_CUSTOMER_ID": true
Expand All @@ -82,4 +83,4 @@
"DATATRICS_PROFILE_STORE_ID_STORE_STORE_ID": true
}
}
}
}

0 comments on commit bdb1acf

Please sign in to comment.