", $this->address["phone"]);
}
if (!in_array('email', $excludedRows)) {
$row .= sprintf("
%s
", $this->address["email"]);
}
if (!in_array('account_id', $excludedRows)) {
$row .= sprintf("
%s
", $this->address["account_id"]);
}
return $row;
}
public function toArray()
{
$data = $this->address;
$data['id'] = $this->id;
return $data;
}
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
}
public function fromArray($array)
{
$this->id = (int)$array['id'];
foreach ($array as $key => $val) {
if (array_key_exists($key, $this->address)) {
$this->address[$key] = $val;
}
}
}
public static function getAddressById($id)
{
$opt = get_option('polkurier_addresses');
$opt[$id]->id = $id;
return $opt[$id];
}
public static function getCoverAddressById($id)
{
$opt = get_option('polkurier_cover_addresses');
if ($opt[$id] !== null) {
$opt[$id]->id = $id;
return $opt[$id];
}
return null;
}
public function renderForm()
{
if ($this->id || $this->id == 0) {
echo '';
}
?>
Opcja dostępna dla klientów
nadających przesyłki za pośrednictwem przewoźnika Geis oraz posiadających aktywną opcje stałych
odbiorów. ID konta należy pozyskać kontaktując się z biurem obsługi klienta serwisu
polkurier.pl.
account;
}
public function asTableRow()
{
return sprintf("
%s
%s
",
$this->alias,
$this->account
);
}
}
class PolkurierOrder extends PolkurierModel
{
public $params = [
'id' => null,
'wp_order_id' => null,
"order_number" => '',
"label" => null,
"price_gross" => 0,
"price_net" => 0,
"carrier" => '',
"address" => null,
"address_to" => null,
"pobranie" => 0,
'status_code' => '',
"extra" => [],
'date_created' => null,
];
/**
* @param $response
* @param $carrier
* @param $address
* @param $address_to
* @param $pobranie
* @param $extra
* @return PolkurierOrder
*/
public static function createFromApiResponse($response, $carrier, $address, $address_to, $pobranie, $extra)
{
$order = new PolkurierOrder();
$order->order_number = (string)$response['order_number'];
$order->label = (array)$response['label'];
$order->price_gross = (float)$response['price_gross'];
$order->price_net = (float)$response['price_net'];
$order->carrier = (string)$carrier;
$order->address = $address;
$order->address_to = $address_to;
$order->pobranie = (float)$pobranie;
$order->extra = (array)$extra;
$order->date_created = new DateTime();
return $order;
}
/**
* @return $this
*/
public function save()
{
global $wpdb;
if (!empty($this->getId())) {
$wpdb->update($wpdb->prefix . 'polkurier_orders', $this->toArray(), [
'id' => $this->getId()
]);
} else {
$this->wp_order_id = $wpdb->insert($wpdb->prefix . 'polkurier_orders', $this->toArray());
}
return $this;
}
/**
* @param $params
* @return $this
*/
public function fromArray($params)
{
$this->id = (int)$params['id'];
$this->wp_order_id = (int)$params['wp_order_id'];
$this->order_number = (string)$params['order_number'];
$this->label = json_decode($params['label'], true);
$this->price_gross = (float)$params['price_gross'];
$this->price_net = (float)$params['price_net'];
$this->carrier = $params['carrier'];
$this->address = new PolkurierAddress();
$this->address->fromArray(json_decode($params['address'], true));
$this->address_to = new PolkurierAddress();
$this->address_to->fromArray(json_decode($params['address_to'], true));
$this->pobranie = (float)$params['pobranie'];
$this->status_code = $params['status_code'];
$this->extra = json_decode($params['extra'], true);
$this->date_created = \Polkurier\Util\Dates::dateTimeOrNull($params['date_created']);
return $this;
}
public function toArray()
{
$data = parent::toArray();
$data['date_created'] = $this->date_created
? $this->date_created->format(\Polkurier\Util\Dates::MYSQL_DATETIME)
: date(\Polkurier\Util\Dates::MYSQL_DATETIME);
return $data;
}
/**
* @param $id
* @return PolkurierOrder|null
*/
public static function getOrderByWCOrderId($id)
{
return PolkurierOrder::getOrderBy('wp_order_id', (int)$id);
}
/**
* @param $id
* @return PolkurierOrder|null
*/
public static function getOrderById($id)
{
return PolkurierOrder::getOrderBy('id', (int)$id);
}
/**
* @param $orderNumber
* @return PolkurierOrder|null
*/
public static function getOrderByNumber($orderNumber)
{
return PolkurierOrder::getOrderBy('order_number', $orderNumber);
}
/**
* @param string $field
* @param string $value
* @return PolkurierOrder|null
*/
public static function getOrderBy($field, $value)
{
global $wpdb;
$data = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}polkurier_orders WHERE `$field` = %s", $value), ARRAY_A);
if (!empty($data)) {
$order = new PolkurierOrder();
$order->fromArray($data);
return $order;
}
return null;
}
/**
* @param $id
* @return bool
*/
public static function hasOrderDefined($id)
{
return self::getOrderByWCOrderId($id) !== null;
}
/**
* @param array $where
* @return string
*/
private static function createWhere(array $where)
{
$searchQuery = '';
if (isset($where['searchQuery'])) {
$searchQuery = trim($where['searchQuery']);
unset($where['searchQuery']);
}
$query = \Polkurier\Util\Database::createWhere($where);
if (!empty($searchQuery)) {
if (!empty($query)) {
$query = "($query) AND ";
}
$query .= \Polkurier\Util\Database::createSearchWhere($searchQuery, array(
'order_number',
'label',
'address',
'address_to',
));
}
return $query;
}
/**
* @param array $where
* @param string|array $order
* @param null $limit
* @param null $offset
* @return PolkurierOrder[]
*/
public static function getAll($where = array(), $order = null, $limit = null, $offset = null)
{
global $wpdb;
$data = [];
$query = "SELECT * FROM {$wpdb->prefix}polkurier_orders";
$whereString = self::createWhere($where);
if (!empty($whereString)) {
$query .= ' WHERE ' . $whereString;
}
if (!empty($order)) {
$col = is_array($order) ? $order[0] : $order;
$dir = strtoupper(is_array($order) ? $order[1] : 'ASC');
$dir = $dir === 'DESC' ? 'DESC' : 'ASC';
$query .= " ORDER BY `$col` $dir ";
}
$limit = (int)$limit;
$offset = (int)$offset;
if (!empty($limit)) {
$query .= ' LIMIT ' . $limit;
if (!empty($offset)) {
$query .= ' OFFSET ' . $offset;
}
}
foreach ($wpdb->get_results($query, ARRAY_A) as $row) {
$polkurierOrder = new PolkurierOrder();
$polkurierOrder->fromArray($row);
$data[] = $polkurierOrder;
}
return $data;
}
/**
* @param array $where
* @return int
*/
public static function countAll($where = array())
{
global $wpdb;
$query = "SELECT COUNT(*) as c FROM {$wpdb->prefix}polkurier_orders";
$whereString = self::createWhere($where);
if (!empty($whereString)) {
$query .= ' WHERE ' . $whereString;
}
$data = $wpdb->get_results($query, ARRAY_A);
return (int)$data[0]['c'];
}
/**
* @param $id
*/
public static function deleteByOrderNumber($orderNumber)
{
global $wpdb;
$wpdb->delete($wpdb->prefix . 'polkurier_orders', ['order_number' => $orderNumber]);
}
public function getDateCreated()
{
if (!($this->date_created instanceof DateTime)) {
$this->date_created = new DateTime('1970-01-01');
}
return $this->date_created;
}
}