add configuration detail

This commit is contained in:
vedatakd 2021-06-30 18:26:24 +03:00
parent 19a0238b21
commit 1a3069085b
2 changed files with 52 additions and 25 deletions

View File

@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Visiosoft\AdvsModule\Adv\Contract\AdvInterface; use Visiosoft\AdvsModule\Adv\Contract\AdvInterface;
use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel; use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel;
use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationModel;
use Visiosoft\AdvsModule\Support\Command\Currency; use Visiosoft\AdvsModule\Support\Command\Currency;
use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\LocationModule\Country\CountryModel;
@ -27,6 +28,10 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
'thumbnail', 'thumbnail',
]; ];
protected $cascades = [
'configurations',
];
public function getDetailUrlAttribute() public function getDetailUrlAttribute()
{ {
// Checking for slug // Checking for slug
@ -36,6 +41,19 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
} }
} }
public function configurations()
{
return $this->hasMany(
OptionConfigurationModel::class,
'parent_adv_id'
);
}
public function getConfigurations()
{
return $this->getAttribute('configurations');
}
public function getCurrencyPriceAttribute() public function getCurrencyPriceAttribute()
{ {
return app(Currency::class)->format($this->price, $this->currency); return app(Currency::class)->format($this->price, $this->currency);

View File

@ -7,35 +7,44 @@ use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueReposit
class OptionConfigurationModel extends AdvsOptionConfigurationEntryModel implements OptionConfigurationInterface class OptionConfigurationModel extends AdvsOptionConfigurationEntryModel implements OptionConfigurationInterface
{ {
public function getName() protected $appends = [
{ 'option_name'
if($adv = app(AdvRepositoryInterface::class)->find($this->parent_adv_id)) ];
{
$configurations_item = json_decode($this->option_json, true);
$option_group_value = "";
foreach ($configurations_item as $option_id => $value) { public function getOptionNameAttribute()
$value_entry = app(ProductoptionsValueRepositoryInterface::class)->find($value); {
$option_group_value .= " " . $value_entry->getName(); return $this->getName();
} }
return $adv->name . ' | ' . trim($option_group_value, ' '); public function getName()
} {
} if ($adv = app(AdvRepositoryInterface::class)->find($this->parent_adv_id)) {
$configurations_item = json_decode($this->option_json, true);
$option_group_value = "";
public function stockControl($id, $quantity) foreach ($configurations_item as $option_id => $value) {
{ $value_entry = app(ProductoptionsValueRepositoryInterface::class)->find($value);
$conf = $this->newQuery()->find($id); $option_group_value .= " " . $value_entry->getName();
$stock = $conf->stock; }
if ($stock === NULL || $stock === 0) { return $adv->name . ' | ' . trim($option_group_value, ' ');
return 0; }
} return null;
}
if ($stock < $quantity) { public function stockControl($id, $quantity)
return 0; {
} $conf = $this->newQuery()->find($id);
$stock = $conf->stock;
return 1; if ($stock === NULL || $stock === 0) {
} return 0;
}
if ($stock < $quantity) {
return 0;
}
return 1;
}
} }