Merge pull request #1156 from openclassify/mua

product options error fixed
This commit is contained in:
spektra2147 2021-09-01 17:15:38 +03:00 committed by GitHub
commit 4bbd7b85ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,37 +6,42 @@ use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueReposit
class OptionConfigurationFormFields
{
public function handle(
OptionConfigurationFormBuilder $builder,
AdvRepositoryInterface $advRepository,
ProductoptionRepositoryInterface $productOptionRepository,
public function handle(
OptionConfigurationFormBuilder $builder,
AdvRepositoryInterface $advRepository,
ProductoptionRepositoryInterface $productOptionRepository,
ProductoptionsValueRepositoryInterface $productoptionsValueRepository
)
{
if(request()->has('ad') || $builder->getEntry())
{
$ad = $advRepository->find(request('ad') ?? $builder->getEntry());
$options = $productOptionRepository->getWithCategoryId($ad->cat1);
{
if(request()->has('ad') || $builder->getEntry())
{
$ad = $advRepository->find(request('ad') ?? $builder->getEntry());
$options_fields = array();
$options_fields = array();
foreach ($options as $option)
{
if($optionValue = $productoptionsValueRepository->getWithOptionsId([$option->id]))
{
$options_fields['option-'.$option->getId()] = [
'type' => 'anomaly.field_type.select',
'label' => $option->getName(),
'required' => true,
'config' => [
'options' => $optionValue->pluck('title','id')->all(),
]
];
}
}
$fields = array_merge($options_fields, ['price', 'currency', 'stock']);
if($ad)
{
$options = $productOptionRepository->getWithCategoryId($ad->cat1);
$builder->setFields($fields);
}
}
foreach ($options as $option)
{
if($optionValue = $productoptionsValueRepository->getWithOptionsId([$option->id]))
{
$options_fields['option-'.$option->getId()] = [
'type' => 'anomaly.field_type.select',
'label' => $option->getName(),
'required' => true,
'config' => [
'options' => $optionValue->pluck('title','id')->all(),
]
];
}
}
}
$fields = array_merge($options_fields, ['price', 'currency', 'stock']);
$builder->setFields($fields);
}
}
}