mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
Merge pull request #897 from openclassify/dia
#3045 product options error
This commit is contained in:
commit
ad6c302b4f
@ -1,8 +1,15 @@
|
||||
<?php namespace Visiosoft\AdvsModule\Adv;
|
||||
|
||||
use Visiosoft\AdvsModule\Adv\Command\DeleteOptionConfiguration;
|
||||
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
|
||||
use Anomaly\Streams\Platform\Entry\EntryObserver;
|
||||
|
||||
class AdvObserver extends EntryObserver
|
||||
{
|
||||
public function deleting(EntryInterface $entry)
|
||||
{
|
||||
$this->dispatch(new DeleteOptionConfiguration($entry));
|
||||
|
||||
parent::deleting($entry);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
<?php namespace Visiosoft\AdvsModule\Adv\Command;
|
||||
|
||||
use Visiosoft\AdvsModule\Adv\Contract\AdvInterface;
|
||||
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
|
||||
|
||||
class DeleteOptionConfiguration
|
||||
{
|
||||
protected $ad;
|
||||
|
||||
public function __construct(AdvInterface $ad)
|
||||
{
|
||||
$this->ad = $ad;
|
||||
}
|
||||
|
||||
public function handle(OptionConfigurationRepositoryInterface $optionConfigurationRepository)
|
||||
{
|
||||
$optionConfigurationRepository->deleteAdsConfigs($this->ad->id);
|
||||
}
|
||||
}
|
||||
@ -1,29 +1,27 @@
|
||||
<?php namespace Visiosoft\AdvsModule\Http\Controller\Admin;
|
||||
|
||||
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
|
||||
use Visiosoft\AdvsModule\OptionConfiguration\Form\OptionConfigurationFormBuilder;
|
||||
use Visiosoft\AdvsModule\OptionConfiguration\Table\OptionConfigurationTableBuilder;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
|
||||
class OptionConfigurationController extends AdminController
|
||||
{
|
||||
|
||||
/**
|
||||
* Display an index of existing entries.
|
||||
*
|
||||
* @param OptionConfigurationTableBuilder $table
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function index(OptionConfigurationTableBuilder $table)
|
||||
public function index(
|
||||
OptionConfigurationTableBuilder $table,
|
||||
OptionConfigurationRepositoryInterface $optionConfigurationRepository
|
||||
)
|
||||
{
|
||||
// Remove deleted ad's configuration
|
||||
$unusedConfigs = $optionConfigurationRepository->getUnusedConfigs();
|
||||
|
||||
if (count($unusedConfigs)) {
|
||||
$optionConfigurationRepository->deleteUnusedConfigs();
|
||||
}
|
||||
|
||||
return $table->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new entry.
|
||||
*
|
||||
* @param OptionConfigurationFormBuilder $form
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function create(OptionConfigurationFormBuilder $form)
|
||||
{
|
||||
$form->setOption('redirect', route('visiosoft.module.advs::configrations.index'));
|
||||
|
||||
@ -7,4 +7,10 @@ interface OptionConfigurationRepositoryInterface extends EntryRepositoryInterfac
|
||||
public function createConfigration($ad_id,$price,$currency,$stock,$option_json);
|
||||
|
||||
public function getConf($ad_id);
|
||||
|
||||
public function getUnusedConfigs();
|
||||
|
||||
public function deleteUnusedConfigs($adsIDs);
|
||||
|
||||
public function deleteAdsConfigs($adID);
|
||||
}
|
||||
|
||||
@ -70,4 +70,24 @@ class OptionConfigurationRepository extends EntryRepository implements OptionCon
|
||||
|
||||
return $configurations;
|
||||
}
|
||||
|
||||
public function getUnusedConfigs()
|
||||
{
|
||||
return $this->newQuery()
|
||||
->leftJoin('advs_advs as ads', 'advs_option_configuration.parent_adv_id', 'ads.id')
|
||||
->whereNull('ads.id')
|
||||
->orWhereNotNull('deleted_at')
|
||||
->pluck('parent_adv_id')
|
||||
->all();
|
||||
}
|
||||
|
||||
public function deleteUnusedConfigs($adsIDs)
|
||||
{
|
||||
return $this->newQuery()->whereIn('parent_adv_id', $adsIDs)->delete();
|
||||
}
|
||||
|
||||
public function deleteAdsConfigs($adID)
|
||||
{
|
||||
return $this->newQuery()->where('parent_adv_id', $adID)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user