Skip to content

Commit

Permalink
Change address logic
Browse files Browse the repository at this point in the history
  • Loading branch information
uryvskiy-dima committed Jul 31, 2024
1 parent 999544f commit 660fc0a
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions retailcrm/lib/RetailcrmOrderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,33 +981,20 @@ function ($v) use ($customer) {

$isCorporateEnabled = RetailcrmTools::isCorporateEnabled();

$crmOrder['contragent']['contragentType'] = $isCorporateEnabled && RetailcrmTools::isOrderCorporate($order)
? 'legal-entity'
: 'individual';

if ($addressInvoice instanceof Address && !empty($addressInvoice->company)) {
$crmOrder['contragent']['legalName'] = $addressInvoice->company;

if (!empty($addressInvoice->vat_number)) {
$crmOrder['contragent']['INN'] = $addressInvoice->vat_number;
}
}

if (
!$isCorporateEnabled
&& RetailcrmTools::isCampanyAndVatNumberSendEnabled()
&& Configuration::get(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED)
) {
$company = $addressDelivery->company;
$vatNumber = $addressDelivery->vat_number;
if ($isCorporateEnabled && RetailcrmTools::isOrderCorporate($order)) {
$crmOrder['contragent']['contragentType'] = 'legal-entity';
$crmOrder['contragent']['legalName'] = $addressInvoice->company ?? '';
$crmOrder['contragent']['INN'] = $addressInvoice->vat_number ?? '';
} else {
$crmOrder['contragent']['contragentType'] = 'individual';

if ($addressInvoice instanceof Address) {
$company = !empty($addressInvoice->company) ? $addressInvoice->company : $company;
$vatNumber = !empty($addressInvoice->vat_number) ? $addressInvoice->vat_number : $vatNumber;
if (
RetailcrmTools::isCampanyAndVatNumberSendEnabled()
&& Configuration::get(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED)
) {
$crmOrder['customFields']['ps_company'] = $addressInvoice->company ?? '';
$crmOrder['customFields']['ps_vat_number'] = $addressInvoice->vat_number ?? '';
}

$crmOrder['customFields']['ps_company'] = $company;
$crmOrder['customFields']['ps_vat_number'] = $vatNumber;
}

if (!empty($payment[$paymentType])) {
Expand Down

0 comments on commit 660fc0a

Please sign in to comment.