restart
This commit is contained in:
@@ -579,4 +579,15 @@ class Articles
|
||||
{
|
||||
return self::update(['homepage' => $homepage], $id);
|
||||
}
|
||||
|
||||
public static function getNumericHash($id)
|
||||
{
|
||||
return hexdec(self::getHash($id));
|
||||
}
|
||||
|
||||
public static function getHash($id)
|
||||
{
|
||||
$name = self::get($id)->name ?? false;
|
||||
return $name ? hash('crc32c', Str::slug($name)) : false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,39 +16,44 @@ class Baskets
|
||||
return $data ? ShopCart::add($data, $update) : false;
|
||||
}
|
||||
|
||||
public static function getBasketSummary()
|
||||
public static function getBasketSummary($sale_channel_id = false)
|
||||
{
|
||||
$basket = ShopCart::getContent();
|
||||
$offers = Offer::with('variation')->whereIn('id', ShopCart::keys())->get();
|
||||
$total = 0;
|
||||
$total_taxed = 0;
|
||||
$shipping = 5;
|
||||
foreach ($basket as $item) {
|
||||
$offer = $offers->where('id', $item->id)->first();
|
||||
$prices = Offers::getPrice($item->id, $item->quantity, $sale_channel_id);
|
||||
$detail[] = [
|
||||
'id' => (int) $item->id,
|
||||
'offer_id' => (int) $item->id,
|
||||
'name' => $offer->article->name . ' (' . $offer->variation->name . ')',
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => $item->price,
|
||||
'tax' => '',
|
||||
'price_taxed' => $item->price,
|
||||
'total' => self::getTotal($item->quantity, $item->price),
|
||||
'total_taxed' => self::getTotal($item->quantity, $item->price),
|
||||
'price' => (float) $prices->price,
|
||||
'tax' => $prices->price_taxed - $prices->price,
|
||||
'price_taxed' => (float) $prices->price_taxed,
|
||||
'total' => self::getTotal($item->quantity, $prices->price),
|
||||
'total_tax' => self::getTotal($item->quantity, $prices->price_taxed - $prices->price),
|
||||
'total_taxed' => self::getTotal($item->quantity, $prices->price_taxed),
|
||||
];
|
||||
$total += self::getTotal($item->quantity, $item->price);
|
||||
$total_taxed += self::getTotal($item->quantity, $item->price);
|
||||
$total += self::getTotal($item->quantity, $prices->price);
|
||||
$total_taxed += self::getTotal($item->quantity, $prices->price_taxed);
|
||||
}
|
||||
$data = [
|
||||
'detail' => $detail,
|
||||
'total' => $total,
|
||||
'taxes' => $total_taxed - $total,
|
||||
'total_taxed' => $total_taxed,
|
||||
'shipping' => $shipping,
|
||||
'total_shipped' => $total_taxed + $shipping,
|
||||
];
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getTotal($quantity, $price)
|
||||
{
|
||||
return (int) $quantity * $price;
|
||||
return $quantity * $price;
|
||||
}
|
||||
|
||||
public static function getBasket($sale_channel_id = false)
|
||||
|
||||
@@ -4,9 +4,10 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use Spatie\Stats\BaseStats;
|
||||
|
||||
class CustomerStats extends BaseStats {}
|
||||
class CustomerStats extends BaseStats
|
||||
{
|
||||
public function getName() : string{
|
||||
public function getName() : string
|
||||
{
|
||||
return 'customers';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,16 @@ use App\Models\Shop\Customer;
|
||||
|
||||
class Customers
|
||||
{
|
||||
public static function editProfile($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
$data = [
|
||||
'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(),
|
||||
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
|
||||
];
|
||||
dump($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getAvatar($id = false)
|
||||
{
|
||||
|
||||
@@ -11,9 +11,10 @@ class Deliveries
|
||||
return Delivery::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
public static function getAll($relations = false)
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->get();
|
||||
$model = $relations ? Delivery::with($relations) : Delivery::query();
|
||||
return $model->orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAllWithSaleChannel()
|
||||
|
||||
@@ -4,9 +4,10 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use Spatie\Stats\BaseStats;
|
||||
|
||||
class InvoiceStats extends BaseStats {}
|
||||
class InvoiceStats extends BaseStats
|
||||
{
|
||||
public function getName() : string{
|
||||
public function getName() : string
|
||||
{
|
||||
return 'invoices';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,9 @@ use App\Models\Shop\Invoice;
|
||||
|
||||
class Invoices
|
||||
{
|
||||
|
||||
public static function saveInvoice($order_id, $data)
|
||||
{
|
||||
$data['order_id'] = $order_id;
|
||||
dump($data);
|
||||
exit;
|
||||
return self::store($data);
|
||||
}
|
||||
|
||||
@@ -29,6 +26,7 @@ class Invoices
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
InvoiceStats::increase($data['total_taxed']);
|
||||
$data['uuid'] = Str::uuid()->toString();
|
||||
$data['ref'] = self::getNewRef();
|
||||
return Invoice::create($data);
|
||||
@@ -44,6 +42,8 @@ class Invoices
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
$invoice = self::get($id);
|
||||
InvoiceStats::decrease($invoice->total_priced);
|
||||
return Invoice::destroy($id);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,6 @@ class Invoices
|
||||
{
|
||||
$ref = date('ym') . '00000';
|
||||
$last_ref = Invoice::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
|
||||
return $last_ref ? $last_ref + 1 : $ref + 1;
|
||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,8 @@ class OrderDetails
|
||||
public static function saveBasket($order_id, $data)
|
||||
{
|
||||
foreach ($data as $item) {
|
||||
$detail = self::store([
|
||||
'order_id' => $order_id,
|
||||
'offer_id' => $item['id'],
|
||||
'quantity' => $item['quantity'],
|
||||
'price_taxed' => $item['price'],
|
||||
]);
|
||||
$item['order_id'] = $order_id;
|
||||
$detail = self::store($item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
13
app/Repositories/Shop/OrderStats.php
Normal file
13
app/Repositories/Shop/OrderStats.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Spatie\Stats\BaseStats;
|
||||
|
||||
class OrderStats extends BaseStats
|
||||
{
|
||||
public function getName() : string
|
||||
{
|
||||
return 'orders';
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,24 @@ class Orders
|
||||
|
||||
public static function saveOrder($data)
|
||||
{
|
||||
$data += $data['basket'];
|
||||
$basket = $data['basket'];
|
||||
unset($data['basket']);
|
||||
dump($data);
|
||||
exit;
|
||||
$order = self::store($data);
|
||||
$invoice = Invoices::saveInvoice($order->id, $data);
|
||||
return $order ? OrderDetails::saveBasket($order->id, $basket) : false;
|
||||
$detail = OrderDetails::saveBasket($order->id, $basket['detail']);
|
||||
unset($data['comment']);
|
||||
unset($data['agree']);
|
||||
unset($data['customer_id']);
|
||||
unset($data['delivery_id']);
|
||||
unset($data['detail']);
|
||||
unset($data['payment_type']);
|
||||
unset($data['sale_channel_id']);
|
||||
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
return Orders::get($id, ['customer', 'address', 'delivery', 'detail']);
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
@@ -30,6 +41,7 @@ class Orders
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
OrderStats::increase();
|
||||
return Order::create($data);
|
||||
}
|
||||
|
||||
|
||||
53
app/Repositories/Shop/Paybox.php
Normal file
53
app/Repositories/Shop/Paybox.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App;
|
||||
|
||||
use Devpark\PayboxGateway\Requests\AuthorizationWithCapture;
|
||||
use Devpark\PayboxGateway\Responses\Verify;
|
||||
use Devpark\PayboxGateway\Requests\Capture;
|
||||
|
||||
class Paybox
|
||||
{
|
||||
|
||||
public static function makeAuthorizationRequest($amount, $customer_email = 'test@example.com')
|
||||
{
|
||||
$authorizationRequest = App::make(AuthorizationWithCapture::class);
|
||||
|
||||
return $authorizationRequest->setAmount($amount)->setCustomerEmail($customer_email)
|
||||
->setPaymentNumber(1)->send('paybox.send');
|
||||
}
|
||||
|
||||
public static function verifyPayment($invoice_id)
|
||||
{
|
||||
$invoice = Invoices::get($invoice_id);
|
||||
$payboxVerify = App::make(Verify::class);
|
||||
try {
|
||||
$success = $payboxVerify->isSuccess($invoice->total_shipped);
|
||||
if ($success) {
|
||||
// process order here after making sure it was real payment
|
||||
}
|
||||
echo "OK";
|
||||
}
|
||||
catch (InvalidSignature $e) {
|
||||
Log::alert('Invalid payment signature detected');
|
||||
}
|
||||
}
|
||||
|
||||
public static function getPreviousAuthorizedRequest()
|
||||
{
|
||||
$payment = PaymentModel::find($idOfAuthorizedPayment);
|
||||
$captureRequest = App::make(Capture::class);
|
||||
$response = $captureRequest->setAmount($payment->amount)
|
||||
->setPayboxCallNumber($payment->call_number)
|
||||
->setPayboxTransactionNumber($payment->transaction_number)
|
||||
->setDayRequestNumber(2)
|
||||
->send();
|
||||
|
||||
if ($response->isSuccess()) {
|
||||
// process order here
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user