Skip to content

Commit

Permalink
fix: create customer account in order created
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiano-mallmann committed Nov 6, 2024
1 parent 8c5abf3 commit 07f805d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/Model/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,15 @@ private function formatFieldsWhenIsSubscription(&$fields, $wc_order)

private function getCardId($fields, $wc_order)
{
if($fields['card_id']){
if (isset($fields['card_id']) && $fields['card_id']) {
return $fields['card_id'];
}
$customer = new Customer($wc_order->get_customer_id());
$cardService = new CardService();
$pagarmeCard = $cardService->create($fields['pagarmetoken1'], $customer->getPagarmeCustomerId());
$pagarmeCard = $cardService->create(
$fields['pagarmetoken1'],
$customer->getPagarmeCustomerIdByOrder($wc_order)
);
return $pagarmeCard['cardId'];
}

Expand Down
34 changes: 23 additions & 11 deletions src/Service/CustomerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ public function createAddress($addressData)
public function extractCustomerDataByWcOrder($wcOrder)
{
$billingData = $wcOrder->get_data()['billing'];

$document = $wcOrder->get_meta('_billing_cpf');
if (empty($document)) {
$document = $wcOrder->get_meta('_billing_cnpj');
}
if (empty($document)) {
$document = $wcOrder->get_meta('_billing_document');
}

$document = $this->getCustomerDocumentByOrder($wcOrder);
$customerData = [
'code' => $wcOrder->get_customer_id(),
'email' => $billingData['email'],
Expand All @@ -88,11 +80,11 @@ public function extractCustomerDataByWcOrder($wcOrder)
'document_type' => Utils::getDocumentTypeByDocumentNumber($document),
'home_phone' => $billingData['phone'],
'mobile_phone' => $wcOrder->get_meta('_billing_cellphone'),
'street' => $billingData['street'],
'street' => $billingData['street'] ?? $billingData['address_1'],
'country' => $billingData['country'],
'city' => $billingData['city'],
'state' => $billingData['state'],
'complement' => $billingData['complement'],
'complement' => $billingData['complement'] ?? $billingData['address_2'],
'zipcode' => $billingData['postcode']
];

Expand All @@ -107,6 +99,26 @@ public function extractCustomerDataByWcOrder($wcOrder)
return $customerData;
}

/**
* Get customer document by order
* @param WC_Order $wcOrder
* @return string
*/
public function getCustomerDocumentByOrder($wcOrder)
{
$document = $wcOrder->get_meta('_billing_cpf');
if (empty($document)) {
$document = $wcOrder->get_meta('_billing_cnpj');
}
if (empty($document)) {
$document = $wcOrder->get_meta('_billing_document');
}
if (empty($document)) {
$document = $wcOrder->get_meta('_wc_billing/address/document');
}
return $document;
}

public function saveOnPlatform($customer)
{
$this->saveOnLegacyMethod($customer);
Expand Down

0 comments on commit 07f805d

Please sign in to comment.