131 lines
3.5 KiB
PHP
131 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Lib\Arcadia;
|
|
|
|
use App\Enums\Arcadia\ArcadiaOrderType;
|
|
use App\Enums\Shop\OrderType;
|
|
use App\Models\Order;
|
|
use App\Models\SellItem;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use Illuminate\Contracts\Support\Jsonable;
|
|
|
|
/**
|
|
* @property-read int $operation
|
|
* @property-read int $support_code
|
|
* @property-read string $label_type_support
|
|
* @property-read \Carbon\Carbon $order_date
|
|
* @property-read int $order_num
|
|
* @property-read int $state_order
|
|
* @property-read int $package_unit_weight
|
|
* @property-read string $email
|
|
* @property-read string $firstname
|
|
* @property-read string $lastname
|
|
* @property-read string $address
|
|
* @property-read string|null $address2
|
|
* @property-read string $city
|
|
* @property-read string $postcode
|
|
* @property-read string|null $phone
|
|
*/
|
|
class HasOrderedAnItemData implements Arrayable, Jsonable
|
|
{
|
|
/**
|
|
* Store data in it.
|
|
*
|
|
* @var array
|
|
*/
|
|
private $data = [];
|
|
|
|
/**
|
|
* Accessibles properties.
|
|
*
|
|
* @var array
|
|
*/
|
|
private $properties = [
|
|
'operation',
|
|
'support_code',
|
|
'label_type_support',
|
|
'order_date',
|
|
'order_num',
|
|
'state_order',
|
|
'package_unit_weight',
|
|
'email',
|
|
'firstname',
|
|
'lastname',
|
|
'address',
|
|
'address2',
|
|
'city',
|
|
'postcode',
|
|
'phone',
|
|
];
|
|
|
|
/**
|
|
* Getter.
|
|
*
|
|
* @return mixed
|
|
*
|
|
* @throws \Error On undefiend prop access.
|
|
*/
|
|
public function __get(string $name)
|
|
{
|
|
if (\in_array($name, $this->properties)) {
|
|
return $this->data[$name];
|
|
}
|
|
throw new \Error("Cannot access property {$name} it dos not exists");
|
|
}
|
|
|
|
/**
|
|
* Has ordered an item data.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(
|
|
Order $order,
|
|
SellItem $sellItem,
|
|
string $firstname,
|
|
string $lastname,
|
|
string $address,
|
|
?string $address2,
|
|
string $city,
|
|
string $postcode,
|
|
?string $phone
|
|
) {
|
|
$this->data = [
|
|
'operation' => \intval(env('BOUTIQUE_ARCADIA_OP_CODE', 16)),
|
|
'support_code' => $sellItem->arcadia_id,
|
|
'label_type_support' => $sellItem->name,
|
|
'order_date' => $order->created_at,
|
|
'order_num' => $order->getKey(),
|
|
'state_order' => $order->payementType->equals(OrderType::cb) ? ArcadiaOrderType::cb->value() : ArcadiaOrderType::check->value(),
|
|
'package_unit_weight' => $sellItem->arcadia_weight,
|
|
'email' => $order->email,
|
|
'firstname' => $firstname,
|
|
'lastname' => $lastname,
|
|
'address' => $address,
|
|
'address2' => $address2,
|
|
'city' => $city,
|
|
'postcode' => $postcode,
|
|
'phone' => $phone,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Convert the object to its JSON representation.
|
|
*
|
|
* @param int $options
|
|
*
|
|
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
|
*/
|
|
public function toJson($options = 0): string
|
|
{
|
|
// phpcs:enable
|
|
return \json_encode($this->toArray(), $options);
|
|
}
|
|
|
|
/**
|
|
* Get the instance as an array.
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return $this->data;
|
|
}
|
|
}
|