Skip to content

Commit

Permalink
Save old address id before delete
Browse files Browse the repository at this point in the history
  • Loading branch information
PululuK committed Dec 5, 2023
1 parent 55e08e9 commit cb54ed7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions classes/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class AddressCore extends ObjectModel
/** @var array<int, bool> Store if an adress ID exists */
protected static $addressExists = [];

/** @var int old address ID */
public $id_old_address;

/**
* @see ObjectModel::$definition
*/
Expand All @@ -129,6 +132,7 @@ class AddressCore extends ObjectModel
'id_warehouse' => ['type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false],
'id_country' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'id_state' => ['type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'],
'id_old_address' => ['type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false],
'alias' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32],
'company' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255],
'lastname' => ['type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 255],
Expand Down
1 change: 1 addition & 0 deletions classes/form/CustomerAddressPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private function updateUsedAddress(Address $address)
{
$old_address = new Address($address->id);
$address->id = $address->id_address = null;
$address->id_old_address = $old_address->id;

if ($address->save() && $old_address->delete()) {
// a new address was created, we must update current cart
Expand Down
1 change: 1 addition & 0 deletions install-dev/data/db_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CREATE TABLE `PREFIX_address` (
`id_manufacturer` int(10) unsigned NOT NULL DEFAULT '0',
`id_supplier` int(10) unsigned NOT NULL DEFAULT '0',
`id_warehouse` int(10) unsigned NOT NULL DEFAULT '0',
`id_old_address` int(10) unsigned NOT NULL DEFAULT '0',
`alias` varchar(32) NOT NULL,
`company` varchar(255) DEFAULT NULL,
`lastname` varchar(255) NOT NULL,
Expand Down

0 comments on commit cb54ed7

Please sign in to comment.