#4061 ads configration improvments

This commit is contained in:
Muammer Top 2021-08-03 11:05:25 +03:00
parent 3bc356b1a0
commit 77ff0b09fa
17 changed files with 190 additions and 31 deletions

View File

@ -261,4 +261,29 @@ label {
} }
} }
} }
} }
.btn-configuration {
background-color: #6E5DDB;
padding: 1rem 2rem;
font-family: 'Poppins', sans-serif;
font-size: calc(18rem / 16);
border-radius: .25rem;
border: 0;
color: #fff;
display: inline-flex;
align-items: center;
margin-bottom: 2rem;
&:hover,
&:active,
&:focus {
background-color: #6E5DDB;
color: #fff;
}
svg {
width: 1.5rem;
height: auto;
}
}

View File

@ -0,0 +1,6 @@
<svg id="Group_42321" data-name="Group 42321" xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 30 30">
<g id="Group_15874" data-name="Group 15874">
<path id="Path_10381" data-name="Path 10381" d="M15,0A15,15,0,1,1,0,15,15,15,0,0,1,15,0Z" fill="#f8f8f8"/>
<path id="close" d="M10.557.6l-.6-.6L5.278,4.675.6,0,0,.6,4.675,5.278,0,9.953l.6.6L5.278,5.882l4.675,4.675.6-.6L5.882,5.278Z" transform="translate(9.5 9.5)" fill="#c7c7c7" stroke="#c7c7c7" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.7"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 570 B

View File

@ -0,0 +1,12 @@
<svg id="add_5_" data-name="add (5)" xmlns="http://www.w3.org/2000/svg" width="19.96" height="19.96" viewBox="0 0 19.96 19.96">
<g id="Group_16519" data-name="Group 16519">
<g id="Group_16518" data-name="Group 16518">
<path id="Path_10382" data-name="Path 10382" d="M9.98,0a9.98,9.98,0,1,0,9.98,9.98A9.991,9.991,0,0,0,9.98,0Zm0,18.414A8.434,8.434,0,1,1,18.414,9.98,8.444,8.444,0,0,1,9.98,18.414Z" fill="#fff"/>
</g>
</g>
<g id="Group_16521" data-name="Group 16521" transform="translate(5.342 5.272)">
<g id="Group_16520" data-name="Group 16520">
<path id="Path_10383" data-name="Path 10383" d="M145.526,139.1h-3.092v-3.092a.773.773,0,0,0-1.546,0V139.1H137.8a.773.773,0,0,0,0,1.546h3.092v3.092a.773.773,0,0,0,1.546,0v-3.092h3.092a.773.773,0,1,0,0-1.546Z" transform="translate(-137.022 -135.238)" fill="#fff"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 898 B

View File

@ -3,8 +3,6 @@ function showLoader() {
} }
var filter = {}; var filter = {};
// TODO will be unified // TODO will be unified
@ -265,4 +263,34 @@ $(document).ready(function () {
return true; return true;
}) })
$('#configurationForm').submit(function (e) {
e.preventDefault();
crudAjax($(this).serialize(), '/advs/configuration/ajax/create', 'POST', function (callback) {
$('.configuration-table').append(`<tr id="configuration-${callback.id}">
<td>${callback.option_name}</td>
<td>${callback.stock}</td>
<td>${callback.currency_price}</td>
<td class="text-right">
<a href="javascript:void(0)" class="btn btn-sm remove-conf" data-id="${callback.id}"><svg id="Group_42321" data-name="Group 42321" xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 30 30">
<g id="Group_15874" data-name="Group 15874">
<path id="Path_10381" data-name="Path 10381" d="M15,0A15,15,0,1,1,0,15,15,15,0,0,1,15,0Z" fill="#f8f8f8"></path>
<path id="close" d="M10.557.6l-.6-.6L5.278,4.675.6,0,0,.6,4.675,5.278,0,9.953l.6.6L5.278,5.882l4.675,4.675.6-.6L5.882,5.278Z" transform="translate(9.5 9.5)" fill="#c7c7c7" stroke="#c7c7c7" stroke-linecap="round" stroke-linejoin="round" stroke-width="0.7"></path>
</g>
</svg>
</a>
</td>
</tr>`);
$('#configurationForm').trigger("reset");
})
});
$(document).on('click', '.remove-conf', function () {
const id = $(this).data('id');
crudAjax({id: id}, '/advs/configuration/ajax/delete', 'POST', function (callback) {
$('#configuration-' + id).remove();
})
});
}); });

View File

