diff --git a/addons/default/visiosoft/advs-module/migrations/2018_09_25_211014_visiosoft.module.advs__create_advs_fields.php b/addons/default/visiosoft/advs-module/migrations/2018_09_25_211014_visiosoft.module.advs__create_advs_fields.php index e6e21a7c7..3ab4d2d9b 100644 --- a/addons/default/visiosoft/advs-module/migrations/2018_09_25_211014_visiosoft.module.advs__create_advs_fields.php +++ b/addons/default/visiosoft/advs-module/migrations/2018_09_25_211014_visiosoft.module.advs__create_advs_fields.php @@ -250,5 +250,13 @@ class VisiosoftModuleAdvsCreateAdvsFields extends Migration 'default_value' => 0, ] ], + + // Options Fields + "adv" => [ + "type" => "anomaly.field_type.relationship", + "config" => [ + "related" => AdvModel::class, + ] + ] ]; } diff --git a/addons/default/visiosoft/advs-module/migrations/2020_06_05_120415_visiosoft.module.advs__create_options_stream.php b/addons/default/visiosoft/advs-module/migrations/2020_06_05_120415_visiosoft.module.advs__create_options_stream.php new file mode 100644 index 000000000..c00f35ae8 --- /dev/null +++ b/addons/default/visiosoft/advs-module/migrations/2020_06_05_120415_visiosoft.module.advs__create_options_stream.php @@ -0,0 +1,45 @@ + 'options', + 'title_column' => 'name', + 'translatable' => false, + 'versionable' => false, + 'trashable' => false, + 'searchable' => false, + 'sortable' => false, + ]; + + /** + * The stream assignments. + * + * @var array + */ + protected $assignments = [ + 'name' => [ + 'required' => true, + ], + 'adv' => [ + 'required' => true, + ], + ]; + +} diff --git a/addons/default/visiosoft/advs-module/resources/config/permissions.php b/addons/default/visiosoft/advs-module/resources/config/permissions.php index 33de065db..eae0b67cd 100644 --- a/addons/default/visiosoft/advs-module/resources/config/permissions.php +++ b/addons/default/visiosoft/advs-module/resources/config/permissions.php @@ -16,4 +16,9 @@ return [ 'write', 'delete', ], + 'options' => [ + 'read', + 'write', + 'delete', + ], ]; diff --git a/addons/default/visiosoft/advs-module/resources/js/new-create.js b/addons/default/visiosoft/advs-module/resources/js/new-create.js index c75f3693a..4464b2885 100644 --- a/addons/default/visiosoft/advs-module/resources/js/new-create.js +++ b/addons/default/visiosoft/advs-module/resources/js/new-create.js @@ -215,5 +215,10 @@ $(document).ready(function () { price = parseInt(price.replace(/\./g, '')); let decimal = parseInt($(".priceDecimalField").val()); $('.priceHidden').find('input').val(parseFloat(price + "." + decimal)); - }) + }); + + // Add dynamic option creation + $(".options-tags").select2({ + tags: true + }); }); diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/button.php b/addons/default/visiosoft/advs-module/resources/lang/en/button.php index 75eac762f..c84a77408 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/button.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/button.php @@ -31,4 +31,5 @@ return [ 'update_category' => [ 'name' => 'Update Category' ], + 'new_option' => 'New Option', ]; diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/permission.php b/addons/default/visiosoft/advs-module/resources/lang/en/permission.php index 762eea4c9..a75575d96 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/permission.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/permission.php @@ -49,4 +49,12 @@ return [ 'delete' => 'Can delete cf values?', ], ], + 'options' => [ + 'name' => 'Options', + 'option' => [ + 'read' => 'Can read options?', + 'write' => 'Can create/edit options?', + 'delete' => 'Can delete options?', + ], + ], ]; diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/section.php b/addons/default/visiosoft/advs-module/resources/lang/en/section.php index 1a3eeb889..d59a01842 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/section.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/section.php @@ -40,4 +40,7 @@ return [ 'general' => 'General', 'ads' => 'Ads', 'user' => 'User', + 'options' => [ + 'title' => 'Options', + ], ]; diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/stream.php b/addons/default/visiosoft/advs-module/resources/lang/en/stream.php index cd23e3479..29e720836 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/stream.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/stream.php @@ -19,4 +19,7 @@ return [ 'cf_values' => [ 'name' => 'Cf values', ], + 'options' => [ + 'name' => 'Options', + ], ]; diff --git a/addons/default/visiosoft/advs-module/resources/views/ad-detail/partials/detail.twig b/addons/default/visiosoft/advs-module/resources/views/ad-detail/partials/detail.twig index e5c1cbac5..5a5c3e1b7 100644 --- a/addons/default/visiosoft/advs-module/resources/views/ad-detail/partials/detail.twig +++ b/addons/default/visiosoft/advs-module/resources/views/ad-detail/partials/detail.twig @@ -34,7 +34,7 @@ - {{ addBlock('ad-detail/details',{'adv':adv})|raw }} + {{ addBlock('ad-detail/details',{'adv':adv, 'options':options})|raw }} {{ addBlock('ad-detail/widget-details',{'adv':adv})|raw }} diff --git a/addons/default/visiosoft/advs-module/resources/views/new-ad/new-create.twig b/addons/default/visiosoft/advs-module/resources/views/new-ad/new-create.twig index 435a6582b..e509c566d 100644 --- a/addons/default/visiosoft/advs-module/resources/views/new-ad/new-create.twig +++ b/addons/default/visiosoft/advs-module/resources/views/new-ad/new-create.twig @@ -20,6 +20,7 @@
{% set form = form('advs', 'advs').entry(id).actions(['update']).get() %} {{ form_open({ + 'id': 'createEditAdvForm', 'class': 'form ' ~ form.options.class , 'enctype': 'multipart/form-data', 'url': 'advs/save_adv', @@ -94,6 +95,22 @@
+
+ +
+ +
+
+
diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index f8173e67e..a8aabe2ce 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -213,10 +213,10 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface return $this->getAdv()->where('advs_advs.id', $id)->first(); } - public function addCart($item, $quantity = 1) + public function addCart($item, $quantity = 1, $name = null) { $cart = $this->dispatch(new GetCart()); - $cart->add($item, $quantity); + $cart->add($item, $quantity, $name); return $this->dispatch(new GetCart()); } diff --git a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php index 133138baa..3c2eb285e 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php @@ -11,6 +11,8 @@ use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel; use Visiosoft\AdvsModule\Adv\AdvModel; use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder; use Visiosoft\AdvsModule\Listener\AddAdvsSettingsScript; +use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface; +use Visiosoft\AdvsModule\Option\OptionRepository; use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface; use Visiosoft\LocationModule\Village\VillageRepository; use Visiosoft\LocationModule\Village\VillageModel; @@ -299,7 +301,7 @@ class AdvsModuleServiceProvider extends AddonServiceProvider VillageRepositoryInterface::class => VillageRepository::class, CategoryRepositoryInterface::class => CategoryRepository::class, CountryRepositoryInterface::class => CountryRepository::class, - AdvRepositoryInterface::class => AdvRepository::class, + OptionRepositoryInterface::class => OptionRepository::class, ]; /** diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php index 88e6db12c..949d147e6 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -14,6 +14,7 @@ use Visiosoft\AdvsModule\Adv\Event\showAdPhone; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cookie; +use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface; use Visiosoft\LocationModule\City\CityRepository; use Visiosoft\ProfileModule\Adress\Contract\AdressRepositoryInterface; use function PMA\Util\get; @@ -69,6 +70,8 @@ class AdvsController extends PublicController private $settings_repository; private $event; + private $optionRepository; + public function __construct( UserRepositoryInterface $userRepository, @@ -89,6 +92,8 @@ class AdvsController extends PublicController CategoryModel $categoryModel, CategoryRepositoryInterface $category_repository, + OptionRepositoryInterface $optionRepository, + SettingRepositoryInterface $settings_repository, Dispatcher $events, @@ -122,6 +127,7 @@ class AdvsController extends PublicController $this->requestHttp = $request; parent::__construct(); + $this->optionRepository = $optionRepository; } @@ -384,6 +390,8 @@ class AdvsController extends PublicController } } + $options = $this->optionRepository->findAllBy('adv_id', $id); + if ($isCommentActive) { $CommentModel = new CommentModel(); $comments = $CommentModel->getComments($adv->id)->get(); @@ -405,7 +413,8 @@ class AdvsController extends PublicController $this->template->set('meta_image', $coverPhoto); if ($adv->created_by_id == isset(auth()->user()->id) OR $adv->status == "approved") { - return $this->view->make('visiosoft.module.advs::ad-detail/detail', compact('adv', 'complaints', 'recommended_advs', 'categories', 'features', 'comments', 'qrSRC')); + return $this->view->make('visiosoft.module.advs::ad-detail/detail', compact('adv', 'complaints', + 'recommended_advs', 'categories', 'features', 'comments', 'qrSRC', 'options')); } else { return back(); } @@ -434,6 +443,8 @@ class AdvsController extends PublicController } } + $options = $this->optionRepository->findAllBy('adv_id', $id); + if ($this->adv_model->is_enabled('customfields')) { $features = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->view($adv); } @@ -441,7 +452,7 @@ class AdvsController extends PublicController $isActiveDopings = $this->adv_model->is_enabled('dopings'); return $this->view->make('visiosoft.module.advs::new-ad/preview/preview', - compact('adv', 'categories', 'features', 'isActiveDopings')); + compact('adv', 'categories', 'features', 'isActiveDopings', 'options')); } public function getLocations() @@ -563,6 +574,27 @@ class AdvsController extends PublicController } } + // Create options + $optionsIds = array(); + foreach ($request->options as $optionValue) { + $option = $this->optionRepository->newQuery() + ->where('name', $optionValue) + ->where('adv_id', $request->update_id) + ->first(); + if (!$option) { + $option = $this->optionRepository->create([ + 'name' => $optionValue, + 'adv_id' => $request->update_id, + ]); + } + $optionsIds[] = $option->id; + } + $this->optionRepository->newQuery() + ->whereNotIn('id', $optionsIds) + ->where('adv_id', $request->update_id) + ->delete(); + + $adv->is_get_adv = $request->is_get_adv; $adv->save(); @@ -685,6 +717,8 @@ class AdvsController extends PublicController } } + $options = $this->optionRepository->findAllBy('adv_id', $id); + //Cloudinary Module $isActiveCloudinary = new AdvModel(); $isActiveCloudinary = $isActiveCloudinary->is_enabled('cloudinary'); @@ -705,7 +739,8 @@ class AdvsController extends PublicController $custom_fields = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->edit($adv, $categories, $cats); } - return $this->view->make('visiosoft.module.advs::new-ad/new-create', compact('id', 'cats_d', 'request', 'Cloudinary', 'cities', 'adv', 'custom_fields')); + return $this->view->make('visiosoft.module.advs::new-ad/new-create', compact('id', 'cats_d', + 'request', 'Cloudinary', 'cities', 'adv', 'custom_fields', 'options')); } public function statusAds($id, $type, SettingRepositoryInterface $settings, Dispatcher $events) @@ -963,11 +998,12 @@ class AdvsController extends PublicController { $id = $request->id; $quantity = $request->quantity; + $name = $request->name; $thisModel = new AdvModel(); $adv = $thisModel->isAdv($id); $response = array(); if ($adv) { - $cart = $thisModel->addCart($adv, $quantity); + $cart = $thisModel->addCart($adv, $quantity, $name); $response['status'] = "success"; } else { $response['status'] = "error";