add constaint on stock

This commit is contained in:
Ludovic CANDELLIER
2022-03-07 20:17:50 +01:00
parent 6a634c10ca
commit 60acbc7939
6 changed files with 9 additions and 122 deletions

View File

@@ -123,7 +123,7 @@ class Article extends Model implements HasMedia
public function scopeWithAvailableOffers($query, $sale_channel_id = false) public function scopeWithAvailableOffers($query, $sale_channel_id = false)
{ {
return $query->whereHas('offers', function ($query) use ($sale_channel_id) { return $query->whereHas('offers', function ($query) use ($sale_channel_id) {
$query->active()->bySaleChannel($sale_channel_id); $query->active()->byStockAvailable()->bySaleChannel($sale_channel_id);
}); });
} }

View File

@@ -97,6 +97,11 @@ class Offer extends Model
return $query->where($this->table . '.variation_id', $id); return $query->where($this->table . '.variation_id', $id);
} }
public function scopeByStockAvailable($query)
{
return $query->where($this->table . '.stock_current', '>', 0);
}
public function scopeByArticleNature($query, $article_nature_id) public function scopeByArticleNature($query, $article_nature_id)
{ {
return $query->whereHas('article.article_nature', function ($query) use ($article_nature_id) { return $query->whereHas('article.article_nature', function ($query) use ($article_nature_id) {
@@ -145,5 +150,4 @@ class Offer extends Model
$query->active()->bySaleChannel($sale_channel_id); $query->active()->bySaleChannel($sale_channel_id);
}); });
} }
} }

View File

@@ -143,6 +143,9 @@ class Articles
'product', 'product',
'article_nature', 'article_nature',
'offers.variation.package', 'offers.variation.package',
'offers.tariff.price_lists' => function($query) use ($sale_channel_id) {
$query->bySaleChannel($sale_channel_id);
},
'offers.tariff.price_lists.price_list_values', 'offers.tariff.price_lists.price_list_values',
])->get(); ])->get();
} }

View File

@@ -1,42 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateActivityLogTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('activity_log', function(Blueprint $table)
{
$table->bigInteger('id', true)->unsigned();
$table->string('log_name')->nullable()->index();
$table->text('description', 65535);
$table->bigInteger('subject_id')->unsigned()->nullable();
$table->string('subject_type')->nullable();
$table->bigInteger('causer_id')->unsigned()->nullable();
$table->string('causer_type')->nullable();
$table->text('properties', 65535)->nullable();
$table->timestamps();
$table->index(['subject_id','subject_type'], 'subject');
$table->index(['causer_id','causer_type'], 'causer');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('activity_log');
}
}

View File

@@ -1,41 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateCategoriesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function(Blueprint $table)
{
$table->increments('id');
$table->string('slug')->unique();
$table->text('name', 65535);
$table->text('description', 65535)->nullable();
$table->integer('_lft')->unsigned()->default(0);
$table->integer('_rgt')->unsigned()->default(0);
$table->integer('parent_id')->unsigned()->nullable();
$table->timestamps();
$table->softDeletes();
$table->index(['_lft','_rgt','parent_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('categories');
}
}

View File

@@ -1,37 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateCategorizablesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categorizables', function(Blueprint $table)
{
$table->integer('category_id')->unsigned();
$table->string('categorizable_type');
$table->bigInteger('categorizable_id')->unsigned();
$table->timestamps();
$table->unique(['category_id','categorizable_id','categorizable_type'], 'categorizables_ids_type_unique');
$table->index(['categorizable_type','categorizable_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('categorizables');
}
}