@ -1,6 +1,7 @@
<?php <?php
return [ return [
'add' => 'Add',
'new_adv' => 'New classified', 'new_adv' => 'New classified',
'new_classified' => 'New classified', 'new_classified' => 'New classified',
'new_category' => 'New Category', 'new_category' => 'New Category',

View File

@ -1,6 +1,7 @@
<?php <?php
return [ return [
'add' => 'Ekle',
'new_adv' => 'Yeni ürün/ilan', 'new_adv' => 'Yeni ürün/ilan',
'new_classified' => 'Yeni ürün/ilan', 'new_classified' => 'Yeni ürün/ilan',
'new_category' => 'Yeni kategori', 'new_category' => 'Yeni kategori',
@ -33,6 +34,7 @@ return [
'name' => 'Kategori Güncelle' 'name' => 'Kategori Güncelle'
], ],
'new_option' => 'Yeni Seçenek', 'new_option' => 'Yeni Seçenek',
'options' => 'Seçenekler',
'export' => 'Dışa aktar', 'export' => 'Dışa aktar',
'new_productoption' => 'Yeni Üretim', 'new_productoption' => 'Yeni Üretim',
'new_productoptions_value' => 'Yeni Ürün seçeneği değeri', 'new_productoptions_value' => 'Yeni Ürün seçeneği değeri',

View File

@ -225,7 +225,11 @@
{{ trans('visiosoft.module.advs::field.product_option.name') }} {{ trans('visiosoft.module.advs::field.product_option.name') }}
</label> </label>
<div class="mt-3 form-group mb-0"> <div class="mt-3 form-group mb-0">
{{ form.fields.product_options_value.configSet('cat1', adv.cat1).input|raw }} <button type="button" class="btn btn-primary btn-configuration" data-toggle="modal" data-target="#configurationModal">
{{ img('visiosoft.module.advs::images/create/plus.svg').data|raw }}
&nbsp;
{{ trans('visiosoft.module.advs::button.new_options_configuration') }}
</button>
</div> </div>
</div> </div>
{% endif %} {% endif %}
@ -316,6 +320,7 @@
</div> </div>
</section> </section>
{% include "visiosoft.module.advs::new-ad/partials/modals" %} {% include "visiosoft.module.advs::new-ad/partials/modals" %}
{% include "visiosoft.module.advs::new-ad/partials/configuration-modal" %}
{{ addBlock('new-ad/modals')|raw }} {{ addBlock('new-ad/modals')|raw }}
<script> <script>
var default_country = "{{ setting_value('visiosoft.module.location::default_country') }}"; var default_country = "{{ setting_value('visiosoft.module.location::default_country') }}";

View File

@ -0,0 +1,52 @@
<div class="modal fade" id="configurationModal" tabindex="-1" role="dialog" aria-labelledby="configurationModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content rounded-0">
<div class="modal-header border-0">
<h5 class="modal-title" id="configurationModalLabel">
{{ trans('visiosoft.module.advs::stream.product_options.name') }}
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="">
{% set configurationForm = form('configuration_form').entry(adv.id).get() %}
{{ form_open({id: 'configurationForm',class: 'd-flex justify-content-between'})|raw }}
<input type="text" name="parent_adv_id" value="{{ adv.id }}" hidden>
{{ configurationForm.fields|raw }}
<button type="submit" class="btn btn-primary btn-configuration my-auto form-control w-auto">
{{ trans('visiosoft.module.advs::button.add') }}
</button>
{{ form_close() }}
</div>
<table class="table">
<thead>
<tr>
<th scope="col">{{ trans('visiosoft.module.advs::field.options') }}</th>
<th scope="col">{{ trans('visiosoft.module.advs::field.stock.name') }}</th>
<th scope="col">{{ trans('visiosoft.module.advs::field.price.name') }}</th>
<th scope=""></th>
</tr>
</thead>
<tbody class="configuration-table">
{% for key, configuration in configurations %}
<tr id="configuration-{{ key }}">
<td>{{ configuration.name }}</td>
<td>{{ configuration.stock }}</td>
<td>{{ currency_format(configuration.price,configuration.currency) }}</td>
<td class="text-right">
<a href="javascript:void(0)" class="btn btn-sm remove-conf"
data-id="{{ key }}">{{ img('visiosoft.module.advs::images/create/close.svg').data|raw }}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>

View File

@ -24,14 +24,6 @@
{% else %} {% else %}
{% set continueLink = url_route('adv_detail_seo', [adv.slug, adv.id]) %} {% set continueLink = url_route('adv_detail_seo', [adv.slug, adv.id]) %}
{% endif %} {% endif %}
{% if not setting_value('visiosoft.module.advs::hide_configurations') %}
{% if setting_value('visiosoft.module.advs::detailed_product_options') %}
<a href="{{ route('visiosoft.module.advs::user.configrations.create') }}?ad={{ adv.id }}"
class="btn btn-warning shadow-sm mr-4 text-white">
{{ trans('visiosoft.module.advs::button.create_configurations') }}
</a>
{% endif %}
{% endif %}
<a href="{{ url_route('visiosoft.module.advs::edit_adv', [adv.id]) }}" <a href="{{ url_route('visiosoft.module.advs::edit_adv', [adv.id]) }}"
class="btn preview-edit shadow-sm border"> class="btn preview-edit shadow-sm border">
{{ trans('visiosoft.module.advs::field.edit') }} {{ trans('visiosoft.module.advs::field.edit') }}
@ -45,12 +37,6 @@
<div class="preview-overlay position-absolute"></div> <div class="preview-overlay position-absolute"></div>
</div> </div>
<div class="preview-actions text-center"> <div class="preview-actions text-center">
{% if not setting_value('visiosoft.module.advs::hide_configurations') %}
<a href="{{ route('visiosoft.module.advs::user.configrations.create') }}?ad={{ adv.id }}"
class="btn btn-warning shadow-sm mr-4 text-white">
{{ trans('visiosoft.module.advs::button.create_configurations') }}
</a>
{% endif %}
<a href="{{ url_route('visiosoft.module.advs::edit_adv', [adv.id]) }}" <a href="{{ url_route('visiosoft.module.advs::edit_adv', [adv.id]) }}"
class="btn preview-edit shadow-sm border"> class="btn preview-edit shadow-sm border">
{{ trans('visiosoft.module.advs::field.edit') }} {{ trans('visiosoft.module.advs::field.edit') }}

View File

@ -20,6 +20,6 @@ class IsOptionsByCategory
$options_id = $option_repository->getWithCategoryId($this->cat_id)->pluck('id')->all(); $options_id = $option_repository->getWithCategoryId($this->cat_id)->pluck('id')->all();
return count($value_repository->getWithOptionsId($options_id)); return $value_repository->getWithOptionsId($options_id);
} }
} }

