mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
#4946 Options value editing
This commit is contained in:
parent
ec8e384410
commit
15286608e1
@ -263,6 +263,15 @@ label {
|
||||
}
|
||||
}
|
||||
|
||||
.swal2-title {
|
||||
max-width: 100% !important;
|
||||
}
|
||||
|
||||
#configurationModal .form-group {
|
||||
flex: 1 1 auto!important;
|
||||
margin: 0 1rem 1rem 1rem;
|
||||
}
|
||||
|
||||
.btn-configuration {
|
||||
background-color: #6E5DDB;
|
||||
padding: 1rem 2rem;
|
||||
|
||||
@ -181,6 +181,33 @@ $(document).ready(function () {
|
||||
});
|
||||
});
|
||||
|
||||
let option_id = 0;
|
||||
let option_value = '';
|
||||
function createOptionValue() {
|
||||
Swal.fire({
|
||||
title: save_the_option,
|
||||
text: option_value,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: new_button,
|
||||
}).then(result => {
|
||||
if (result.isConfirmed) {
|
||||
crudAjax({
|
||||
option: option_id,
|
||||
name: option_value
|
||||
}, '/api/classified/configuration/createOptions', 'POST', function (callback) {
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: option_saved,
|
||||
text: callback.name,
|
||||
showConfirmButton: false,
|
||||
timer: 1500
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
$(".priceField, .standard-price-field").inputmask('currency', {
|
||||
rightAlign: true,
|
||||
@ -231,6 +258,36 @@ $(document).ready(function () {
|
||||
tokenSeparators: [',']
|
||||
});
|
||||
|
||||
$('.product-options-fields').select2({
|
||||
width: '100%',
|
||||
dropdownAutoWidth : true,
|
||||
allowClear: false,
|
||||
ajax: {
|
||||
url: "/api/classified/configuration/getOptions",
|
||||
data: function (params) {
|
||||
option_value = params.term;
|
||||
return {
|
||||
q: params.term,
|
||||
option: option_id,
|
||||
};
|
||||
},
|
||||
processResults: function (data) {
|
||||
return {
|
||||
results: $.map(data, (item) => {
|
||||
return {id: item.id, text: item.name}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return $(`<button class='btn btn-primary btn-configuration text-nowrap my-auto form-control w-100 justify-content-center' onclick='createOptionValue()'>${new_button}</button>`);
|
||||
}
|
||||
}
|
||||
}).on('select2:open', function (e) {
|
||||
option_id = $(e.target).data('id');
|
||||
});
|
||||
|
||||
let deletedOptions = [];
|
||||
$('#selectOptions').on('select2:unselect', function (e) {
|
||||
if (e.params.data.element.id) {
|
||||
@ -266,7 +323,7 @@ $(document).ready(function () {
|
||||
|
||||
$('#configurationForm').submit(function (e) {
|
||||
e.preventDefault();
|
||||
crudAjax($(this).serialize(), '/advs/configuration/ajax/create', 'POST', function (callback) {
|
||||
crudAjax($(this).serialize(), '/classified/configuration/ajax/create', 'POST', function (callback) {
|
||||
$('.configuration-table').append(`<tr id="configuration-${callback.id}">
|
||||
<td>${callback.option_name}</td>
|
||||
<td>${callback.stock}</td>
|
||||
@ -288,7 +345,7 @@ $(document).ready(function () {
|
||||
$(document).on('click', '.remove-conf', function () {
|
||||
const id = $(this).data('id');
|
||||
|
||||
crudAjax({id: id}, '/advs/configuration/ajax/delete', 'POST', function (callback) {
|
||||
crudAjax({id: id}, '/classified/configuration/ajax/delete', 'POST', function (callback) {
|
||||
$('#configuration-' + id).remove();
|
||||
})
|
||||
});
|
||||
|
||||
@ -35,7 +35,7 @@ return [
|
||||
],
|
||||
'new_option' => 'New Option',
|
||||
'export' => 'Export',
|
||||
'new_productoption' => 'New Productoption',
|
||||
'new_productoption' => 'New Product Option',
|
||||
'new_productoptions_value' => 'New Product option value',
|
||||
'new_options_configuration' => 'New Option configuration',
|
||||
'new_option_configuration' => 'New Option configuration',
|
||||
|
||||
@ -34,4 +34,6 @@ return [
|
||||
'disabled_detailed_options_for_admin_role' => "Detailed product options are disabled.",
|
||||
'permission_error' => 'You do not have permission for this action',
|
||||
'currency_converter_not_available' => 'The currency converter is not available.',
|
||||
'option_saved' => 'Option Saved',
|
||||
'do_you_want_to_save_the_option' => 'Do you want to save the option?',
|
||||
];
|
||||
|
||||
@ -50,3 +50,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let new_button = "{{ trans('visiosoft.module.advs::button.new_productoption') }}",
|
||||
option_saved = "{{ trans('visiosoft.module.advs::message.option_saved') }}",
|
||||
save_the_option = "{{ trans('visiosoft.module.advs::message.do_you_want_to_save_the_option') }}";
|
||||
</script>
|
||||
|
||||
@ -224,15 +224,22 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
|
||||
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@create',
|
||||
],
|
||||
|
||||
'advs/configuration/ajax/create' => [
|
||||
'classified/configuration/ajax/create' => [
|
||||
'middleware' => 'auth',
|
||||
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@ajaxCreate'
|
||||
],
|
||||
'advs/configuration/ajax/delete' => [
|
||||
'classified/configuration/ajax/delete' => [
|
||||
'middleware' => 'auth',
|
||||
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@ajaxDelete'
|
||||
],
|
||||
|
||||
'api/classified/configuration/getOptions' => [
|
||||
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@ajaxGetOptions',
|
||||
],
|
||||
'api/classified/configuration/createOptions' => [
|
||||
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@ajaxCreateOptions',
|
||||
],
|
||||
|
||||
'conf/addCart' => [
|
||||
'as' => 'configuration::add_cart',
|
||||
'uses' => 'Visiosoft\AdvsModule\Http\Controller\OptionConfigurationController@confAddCart',
|
||||
|
||||
@ -4,6 +4,8 @@ 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\Productoption\Contract\ProductoptionRepositoryInterface;
|
||||
use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueRepositoryInterface;
|
||||
use Visiosoft\AdvsModule\Support\Command\Currency;
|
||||
use Visiosoft\CartsModule\Cart\CartRepository;
|
||||
use Visiosoft\CartsModule\Cart\Command\GetCart;
|
||||
@ -13,16 +15,22 @@ class OptionConfigurationController extends PublicController
|
||||
private $adv_model;
|
||||
private $optionConfigurationRepository;
|
||||
private $cartRepository;
|
||||
private $productoptionRepository;
|
||||
private $productoptionsValueRepository;
|
||||
|
||||
public function __construct(
|
||||
AdvModel $advModel,
|
||||
OptionConfigurationRepositoryInterface $optionConfigurationRepository,
|
||||
CartRepository $cartRepository
|
||||
CartRepository $cartRepository,
|
||||
ProductoptionRepositoryInterface $productoptionRepository,
|
||||
ProductoptionsValueRepositoryInterface $productoptionsValueRepository
|
||||
)
|
||||
{
|
||||
$this->adv_model = $advModel;
|
||||
$this->optionConfigurationRepository = $optionConfigurationRepository;
|
||||
$this->cartRepository = $cartRepository;
|
||||
$this->productoptionRepository = $productoptionRepository;
|
||||
$this->productoptionsValueRepository = $productoptionsValueRepository;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@ -75,6 +83,21 @@ class OptionConfigurationController extends PublicController
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxGetOptions() {
|
||||
$option = $this->productoptionRepository->find($this->request->option);
|
||||
return $this->productoptionsValueRepository->searchByOption($option->id, $this->request->q);
|
||||
}
|
||||
|
||||
public function ajaxCreateOptions()
|
||||
{
|
||||
$option = $this->productoptionRepository->find($this->request->option);
|
||||
|
||||
return $this->productoptionsValueRepository->create([
|
||||
'product_option' => $option,
|
||||
'name' => $this->request->name
|
||||
]);
|
||||
}
|
||||
|
||||
public function ajaxConfAddCart()
|
||||
{
|
||||
if ($conf = $this->optionConfigurationRepository->find($this->request->configuration ?? $this->request->data['conf'])) {
|
||||
|
||||
@ -29,8 +29,12 @@ class OptionConfigurationFormFields
|
||||
{
|
||||
$options_fields['option-'.$option->getId()] = [
|
||||
'type' => 'anomaly.field_type.select',
|
||||
'class' => 'form-control product-options-fields',
|
||||
'label' => $option->getName(),
|
||||
'required' => true,
|
||||
'attributes' => [
|
||||
'data-id' => $option->getId(),
|
||||
],
|
||||
'config' => [
|
||||
'options' => $optionValue->pluck('title','id')->all(),
|
||||
]
|
||||
|
||||
@ -5,4 +5,5 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
|
||||
interface ProductoptionsValueRepositoryInterface extends EntryRepositoryInterface
|
||||
{
|
||||
public function getWithOptionsId(array $ids);
|
||||
public function searchByOption($option, $value);
|
||||
}
|
||||
|
||||
@ -23,8 +23,15 @@ class ProductoptionsValueRepository extends EntryRepository implements Productop
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function getWithOptionsId(array $ids)
|
||||
{
|
||||
return $this->newQuery()->whereIn('product_option_id', $ids)->get();
|
||||
}
|
||||
public function getWithOptionsId(array $ids)
|
||||
{
|
||||
return $this->newQuery()->whereIn('product_option_id', $ids)->get();
|
||||
}
|
||||
|
||||
public function searchByOption($option, $value)
|
||||
{
|
||||
return $this->newQuery()->where('product_option_id', $option)
|
||||
->where('name', 'like', '%' . $value . '%')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user