Order cancelation for downloadble product
This commit is contained in:
parent
f6a6501a62
commit
27c0a4f8ee
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddDownloadCanceledColumnInDownloadableLinkPurchasedTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('downloadable_link_purchased', function (Blueprint $table) {
|
||||
$table->integer('download_canceled')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('downloadable_link_purchased', function (Blueprint $table) {
|
||||
$table->integer('download_canceled')->default(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ class DownloadableLinkPurchased extends Model implements DownloadableLinkPurchas
|
|||
'customer_id',
|
||||
'order_id',
|
||||
'order_item_id',
|
||||
'download_canceled',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class DownloadableLinkPurchasedRepository extends Repository
|
|||
if (stristr($orderItem->type,'downloadable') !== false && isset($orderItem->additional['links'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -98,9 +98,28 @@ class DownloadableLinkPurchasedRepository extends Repository
|
|||
$purchasedLinks = $this->findByField('order_item_id', $orderItem->id);
|
||||
|
||||
foreach ($purchasedLinks as $purchasedLink) {
|
||||
$this->update([
|
||||
'status' => $status,
|
||||
], $purchasedLink->id);
|
||||
if ($status == 'expired') {
|
||||
if (count($purchasedLink->order_item->invoice_items) > 0) {
|
||||
$totalInvoiceQty = 0;
|
||||
|
||||
foreach ($purchasedLink->order_item->invoice_items as $invoice_item) {
|
||||
$totalInvoiceQty = $totalInvoiceQty + $invoice_item->qty;
|
||||
}
|
||||
|
||||
$this->update([
|
||||
'download_canceled' => $purchasedLink->download_bought - $totalInvoiceQty,
|
||||
], $purchasedLink->id);
|
||||
} else {
|
||||
$this->update([
|
||||
'status' => $status,
|
||||
'download_canceled' => $purchasedLink->download_bought,
|
||||
], $purchasedLink->id);
|
||||
}
|
||||
} else {
|
||||
$this->update([
|
||||
'status' => $status,
|
||||
], $purchasedLink->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ class DownloadableProductDataGrid extends DataGrid
|
|||
->leftJoin('orders', 'downloadable_link_purchased.order_id', '=', 'orders.id')
|
||||
->leftJoin('invoices', 'downloadable_link_purchased.order_id', '=', 'invoices.order_id')
|
||||
->addSelect('downloadable_link_purchased.*', 'invoices.state as invoice_state', 'orders.increment_id')
|
||||
->addSelect(DB::raw('(' . DB::getTablePrefix() . 'downloadable_link_purchased.download_bought - ' . DB::getTablePrefix() . 'downloadable_link_purchased.download_used) as remaining_downloads'))
|
||||
->addSelect(DB::raw('(' . DB::getTablePrefix() . 'downloadable_link_purchased.download_bought - ' . DB::getTablePrefix() . 'downloadable_link_purchased.download_canceled - ' . DB::getTablePrefix() . 'downloadable_link_purchased.download_used) as remaining_downloads'))
|
||||
->where('downloadable_link_purchased.customer_id', auth()->guard('customer')->user()->id);
|
||||
|
||||
$this->addFilter('status', 'downloadable_link_purchased.status');
|
||||
|
|
|
|||
Loading…
Reference in New Issue