View File

@ -19,6 +19,7 @@ use Visiosoft\AdvsModule\Listener\AddTotalSales;
use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface; use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface;
use Visiosoft\AdvsModule\Option\OptionRepository; use Visiosoft\AdvsModule\Option\OptionRepository;
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface; use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\Form\OptionConfigurationFormBuilder;
use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationRepository; use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationRepository;
use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface; use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface;
use Visiosoft\AdvsModule\Productoption\ProductoptionRepository; use Visiosoft\AdvsModule\Productoption\ProductoptionRepository;
@ -217,6 +218,10 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
'as' => 'visiosoft.module.advs::user.configrations.create', 'as' => 'visiosoft.module.advs::user.configrations.create',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@create', 'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@create',
], ],
'advs/configuration/ajax/create' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@ajaxCreate',
'advs/configuration/ajax/delete' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@ajaxDelete',
'conf/addCart' => [ 'conf/addCart' => [
'as' => 'configuration::add_cart', 'as' => 'configuration::add_cart',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@confAddCart', 'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@confAddCart',
@ -257,6 +262,7 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
AdvsAdvsEntryModel::class => AdvModel::class, AdvsAdvsEntryModel::class => AdvModel::class,
AdvsStatusEntryModel::class => StatusModel::class, AdvsStatusEntryModel::class => StatusModel::class,
'my_form' => AdvFormBuilder::class, 'my_form' => AdvFormBuilder::class,
'configuration_form' => OptionConfigurationFormBuilder::class,
]; ];
protected $singletons = [ protected $singletons = [

View File

@ -784,7 +784,7 @@ class AdvsController extends PublicController
$is_new_create = ($adv->slug == "") ? true : false; $is_new_create = ($adv->slug == "") ? true : false;
//Set Old Price //Set Old Price
$old_price = ($adv->slug == "") ? $this->request->price : $adv->price; $old_price = $is_new_create ? $this->request->price : $adv->price;
$adv->old_price = $old_price; $adv->old_price = $old_price;
@ -999,10 +999,11 @@ class AdvsController extends PublicController
* Added to query if there are product options. * Added to query if there are product options.
*/ */
$is_options = dispatch_now(new IsOptionsByCategory($adv['cat1'])); $is_options = dispatch_now(new IsOptionsByCategory($adv['cat1']));
$configurations = app(OptionConfigurationRepositoryInterface::class)->getConf($adv['id']);
return $this->view->make( return $this->view->make(
'visiosoft.module.advs::new-ad/new-create', 'visiosoft.module.advs::new-ad/new-create',
compact('id', 'cats_d', 'cats', 'adv', 'custom_fields', 'options', 'hidePrice','is_options') compact('id', 'cats_d', 'cats', 'adv', 'custom_fields', 'options', 'hidePrice','is_options', 'configurations')
); );
} }
@ -1191,4 +1192,4 @@ class AdvsController extends PublicController
$response['maxQuantity'] = $adv->stock; $response['maxQuantity'] = $adv->stock;
return $response; return $response;
} }
} }

