Refactor save_customer method to saveCustomer for PSR compliance

Signed-off-by: objec <objecttothis@gmail.com>
This commit is contained in:
objec
2026-04-30 14:21:34 +04:00
parent f71af765f8
commit 43bee7bfe4
2 changed files with 11 additions and 13 deletions

View File

@@ -231,7 +231,7 @@ class Customers extends Persons
'sales_tax_code_id' => $this->request->getPost('sales_tax_code_id') == '' ? null : $this->request->getPost('sales_tax_code_id', FILTER_SANITIZE_NUMBER_INT)
];
if ($this->customer->save_customer($personData, $customerData, $customerId)) {
if ($this->customer->saveCustomer($personData, $customerData, $customerId)) {
Events::trigger('customer_saved', $customerData);
// New customer
@@ -400,7 +400,7 @@ class Customers extends Persons
if ($invalidated) {
$failCodes[] = $rowNumber;
log_message('error', "Row $rowNumber was not imported: Either email or account number already exist or data was invalid.");
} elseif ($this->customer->save_customer($person_data, $customer_data)) {
} elseif ($this->customer->saveCustomer($person_data, $customer_data)) {
Events::trigger('customer_saved', $person_data);
} else {
$failCodes[] = $rowNumber;

View File

@@ -210,28 +210,26 @@ class Customer extends Person
/**
* Inserts or updates a customer
*/
public function save_customer(array &$person_data, array &$customer_data, int $customer_id = NEW_ENTRY): bool
public function saveCustomer(array &$personData, array &$customerData, int $customerId = NEW_ENTRY): bool
{
$success = false;
$this->db->transStart();
if (parent::save_value($person_data, $customer_id)) {
if (parent::save_value($personData, $customerId)) {
$builder = $this->db->table('customers');
if ($customer_id == NEW_ENTRY || !$customer_id || !$this->exists($customer_id)) {
$customer_data['person_id'] = $person_data['person_id'];
$success = $builder->insert($customer_data);
if ($customerId == NEW_ENTRY || !$customerId || !$this->exists($customerId)) {
$customerData['person_id'] = $personData['person_id'];
$success = $builder->insert($customerData);
} else {
$builder->where('person_id', $customer_id);
$success = $builder->update($customer_data);
$customer_data['person_id'] = $customer_id;
$builder->where('person_id', $customerId);
$success = $builder->update($customerData);
$customerData['person_id'] = $customerId;
}
}
$this->db->transComplete();
$success &= $this->db->transStatus();
return $success;
return $success && $this->db->transStatus();
}
/**