Order cancelation for downloadble product

This commit is contained in:
rahul shukla 2021-02-04 15:26:14 +05:30
parent f6a6501a62
commit 27c0a4f8ee
4 changed files with 57 additions and 5 deletions

View File

@ -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);
});
}
}

View File

@ -24,6 +24,7 @@ class DownloadableLinkPurchased extends Model implements DownloadableLinkPurchas
'customer_id',
'order_id',
'order_item_id',
'download_canceled',
];
/**

View File

@ -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);
}
}
}
}

View File

@ -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');