forked from shopware/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'NEXT-11193/create-migration-for-vat-handling' into 'mas…
…ter' NEXT-11193 - Create migration for VAT handling Epic Closes NEXT-11193 See merge request shopware/6/product/platform!3491
- Loading branch information
Showing
17 changed files
with
824 additions
and
3 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
changelog/_unreleased/2020-10-19-vat-handling-for-companies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: VAT handling for companies | ||
issue: NEXT-10559 | ||
flag: FEATURE_NEXT_10559 | ||
--- | ||
# Core | ||
* Added `vat_ids` column and moved `vat_id` data from `customer_address` to `customer` table. | ||
* Added `company_tax_free`, `check_vat_id_pattern` and `vat_id_pattern` columns to `country` table. | ||
* Added `VAT ID field required` to login/registration setting. | ||
* Added `Shopware\Core\Checkout\Customer\DataAbstractionLayer\CustomerVatIdsDeprecationUpdater`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Core/Checkout/Customer/DataAbstractionLayer/CustomerVatIdsDeprecationUpdater.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Core\Checkout\Customer\DataAbstractionLayer; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent; | ||
use Shopware\Core\Framework\Uuid\Uuid; | ||
|
||
/** | ||
* @feature-deprecated (flag:FEATURE_NEXT_10559) tag:v6.4.0 - class will be removed in 6.4.0 | ||
*/ | ||
class CustomerVatIdsDeprecationUpdater | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
public function __construct(Connection $connection) | ||
{ | ||
$this->connection = $connection; | ||
} | ||
|
||
public function updateByEvent(EntityWrittenEvent $event): void | ||
{ | ||
foreach ($event->getPayloads() as $payload) { | ||
if (isset($payload['vatIds'])) { | ||
$this->updateVatIdsInCustomer($payload['vatIds'], $payload['id']); | ||
} | ||
} | ||
} | ||
|
||
private function updateVatIdsInCustomer(array $vatIds, string $customerId): void | ||
{ | ||
if (!empty($vatIds)) { | ||
$this->connection->executeUpdate( | ||
'UPDATE `customer_address` SET `vat_id` = :vatId | ||
WHERE `customer_address`.`customer_id` = :customerId | ||
AND (customer_address.vat_id <> :vatId OR customer_address.vat_id IS NULL)', | ||
[ | ||
'vatId' => $vatIds[0], | ||
'customerId' => Uuid::fromHexToBytes($customerId), | ||
] | ||
); | ||
} else { | ||
$this->connection->executeUpdate( | ||
'UPDATE `customer_address` SET `vat_id` = NULL WHERE `customer_id` = :customerId', | ||
['customerId' => Uuid::fromHexToBytes($customerId)] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.