Files
opensourcepos/app/Models/Tokens/Token_customer.php
objecttothis 48c04417b8 Fixes
- PHP 8.2 deprecates dynamically declared class properties. Adding these declarations removes deprecation warnings and makes the code PHP 8.3 compatible.
- Add Elvis operator to set search string to an empty string when it's value is null to get rid of an error in the search function call.
- Imported class for OSPOS config
- Replaced private with protected in parent controller's property.
- Removed unneeded TODO
- Refactored local variables
- Replaced ternary notation
- Removed unneeded comments
- Removed unneeded class property
- Removed unneeded @property declarations
- Fixed database version
2024-06-15 17:19:15 +02:00

47 lines
868 B
PHP

<?php
namespace App\Models\Tokens;
use App\Libraries\Sale_lib;
use App\Models\Customer;
/**
* Token_customer class
**/
class Token_customer extends Token
{
private string $customer_info;
private Sale_lib $sale_lib;
public function __construct(string $customer_info = '')
{
parent::__construct();
$this->customer_info = $customer_info;
$this->sale_lib = new Sale_lib();
}
public function token_id(): string
{
return 'CU';
}
public function get_value(): string
{
//substitute customer info
$customer_id = $this->sale_lib->get_customer();
if($customer_id != NEW_ITEM && empty($this->customer_info))
{
$customer = model(Customer::class);
$customer_info = $customer->get_info($customer_id);
if($customer_info != '')
{
return trim($customer_info->first_name . ' ' . $customer_info->last_name);
}
}
return '';
}
}