Merge pull request #1131 from openclassify/muammertop

#4061 ads configration improvments
This commit is contained in:
spektra2147 2021-08-03 13:36:53 +03:00 committed by GitHub
commit 47dcf6133a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 204 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 = {};
// TODO will be unified
@ -265,4 +263,34 @@ $(document).ready(function () {
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
return [
'add' => 'Add',
'new_adv' => 'New classified',
'new_classified' => 'New classified',
'new_category' => 'New Category',

View File

@ -1,6 +1,7 @@
<?php
return [
'add' => 'Ekle',
'new_adv' => 'Yeni ürün/ilan',
'new_classified' => 'Yeni ürün/ilan',
'new_category' => 'Yeni kategori',
@ -33,6 +34,7 @@ return [
'name' => 'Kategori Güncelle'
],
'new_option' => 'Yeni Seçenek',
'options' => 'Seçenekler',
'export' => 'Dışa aktar',
'new_productoption' => 'Yeni Üretim',
'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') }}
</label>
<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>
{% endif %}
@ -316,6 +320,7 @@
</div>
</section>
{% include "visiosoft.module.advs::new-ad/partials/modals" %}
{% include "visiosoft.module.advs::new-ad/partials/configuration-modal" %}
{{ addBlock('new-ad/modals')|raw }}
<script>
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 %}
{% set continueLink = url_route('adv_detail_seo', [adv.slug, adv.id]) %}
{% 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]) }}"
class="btn preview-edit shadow-sm border">
{{ trans('visiosoft.module.advs::field.edit') }}
@ -45,12 +37,6 @@
<div class="preview-overlay position-absolute"></div>
</div>
<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]) }}"
class="btn preview-edit shadow-sm border">
{{ 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();
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\OptionRepository;
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\Form\OptionConfigurationFormBuilder;
use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationRepository;
use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface;
use Visiosoft\AdvsModule\Productoption\ProductoptionRepository;
@ -217,6 +218,16 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
'as' => 'visiosoft.module.advs::user.configrations.create',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@create',
],
'advs/configuration/ajax/create' => [
'middleware' => 'auth',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@ajaxCreate'
],
'advs/configuration/ajax/delete' => [
'middleware' => 'auth',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@ajaxDelete'
],
'conf/addCart' => [
'as' => 'configuration::add_cart',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@confAddCart',
@ -257,6 +268,7 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
AdvsAdvsEntryModel::class => AdvModel::class,
AdvsStatusEntryModel::class => StatusModel::class,
'my_form' => AdvFormBuilder::class,
'configuration_form' => OptionConfigurationFormBuilder::class,
];
protected $singletons = [

View File

@ -792,7 +792,7 @@ class AdvsController extends PublicController
$is_new_create = ($adv->slug == "") ? true : false;
//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;
@ -1007,10 +1007,11 @@ class AdvsController extends PublicController
* Added to query if there are product options.
*/
$is_options = dispatch_now(new IsOptionsByCategory($adv['cat1']));
$configurations = app(OptionConfigurationRepositoryInterface::class)->getConf($adv['id']);
return $this->view->make(
'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')
);
}
@ -1208,4 +1209,4 @@ class AdvsController extends PublicController
$response['maxQuantity'] = $adv->stock;
return $response;
}
}
}

View File

@ -4,6 +4,7 @@ use Anomaly\Streams\Platform\Http\Controller\PublicController;
use Visiosoft\AdvsModule\Adv\AdvModel;
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\Form\OptionConfigurationFormBuilder;
use Visiosoft\AdvsModule\Support\Command\Currency;
use Visiosoft\CartsModule\Cart\CartRepository;
use Visiosoft\CartsModule\Cart\Command\GetCart;
@ -31,6 +32,30 @@ class OptionConfigurationController extends PublicController
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()
{
if ($conf = $this->optionConfigurationRepository->find($this->request->configuration)) {

View File

@ -13,4 +13,6 @@ interface OptionConfigurationRepositoryInterface extends EntryRepositoryInterfac
public function deleteUnusedConfigs($adsIDs);
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
{
protected $actions = [
'save',
];
}

View File

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

View File

@ -1,6 +1,6 @@
<?php namespace Visiosoft\AdvsModule\OptionConfiguration;
use Anomaly\Streams\Platform\Model\Configuration\ConfigurationConfigurationEntryModel;
use Illuminate\Support\Facades\Auth;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository;
@ -93,4 +93,15 @@ class OptionConfigurationRepository extends EntryRepository implements OptionCon
{
return $this->newQuery()->where('parent_adv_id', $adID)->delete();
}
public function deleteConfig($id)
{
if ($conf = ($this->newQuery()->find($id))) {
if ($conf->created_by_id === Auth::user()->getAuthIdentifier()) {
return $conf->delete();
}
return response()->json(['status' => 'error'], 403);
}
return response()->json(['status' => 'error'], 404);
}
}