fixes
This commit is contained in:
@@ -9,67 +9,6 @@ class CustomerAddresses
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function add($userId, $data)
|
||||
{
|
||||
self::addDeliveryAddress($userId, $data);
|
||||
self::addInvoiceAddress($userId, $data);
|
||||
}
|
||||
|
||||
public static function addDeliveryAddress($userId, $data)
|
||||
{
|
||||
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
|
||||
$delivery = $data['use_for_delivery'] ?? false;
|
||||
|
||||
$data = [
|
||||
'customer_id' => $userId,
|
||||
'type' => 2,
|
||||
'name' => $name,
|
||||
'address' => $delivery ? $data['delivery_address'] : $data['address'],
|
||||
'address2' => $delivery ? $data['delivery_address2'] : $data['address2'],
|
||||
'zipcode' => $delivery ? $data['delivery_zipcode'] : $data['zipcode'],
|
||||
'city' => $delivery ? $data['delivery_city'] : $data['city'],
|
||||
];
|
||||
|
||||
return self::store($data);
|
||||
}
|
||||
|
||||
public static function addInvoiceAddress($userId, $data)
|
||||
{
|
||||
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
|
||||
|
||||
$data = [
|
||||
'customer_id' => $userId,
|
||||
'type' => 1,
|
||||
'name' => $name,
|
||||
'address' => $data['address'],
|
||||
'address2' => $data['address2'],
|
||||
'zipcode' => $data['zipcode'],
|
||||
'city' => $data['city'],
|
||||
];
|
||||
|
||||
return self::store($data);
|
||||
}
|
||||
|
||||
public static function getInvoiceAddress($customerId)
|
||||
{
|
||||
$addresses = CustomerAddress::byCustomer($customerId)->byInvoicing()->get();
|
||||
if (count($addresses)) {
|
||||
$address = $addresses->first();
|
||||
}
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
public static function getDeliveryAddress($customerId)
|
||||
{
|
||||
$addresses = CustomerAddress::byCustomer($customerId)->byDelivery()->get();
|
||||
if (count($addresses)) {
|
||||
$address = $addresses->first();
|
||||
}
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
public static function storeByCustomer($customer, $data)
|
||||
{
|
||||
$deliveries = $data['deliveries'] ?? false;
|
||||
@@ -87,6 +26,72 @@ class CustomerAddresses
|
||||
}
|
||||
}
|
||||
|
||||
public static function createByCustomer($customerId, $data)
|
||||
{
|
||||
self::addDeliveryAddress($customerId, $data);
|
||||
self::addInvoiceAddress($customerId, $data);
|
||||
}
|
||||
|
||||
public static function addDeliveryAddress($customerId, $data)
|
||||
{
|
||||
$delivery = $data['use_for_delivery'] ?? false;
|
||||
$data = array_merge($data, [
|
||||
'address' => $delivery ? $data['delivery_address'] : $data['address'],
|
||||
'address2' => $delivery ? $data['delivery_address2'] : $data['address2'],
|
||||
'zipcode' => $delivery ? $data['delivery_zipcode'] : $data['zipcode'],
|
||||
'city' => $delivery ? $data['delivery_city'] : $data['city'],
|
||||
]);
|
||||
|
||||
return self::addAddress($customerId, $data, 2);
|
||||
}
|
||||
|
||||
public static function addInvoiceAddress($customerId, $data)
|
||||
{
|
||||
return self::addAddress($customerId, $data, 1);
|
||||
|
||||
}
|
||||
|
||||
public static function addAddress($customerId, $data, $type)
|
||||
{
|
||||
$name = $data['company'] ? $data['company'] : $data['first_name'] . ' ' . $data['last_name'];
|
||||
|
||||
$data = [
|
||||
'customer_id' => $customerId,
|
||||
'type' => $type,
|
||||
'name' => $name,
|
||||
'address' => $data['address'],
|
||||
'address2' => $data['address2'],
|
||||
'zipcode' => $data['zipcode'],
|
||||
'city' => $data['city'],
|
||||
];
|
||||
|
||||
return self::store($data);
|
||||
}
|
||||
|
||||
public static function getInvoiceAddress($customerId)
|
||||
{
|
||||
$addresses = CustomerAddress::byCustomer($customerId)->byInvoicing()->get();
|
||||
return count($addresses) ? $addresses->first() : self::getByCustomer($customerId);
|
||||
}
|
||||
|
||||
public static function getDeliveryAddress($customerId)
|
||||
{
|
||||
$addresses = CustomerAddress::byCustomer($customerId)->byDelivery()->get();
|
||||
return count($addresses) ? $addresses->first() : self::getByCustomer($customerId);
|
||||
}
|
||||
|
||||
public static function getByCustomer($customerId = false)
|
||||
{
|
||||
$customer = Customers::get($customerId);
|
||||
|
||||
return $customer ? $customer->only(['address', 'adress2', 'zipcode', 'city']) : false;
|
||||
}
|
||||
|
||||
public static function getIconByType($type)
|
||||
{
|
||||
return ((int) $type === 1) ? '<i class="fa fa-fw fa-truck"></i>' : '<i class="fa fa-fw fa-file-invoice"></i>';
|
||||
}
|
||||
|
||||
public static function toggleActive($id, $active)
|
||||
{
|
||||
return self::update(['active' => $active], $id);
|
||||
|
||||
Reference in New Issue
Block a user