View File

@ -4,6 +4,7 @@ use Anomaly\Streams\Platform\Http\Controller\PublicController;
use Visiosoft\AdvsModule\Adv\AdvModel; use Visiosoft\AdvsModule\Adv\AdvModel;
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface; use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\Form\OptionConfigurationFormBuilder; use Visiosoft\AdvsModule\OptionConfiguration\Form\OptionConfigurationFormBuilder;
use Visiosoft\AdvsModule\Support\Command\Currency;
use Visiosoft\CartsModule\Cart\CartRepository; use Visiosoft\CartsModule\Cart\CartRepository;
use Visiosoft\CartsModule\Cart\Command\GetCart; use Visiosoft\CartsModule\Cart\Command\GetCart;
@ -31,6 +32,30 @@ class OptionConfigurationController extends PublicController
return $form->render(); return $form->render();
} }
public function ajaxCreate(OptionConfigurationRepositoryInterface $optionConfigurationRepository){
$parameters = $this->request->all();
$option_json = array();
foreach ($parameters as $key => $parameter_value) {
if ((strpos($key, "option-") === 0)) {
if ($parameter_value !== '') {
$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 = $optionConfigurationRepository->create($configration);
$entry['currency_price'] = app(Currency::class)->format($entry->price, $entry->currency);
return $this->response->json($entry);
}
public function ajaxDelete(OptionConfigurationRepositoryInterface $optionConfigurationRepository){
return $optionConfigurationRepository->deleteConfig($this->request->id);
}
public function confAddCart() public function confAddCart()
{ {
if ($conf = $this->optionConfigurationRepository->find($this->request->configuration)) { if ($conf = $this->optionConfigurationRepository->find($this->request->configuration)) {

View File

@ -13,4 +13,6 @@ interface OptionConfigurationRepositoryInterface extends EntryRepositoryInterfac
public function deleteUnusedConfigs($adsIDs); public function deleteUnusedConfigs($adsIDs);
public function deleteAdsConfigs($adID); public function deleteAdsConfigs($adID);
public function deleteConfig($id);
} }

View File

@ -4,4 +4,7 @@ use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
class OptionConfigurationFormBuilder extends FormBuilder class OptionConfigurationFormBuilder extends FormBuilder
{ {
protected $actions = [
'save',
];
} }

View File

@ -2,32 +2,34 @@
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface; use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface;
use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueRepositoryInterface;
class OptionConfigurationFormFields class OptionConfigurationFormFields
{ {
public function handle( public function handle(
OptionConfigurationFormBuilder $builder, OptionConfigurationFormBuilder $builder,
AdvRepositoryInterface $advRepository, AdvRepositoryInterface $advRepository,
ProductoptionRepositoryInterface $productOptionRepository) ProductoptionRepositoryInterface $productOptionRepository,
ProductoptionsValueRepositoryInterface $productoptionsValueRepository
)
{ {
if(request()->has('ad')) if(request()->has('ad') || $builder->getEntry())
{ {
$ad = $advRepository->find(request('ad')); $ad = $advRepository->find(request('ad') ?? $builder->getEntry());
$options = $productOptionRepository->getWithCategoryId($ad->cat1);
$options = $ad->getProductOptionsValues()->groupBy('product_option_id');
$options_fields = array(); $options_fields = array();
foreach ($options as $option_id => $option_values) foreach ($options as $option)
{ {
if($option = $productOptionRepository->find($option_id)) if($optionValue = $productoptionsValueRepository->getWithOptionsId([$option->id]))
{ {
$options_fields['option-'.$option->getId()] = [ $options_fields['option-'.$option->getId()] = [
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
'label' => $option->getName(), 'label' => $option->getName(),
'required' => true, 'required' => true,
'config' => [ 'config' => [
'options' => $option_values->pluck('name','id')->all(), 'options' => $optionValue->pluck('name','id')->all(),
] ]
]; ];
} }

View File

@ -1,6 +1,5 @@
<?php namespace Visiosoft\AdvsModule\OptionConfiguration; <?php namespace Visiosoft\AdvsModule\OptionConfiguration;
use Anomaly\Streams\Platform\Model\Configuration\ConfigurationConfigurationEntryModel;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface; use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository; use Anomaly\Streams\Platform\Entry\EntryRepository;
@ -93,4 +92,8 @@ class OptionConfigurationRepository extends EntryRepository implements OptionCon
{ {
return $this->newQuery()->where('parent_adv_id', $adID)->delete(); return $this->newQuery()->where('parent_adv_id', $adID)->delete();
} }
public function deleteConfig($id){
return $this->newQuery()->find($id)->delete();
}
} }