diff --git a/addons/default/visiosoft/advs-module/migrations/2020_10_15_130044_visiosoft.module.advs__create_productoptions_stream.php b/addons/default/visiosoft/advs-module/migrations/2020_10_15_130044_visiosoft.module.advs__create_productoptions_stream.php new file mode 100644 index 000000000..2961bbc3c --- /dev/null +++ b/addons/default/visiosoft/advs-module/migrations/2020_10_15_130044_visiosoft.module.advs__create_productoptions_stream.php @@ -0,0 +1,52 @@ + [ + 'type' => 'anomaly.field_type.select', + 'config' => [ + 'handler' => 'Visiosoft\AdvsModule\OptionHandler\CategoriesOptions@handle' + ] + ], + ]; + /** + * The stream definition. + * + * @var array + */ + protected $stream = [ + 'slug' => 'productoptions', + 'title_column' => 'name', + 'translatable' => true, + 'versionable' => false, + 'trashable' => true, + 'searchable' => false, + 'sortable' => false, + ]; + + /** + * The stream assignments. + * + * @var array + */ + protected $assignments = [ + 'category', + 'name' => [ + 'translatable' => true, + 'required' => true, + ], + ]; +} diff --git a/addons/default/visiosoft/advs-module/migrations/2020_10_15_131614_visiosoft.module.advs__create_productoptions_value_stream.php b/addons/default/visiosoft/advs-module/migrations/2020_10_15_131614_visiosoft.module.advs__create_productoptions_value_stream.php new file mode 100644 index 000000000..47fff9601 --- /dev/null +++ b/addons/default/visiosoft/advs-module/migrations/2020_10_15_131614_visiosoft.module.advs__create_productoptions_value_stream.php @@ -0,0 +1,56 @@ + [ + 'type' => 'anomaly.field_type.relationship', + 'config' => [ + 'related' => ProductoptionModel::class, + ], + ] + ]; + + /** + * The stream definition. + * + * @var array + */ + protected $stream = [ + 'slug' => 'productoptions_value', + 'title_column' => 'name', + 'translatable' => true, + 'versionable' => false, + 'trashable' => true, + 'searchable' => false, + 'sortable' => false, + ]; + + /** + * The stream assignments. + * + * @var array + */ + protected $assignments = [ + 'name' => [ + 'translatable' => true, + 'required' => true, + ], + 'product_option' => [ + 'required' => true, + ], + ]; +} diff --git a/addons/default/visiosoft/advs-module/migrations/2020_10_16_082339_visiosoft.module.advs__added_options_field.php b/addons/default/visiosoft/advs-module/migrations/2020_10_16_082339_visiosoft.module.advs__added_options_field.php new file mode 100644 index 000000000..d00e201c7 --- /dev/null +++ b/addons/default/visiosoft/advs-module/migrations/2020_10_16_082339_visiosoft.module.advs__added_options_field.php @@ -0,0 +1,48 @@ + 'advs', + ]; + + /** + * The addon fields. + * + * @var array + */ + protected $fields = [ + 'product_options_value' => [ + 'type' => 'anomaly.field_type.multiple', + 'config' => [ + 'mode' => 'lookup', + 'related' => \Visiosoft\AdvsModule\ProductoptionsValue\ProductoptionsValueModel::class, + ], + ] + ]; + + /** + * The field's assignment. + * + * @var array + */ + protected $assignments = [ + 'product_options_value', + ]; +} diff --git a/addons/default/visiosoft/advs-module/migrations/2020_10_16_124151_visiosoft.module.advs__create_option_configuration_stream.php b/addons/default/visiosoft/advs-module/migrations/2020_10_16_124151_visiosoft.module.advs__create_option_configuration_stream.php new file mode 100644 index 000000000..b42c31acf --- /dev/null +++ b/addons/default/visiosoft/advs-module/migrations/2020_10_16_124151_visiosoft.module.advs__create_option_configuration_stream.php @@ -0,0 +1,58 @@ + 'visiosoft.field_type.json', + ]; + + /** + * The stream definition. + * + * @var array + */ + protected $stream = [ + 'slug' => 'option_configuration', + 'title_column' => 'option_json', + 'translatable' => false, + 'versionable' => false, + 'trashable' => false, + 'searchable' => false, + 'sortable' => false, + ]; + + /** + * The stream assignments. + * + * @var array + */ + protected $assignments = [ + 'parent_adv' => [ + 'required' => true, + ], + 'price' => [ + 'required' => true, + ], + 'currency' => [ + 'required' => true, + ], + 'stock' => [ + 'required' => true, + ], + 'option_json' => [ + '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 eae0b67cd..cead467e5 100644 --- a/addons/default/visiosoft/advs-module/resources/config/permissions.php +++ b/addons/default/visiosoft/advs-module/resources/config/permissions.php @@ -21,4 +21,29 @@ return [ 'write', 'delete', ], + 'productoptions' => [ + 'read', + 'write', + 'delete', + ], + 'productoptions_value' => [ + 'read', + 'write', + 'delete', + ], + 'options_configuration' => [ + 'read', + 'write', + 'delete', + ], + 'option_configuration' => [ + 'read', + 'write', + 'delete', + ], + 'option_configuration' => [ + 'read', + 'write', + 'delete', + ], ]; 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 ab988e7b0..1b49391ae 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/button.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/button.php @@ -32,5 +32,11 @@ return [ 'name' => 'Update Category' ], 'new_option' => 'New Option', - 'export' => 'Export' + 'export' => 'Export', + 'new_productoption' => 'New Productoption', + 'new_productoptions_value' => 'New Productoptions value', + 'new_options_configuration' => 'New Options configuration', + 'new_option_configuration' => 'New Option configuration', + 'new_option_configuration' => 'New Option configuration', + 'create_configurations' => 'Create Configurations', ]; diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/field.php b/addons/default/visiosoft/advs-module/resources/lang/en/field.php index bd9bfeb76..6fd4f4005 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/field.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/field.php @@ -137,7 +137,9 @@ return [ 'oldest' => 'Oldest', 'address_a_z' => 'Address (A to Z)', 'address_z_a' => 'Address (Z to A)', - 'categories' => 'Categories', + 'categories' => [ + 'name' => 'Categories' + ], 'all_categories' => 'All Categories', 'location' => 'Location', 'send_message' => 'Send Message', @@ -313,6 +315,12 @@ return [ 'site' => 'Site', 'subscription' => 'Subscription', 'created' => 'Created', + 'product_option' => [ + 'name' => 'Product Option' + ], + 'option_json' => [ + 'name' => 'Option' + ], 'old_price' => [ 'name' => 'Old Price' ], 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 a75575d96..0a094c9f1 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/permission.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/permission.php @@ -57,4 +57,44 @@ return [ 'delete' => 'Can delete options?', ], ], + 'productoptions' => [ + 'name' => 'Productoptions', + 'option' => [ + 'read' => 'Can read productoptions?', + 'write' => 'Can create/edit productoptions?', + 'delete' => 'Can delete productoptions?', + ], + ], + 'productoptions_value' => [ + 'name' => 'Productoptions value', + 'option' => [ + 'read' => 'Can read productoptions value?', + 'write' => 'Can create/edit productoptions value?', + 'delete' => 'Can delete productoptions value?', + ], + ], + 'options_configuration' => [ + 'name' => 'Options configuration', + 'option' => [ + 'read' => 'Can read options configuration?', + 'write' => 'Can create/edit options configuration?', + 'delete' => 'Can delete options configuration?', + ], + ], + 'option_configuration' => [ + 'name' => 'Option configuration', + 'option' => [ + 'read' => 'Can read option configuration?', + 'write' => 'Can create/edit option configuration?', + 'delete' => 'Can delete option configuration?', + ], + ], + 'option_configuration' => [ + 'name' => 'Option configuration', + 'option' => [ + 'read' => 'Can read option configuration?', + 'write' => 'Can create/edit option configuration?', + 'delete' => 'Can delete option configuration?', + ], + ], ]; 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 b3ebe1995..cdd4948d1 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/section.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/section.php @@ -45,4 +45,13 @@ return [ 'title' => 'Options', ], 'ads_image' => 'Ads Image', + 'product_options' => [ + 'title' => 'Options', + ], + 'productoptions_value' => [ + 'title' => 'Options Value', + ], + 'option_configuration' => [ + 'title' => 'Configuration', + ], ]; 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 29e720836..761fa569d 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/stream.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/stream.php @@ -22,4 +22,13 @@ return [ 'options' => [ 'name' => 'Options', ], + 'product_options' => [ + 'name' => 'Product Options', + ], + 'productoptions_value' => [ + 'name' => 'Options value', + ], + 'option_configuration' => [ + 'name' => 'Configuration', + ], ]; 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 80f58bf24..d700caebb 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 @@ -45,7 +45,7 @@ - {{ addBlock('ad-detail/details',{'adv':adv, 'options':options})|raw }} + {{ addBlock('ad-detail/details',{'adv':adv, 'options':options, 'configurations':configurations})|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 bd3a7c660..861db4e06 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 @@ -138,6 +138,15 @@ +
+ +
+ {{ form.fields.product_options_value.input|raw }} +
+
+
diff --git a/addons/default/visiosoft/advs-module/resources/views/new-ad/preview/preview.twig b/addons/default/visiosoft/advs-module/resources/views/new-ad/preview/preview.twig index 1c52f2e32..f016f7040 100644 --- a/addons/default/visiosoft/advs-module/resources/views/new-ad/preview/preview.twig +++ b/addons/default/visiosoft/advs-module/resources/views/new-ad/preview/preview.twig @@ -14,6 +14,10 @@ {% else %} {% set continueLink = url_route('adv_detail_seo', [adv.slug, adv.id]) %} {% endif %} + + {{trans('visiosoft.module.advs::button.create_configurations')}} + {{ trans('visiosoft.module.advs::field.edit') }} @@ -27,6 +31,10 @@
+ + {{trans('visiosoft.module.advs::button.create_configurations')}} + {{ trans('visiosoft.module.advs::field.edit') }} diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index 41949da7a..44a7f571c 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -385,4 +385,9 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface { return $this->finish_at ? $this->finish_at < Carbon::now() : true; } + + public function getProductOptionsValues() + { + return $this->product_options_value; + } } diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index a87a12e76..f61347c48 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -448,6 +448,10 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface ->paginate(setting_value('visiosoft.module.advs::popular_ads_limit', setting_value('streams::per_page'))); } + public function getName($id){ + return $this->find($id)->name; + } + public function approveAds($adsIDs) { $defaultAdPublishTime = setting_value('visiosoft.module.advs::default_published_time'); diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php index 586b7a94a..42968fa28 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php @@ -81,4 +81,6 @@ interface AdvInterface extends EntryInterface public function getVillage(); public function expired(); + + public function getProductOptionsValues(); } diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php index 37104c3f2..589404ee8 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php @@ -45,6 +45,8 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface public function getPopular(); + public function getName($id); + public function approveAds($adsIDs); public function getUserAds($userID = null); diff --git a/addons/default/visiosoft/advs-module/src/Adv/Form/AdvFormBuilder.php b/addons/default/visiosoft/advs-module/src/Adv/Form/AdvFormBuilder.php index 0623c5ca6..8f58892f5 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Form/AdvFormBuilder.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Form/AdvFormBuilder.php @@ -60,7 +60,8 @@ class AdvFormBuilder extends FormBuilder ], 'files', 'popular_adv', - 'adv_day' + 'adv_day', + 'product_options_value' ]; protected $category = null; diff --git a/addons/default/visiosoft/advs-module/src/AdvsModule.php b/addons/default/visiosoft/advs-module/src/AdvsModule.php index 0eda5defc..e7835c641 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModule.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModule.php @@ -37,9 +37,22 @@ class AdvsModule extends Module ], ], ], + 'product_options' => [ + 'title' => 'visiosoft.module.advs::section.product_options.title', + 'buttons' => [ + 'new_productoption', + ], + ], + 'productoptions_value' => [ + 'title' => 'visiosoft.module.advs::section.productoptions_value.title', + 'buttons' => [ + 'new_productoptions_value', + ], + ], + 'option_configuration', 'assets_clear' => [ - 'title' => 'visiosoft.module.advs::section.assets_clear.name', - 'href' => '/admin/assets/clear', + 'title' => 'visiosoft.module.advs::section.assets_clear.name', + 'href' => '/admin/assets/clear', ] // 'custom_fields' => [ // 'buttons' => [ diff --git a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php index ec32d05a9..1070f7bb7 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php @@ -15,6 +15,12 @@ use Visiosoft\AdvsModule\Http\Middleware\SetLang; use Visiosoft\AdvsModule\Listener\AddAdvsSettingsScript; use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface; use Visiosoft\AdvsModule\Option\OptionRepository; +use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface; +use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationRepository; +use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface; +use Visiosoft\AdvsModule\Productoption\ProductoptionRepository; +use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueRepositoryInterface; +use Visiosoft\AdvsModule\ProductoptionsValue\ProductoptionsValueRepository; use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface; use Visiosoft\LocationModule\Village\VillageRepository; use Visiosoft\LocationModule\Village\VillageModel; @@ -214,6 +220,28 @@ class AdvsModuleServiceProvider extends AddonServiceProvider // Others 'advs/ttr/{id}' => 'Visiosoft\PackagesModule\Http\Controller\packageFEController@advsStatusbyUser', + + //Configurations Admin Controller + 'admin/advs/option_configuration/create' => [ + 'as' => 'visiosoft.module.advs::configrations.create', + 'uses' => 'Visiosoft\AdvsModule\Http\Controller\Admin\OptionConfigurationController@create', + ], + 'admin/advs/option_configuration' => [ + 'as' => 'visiosoft.module.advs::configrations.index', + 'uses' => 'Visiosoft\AdvsModule\Http\Controller\Admin\OptionConfigurationController@index', + ], + + //Configuration Controller + 'advs/option_configuration/create' => [ + 'as' => 'visiosoft.module.advs::user.configrations.create', + 'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@create', + ], + 'conf/addCart' => [ + 'as' => 'configuration::add_cart', + 'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@confAddCart', + ], + + ]; /** @@ -294,6 +322,9 @@ class AdvsModuleServiceProvider extends AddonServiceProvider CategoryRepositoryInterface::class => CategoryRepository::class, CountryRepositoryInterface::class => CountryRepository::class, OptionRepositoryInterface::class => OptionRepository::class, + ProductoptionRepositoryInterface::class => ProductoptionRepository::class, + OptionConfigurationRepositoryInterface::class => OptionConfigurationRepository::class, + ProductoptionsValueRepositoryInterface::class => ProductoptionsValueRepository::class, ]; /** diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/AdvsController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/AdvsController.php index 47032280d..2321df840 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/AdvsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/AdvsController.php @@ -108,6 +108,10 @@ class AdvsController extends AdminController 'replicate' => [ 'text' => 'Replicate', ], + 'create_configration' => [ + 'text' => trans('visiosoft.module.advs::button.create_configurations'), + 'href' => route('visiosoft.module.advs::configrations.create')."?ad={entry.id}" + ], ], ], ]); diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/OptionConfigurationController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/OptionConfigurationController.php new file mode 100644 index 000000000..2115f408f --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/OptionConfigurationController.php @@ -0,0 +1,32 @@ +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')); + return $form->render(); + } +} diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/ProductoptionsController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/ProductoptionsController.php new file mode 100644 index 000000000..c4e57e82d --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/ProductoptionsController.php @@ -0,0 +1,43 @@ +render(); + } + + /** + * Create a new entry. + * + * @param ProductoptionFormBuilder $form + * @return \Symfony\Component\HttpFoundation\Response + */ + public function create(ProductoptionFormBuilder $form) + { + return $form->render(); + } + + /** + * Edit an existing entry. + * + * @param ProductoptionFormBuilder $form + * @param $id + * @return \Symfony\Component\HttpFoundation\Response + */ + public function edit(ProductoptionFormBuilder $form, $id) + { + return $form->render($id); + } +} diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/ProductoptionsValueController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/ProductoptionsValueController.php new file mode 100644 index 000000000..2a5acfb58 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/ProductoptionsValueController.php @@ -0,0 +1,43 @@ +render(); + } + + /** + * Create a new entry. + * + * @param ProductoptionsValueFormBuilder $form + * @return \Symfony\Component\HttpFoundation\Response + */ + public function create(ProductoptionsValueFormBuilder $form) + { + return $form->render(); + } + + /** + * Edit an existing entry. + * + * @param ProductoptionsValueFormBuilder $form + * @param $id + * @return \Symfony\Component\HttpFoundation\Response + */ + public function edit(ProductoptionsValueFormBuilder $form, $id) + { + return $form->render($id); + } +} diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/OptionConfigurationController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/OptionConfigurationController.php new file mode 100644 index 000000000..b3f4ce198 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/OptionConfigurationController.php @@ -0,0 +1,61 @@ +advRepository = $advRepository; + $this->adv_model = $advModel; + $this->optionConfigurationModel = $optionConfigurationModel; + $this->optionConfigurationRepository = $optionConfigurationRepository; + parent::__construct(); + } + + public function create(OptionConfigurationFormBuilder $form) + { + $form->setOption('redirect', route('advs_preview', [request('ad')])); + return $form->render(); + } + + public function confAddCart() + { + + if($conf = $this->optionConfigurationRepository->find($this->request->configuration)) + { + $conf->name = $conf->getName(); + + $this->adv_model->authControl(); + + if ($conf->stock < $this->request->quantity){ + return redirect()->back()->with('warning', [trans('visiosoft.module.carts::message.error1in2')]); + }else{ + $cart = $this->dispatch(new GetCart()); + $cart->add($conf, $this->request->quantity); + return $this->redirect->to(route('visiosoft.module.carts::cart')); + } + } + } +} 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 f57340647..2204a7e44 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -19,6 +19,10 @@ use Visiosoft\AdvsModule\Adv\Event\showAdPhone; use Visiosoft\AdvsModule\Adv\Event\viewAd; use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder; use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface; +use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface; +use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationModel; +use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface; +use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueRepositoryInterface; use Visiosoft\AlgoliaModule\Search\SearchModel; use Visiosoft\CatsModule\Category\CategoryModel; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; @@ -41,6 +45,10 @@ class AdvsController extends PublicController private $adv_model; private $adv_repository; + private $optionConfigurationRepository; + private $productOptionRepository; + private $productOptionsValueRepository; + private $country_repository; private $city_model; @@ -67,6 +75,10 @@ class AdvsController extends PublicController AdvModel $advModel, AdvRepositoryInterface $advRepository, + OptionConfigurationRepositoryInterface $optionConfigurationRepository, + ProductoptionRepositoryInterface $productOptionRepository, + ProductoptionsValueRepositoryInterface $productOptionsValueRepository, + CountryRepositoryInterface $country_repository, CityModel $city_model, @@ -95,6 +107,10 @@ class AdvsController extends PublicController $this->adv_model = $advModel; $this->adv_repository = $advRepository; + $this->optionConfigurationRepository = $optionConfigurationRepository; + $this->productOptionRepository = $productOptionRepository; + $this->productOptionsValueRepository = $productOptionsValueRepository; + $this->country_repository = $country_repository; $this->city_model = $city_model; @@ -550,9 +566,11 @@ class AdvsController extends PublicController $this->template->set('showTitle', false); $this->template->set('meta_title', $metaTitle); - if ($adv->created_by_id == isset(auth()->user()->id) or $adv->status == "approved") { + $configurations = $this->optionConfigurationRepository->getConf($adv->id); + + 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', 'options')); + 'recommended_advs', 'categories', 'features', 'comments', 'qrSRC', 'options', 'configurations')); } else { return back(); } @@ -593,7 +611,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', 'options')); + compact('adv', 'categories', 'features', 'isActiveDopings', 'configurations')); } public function getLocations() diff --git a/addons/default/visiosoft/advs-module/src/OptionConfiguration/Contract/OptionConfigurationInterface.php b/addons/default/visiosoft/advs-module/src/OptionConfiguration/Contract/OptionConfigurationInterface.php new file mode 100644 index 000000000..99be0f686 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/OptionConfiguration/Contract/OptionConfigurationInterface.php @@ -0,0 +1,8 @@ +has('ad')) + { + $ad = $advRepository->find(request('ad')); + + $options = $ad->getProductOptionsValues()->groupBy('product_option_id'); + + $options_fields = array(); + + foreach ($options as $option_id => $option_values) + { + if($option = $productOptionRepository->find($option_id)) + { + $options_fields['option-'.$option->getId()] = [ + 'type' => 'anomaly.field_type.select', + 'label' => $option->getName(), + 'required' => true, + 'config' => [ + 'options' => $option_values->pluck('name','id')->all(), + ] + ]; + } + } + $fields = array_merge($options_fields, ['price', 'currency', 'stock']); + + $builder->setFields($fields); + } + } +} diff --git a/addons/default/visiosoft/advs-module/src/OptionConfiguration/Form/OptionConfigurationFormHandler.php b/addons/default/visiosoft/advs-module/src/OptionConfiguration/Form/OptionConfigurationFormHandler.php new file mode 100644 index 000000000..da93db1c2 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/OptionConfiguration/Form/OptionConfigurationFormHandler.php @@ -0,0 +1,35 @@ +canSave()) { + return; + } + + $parameters = $builder->getPostData(); + $parameters['parent_adv_id'] = request()->get('ad'); + + $option_json = array(); + + foreach ($parameters as $key => $parameter_value) { + if (substr($key, 0, 7) === "option-") { + $option_id = substr($key, 7); + $option_json[$option_id] = $parameter_value; + unset($parameters[$key]); + } + } + $option_json = ['option_json' => json_encode($option_json)]; + $configration = array_merge($parameters, $option_json); + + + $entry = $repository->create($configration); + $builder->setFormEntry($entry); + } +} diff --git a/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationCollection.php b/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationCollection.php new file mode 100644 index 000000000..64c3e2d1d --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationCollection.php @@ -0,0 +1,8 @@ +find($this->parent_adv_id)) + { + $configurations_item = json_decode($this->option_json, true); + $option_group_value = ""; + + foreach ($configurations_item as $option_id => $value) { + $value_entry = app(ProductoptionsValueRepositoryInterface::class)->find($value); + $option_group_value .= " " . $value_entry->getName(); + } + + return $adv->name . ' | ' . trim($option_group_value, ' '); + } + } +} diff --git a/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationObserver.php b/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationObserver.php new file mode 100644 index 000000000..a954f8a1d --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationObserver.php @@ -0,0 +1,8 @@ +model = $model; + $this->advRepository = $advRepository; + $this->productOptionsValueRepository = $productoptionsValueRepository; + } + + public function createConfigration($ad_id, $price, $currency, $stock, $option_json) + { + return $this->create([ + 'parent_adv_id' => $ad_id, + 'price' => $price, + 'currency' => $currency, + 'stock' => $stock, + 'option_json' => $option_json, + ]); + } + + public function getConf($ad_id) + { + $adv = $this->advRepository->find($ad_id); + $configurations = array(); + + $product_configurations = $this->model->where('stock', '>', '0')->where('parent_adv_id', $ad_id)->get(); + + foreach ($product_configurations as $product_configuration) { + $configurations_item = json_decode($product_configuration->option_json, true); + $option_group_value = ""; + foreach ($configurations_item as $option_id => $value) { + $value_entry = $this->productOptionsValueRepository->find($value); + $option_group_value .= " " . $value_entry->getName(); + } + $configurations[$product_configuration->getId()] = [ + 'name' => $option_group_value, + 'price' => $product_configuration->price, + 'currency' => $product_configuration->currency, + 'stock' => $product_configuration->stock, + 'adv' => $adv->name . ' (' . trim($option_group_value, ' ') . ')', + ]; + } + + return $configurations; + } +} diff --git a/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationRouter.php b/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationRouter.php new file mode 100644 index 000000000..87fe2c59c --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/OptionConfiguration/OptionConfigurationRouter.php @@ -0,0 +1,8 @@ +setColumns([ + 'name' => [ + 'value' => function (EntryModel $entry, + AdvRepositoryInterface $advRepository) { + + $adv = $advRepository->findById($entry->parent_adv_id); + return "parent_adv_id]) . "'>$adv->name"; + } + ], + 'option_json' => [ + 'value' => function (EntryModel $entry, + ProductoptionRepositoryInterface $productOptionRepository, + ProductoptionsValueRepositoryInterface $productOptionsValueRepository) { + + $values = json_decode($entry->option_json); + $text = ""; + + foreach ($values as $key => $value) { + $productOption = $productOptionRepository->findBy('entry_id', $key); + $productOptionsValue = $productOptionsValueRepository->findBy('entry_id', $value); + + $text .= + '' . + $productOption->name . ': ' . $productOptionsValue->name . + ''; + + } + + return $text; + } + ], + ]); + } +} diff --git a/addons/default/visiosoft/advs-module/src/OptionHandler/CategoriesOptions.php b/addons/default/visiosoft/advs-module/src/OptionHandler/CategoriesOptions.php new file mode 100644 index 000000000..ce3958242 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/OptionHandler/CategoriesOptions.php @@ -0,0 +1,21 @@ +categoryRepository = $categoryRepository; + } + + public function handle(SelectFieldType $fieldType) + { + $categories = $this->categoryRepository->mainCats(); + $options = $categories->pluck('name', 'id')->all(); + $fieldType->setOptions($options); + } +} \ No newline at end of file diff --git a/addons/default/visiosoft/advs-module/src/Productoption/Contract/ProductoptionInterface.php b/addons/default/visiosoft/advs-module/src/Productoption/Contract/ProductoptionInterface.php new file mode 100644 index 000000000..66e68c2dc --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Productoption/Contract/ProductoptionInterface.php @@ -0,0 +1,8 @@ +name; + } +} diff --git a/addons/default/visiosoft/advs-module/src/Productoption/ProductoptionObserver.php b/addons/default/visiosoft/advs-module/src/Productoption/ProductoptionObserver.php new file mode 100644 index 000000000..e1a582328 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Productoption/ProductoptionObserver.php @@ -0,0 +1,8 @@ +model = $model; + } + + public function getWithCategoryId($id) + { + return $this->findAllBy('category',$id); + } +} diff --git a/addons/default/visiosoft/advs-module/src/Productoption/ProductoptionRouter.php b/addons/default/visiosoft/advs-module/src/Productoption/ProductoptionRouter.php new file mode 100644 index 000000000..8067574e6 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Productoption/ProductoptionRouter.php @@ -0,0 +1,8 @@ +getWithCategoryId(7)->pluck('id')->all(); + + $values = $value_repository->getWithOptionsId($options_id); + return parent::setTableEntries($values); + } + /** + * The table views. + * + * @var array|string + */ + protected $views = []; + + /** + * The table filters. + * + * @var array|string + */ + protected $filters = []; + + /** + * The table columns. + * + * @var array|string + */ + protected $columns = []; + + /** + * The table buttons. + * + * @var array|string + */ + protected $buttons = [ + 'edit' + ]; + + /** + * The table actions. + * + * @var array|string + */ + protected $actions = [ + 'delete' + ]; + + /** + * The table options. + * + * @var array + */ + protected $options = []; + + /** + * The table assets. + * + * @var array + */ + protected $assets = []; + +} diff --git a/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Contract/ProductoptionsValueInterface.php b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Contract/ProductoptionsValueInterface.php new file mode 100644 index 000000000..82fbb4f25 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Contract/ProductoptionsValueInterface.php @@ -0,0 +1,8 @@ +name; + } +} diff --git a/addons/default/visiosoft/advs-module/src/ProductoptionsValue/ProductoptionsValueObserver.php b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/ProductoptionsValueObserver.php new file mode 100644 index 000000000..0e323b8d3 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/ProductoptionsValueObserver.php @@ -0,0 +1,8 @@ +model = $model; + } + + public function getWithOptionsId(array $ids) + { + return $this->newQuery()->whereIn('product_option_id', $ids)->get(); + } +} diff --git a/addons/default/visiosoft/advs-module/src/ProductoptionsValue/ProductoptionsValueRouter.php b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/ProductoptionsValueRouter.php new file mode 100644 index 000000000..e912ae9bf --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/ProductoptionsValueRouter.php @@ -0,0 +1,8 @@ + + * @author Ryan Thompson + */ +class LookupTableBuilder extends \Anomaly\MultipleFieldType\Table\LookupTableBuilder +{ + public function setTableEntries(\Illuminate\Support\Collection $entries) + { + $option_repository = app(ProductoptionRepositoryInterface::class); + $value_repository = app(ProductoptionsValueRepositoryInterface::class); + + $options_id = $option_repository->getWithCategoryId(7)->pluck('id')->all(); + + $values = $value_repository->getWithOptionsId($options_id); + return parent::setTableEntries($values); + } + + protected $filters = [ + 'product_option' + ]; + + /** + * The table columns. + * + * @var array + */ + protected $columns = [ + 'name', 'product_option' + ]; +} diff --git a/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Support/MultipleFieldType/SelectedTableBuilder.php b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Support/MultipleFieldType/SelectedTableBuilder.php new file mode 100644 index 000000000..dccc81c96 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Support/MultipleFieldType/SelectedTableBuilder.php @@ -0,0 +1,21 @@ + + * @author Ryan Thompson + */ +class SelectedTableBuilder extends \Anomaly\MultipleFieldType\Table\SelectedTableBuilder +{ + + /** + * The table columns. + * + * @var array + */ + protected $columns = [ + 'name', 'product_option' + ]; +} diff --git a/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Support/MultipleFieldType/ValueTableBuilder.php b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Support/MultipleFieldType/ValueTableBuilder.php new file mode 100644 index 000000000..b9a42c19b --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Support/MultipleFieldType/ValueTableBuilder.php @@ -0,0 +1,21 @@ + + * @author Ryan Thompson + */ +class ValueTableBuilder extends \Anomaly\MultipleFieldType\Table\ValueTableBuilder +{ + + /** + * The table columns. + * + * @var array + */ + protected $columns = [ + 'name', 'product_option' + ]; +} diff --git a/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Table/ProductoptionsValueTableBuilder.php b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Table/ProductoptionsValueTableBuilder.php new file mode 100644 index 000000000..8c331821d --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/ProductoptionsValue/Table/ProductoptionsValueTableBuilder.php @@ -0,0 +1,68 @@ + [ + 'value' => 'entry.name' + ], + 'product_option', + ]; + + /** + * The table buttons. + * + * @var array|string + */ + protected $buttons = [ + 'edit' + ]; + + /** + * The table actions. + * + * @var array|string + */ + protected $actions = [ + 'delete' + ]; + + /** + * The table options. + * + * @var array + */ + protected $options = []; + + /** + * The table assets. + * + * @var array + */ + protected $assets = []; + +} diff --git a/addons/default/visiosoft/profile-module/src/Profile/Profile/ProfileFormHandler.php b/addons/default/visiosoft/profile-module/src/Profile/Profile/ProfileFormHandler.php index f98368903..aae2f88f6 100644 --- a/addons/default/visiosoft/profile-module/src/Profile/Profile/ProfileFormHandler.php +++ b/addons/default/visiosoft/profile-module/src/Profile/Profile/ProfileFormHandler.php @@ -36,7 +36,7 @@ class ProfileFormHandler // Prevent removing already filled fields foreach ($parameters as $field => $value) { if ($user->$field && !$value) { - $messages->error('visiosoft.module.profile::message.can_not_changed_filled_fields'); + $messages->error('visiosoft.module.profile::message.can_not_remove_filled_fields'); return; } }