This commit is contained in:
Diatrex 2020-06-09 16:37:26 +03:00
commit c7a9624fdd
17 changed files with 178 additions and 12 deletions

View File

@ -250,5 +250,13 @@ class VisiosoftModuleAdvsCreateAdvsFields extends Migration
'default_value' => 0,
]
],
// Options Fields
"adv" => [
"type" => "anomaly.field_type.relationship",
"config" => [
"related" => AdvModel::class,
]
]
];
}

View File

@ -0,0 +1,45 @@
<?php
use Anomaly\Streams\Platform\Database\Migration\Migration;
class VisiosoftModuleAdvsCreateOptionsStream extends Migration
{
/**
* This migration creates the stream.
* It should be deleted on rollback.
*
* @var bool
*/
protected $delete = true;
/**
* The stream definition.
*
* @var array
*/
protected $stream = [
'slug' => '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,
],
];
}

View File

@ -16,4 +16,9 @@ return [
'write',
'delete',
],
'options' => [
'read',
'write',
'delete',
],
];

View File

@ -215,5 +215,44 @@ $(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,
tokenSeparators: [',']
});
let deletedOptions = [];
$('#selectOptions').on('select2:unselect', function (e) {
if (e.params.data.element.id) {
const id = e.params.data.element.id.substr(9);
deletedOptions.push(id);
} else {
let index = newOptions.indexOf(e.params.data.text);
if (index > -1) {
newOptions.splice(index, 1);
}
}
});
let newOptions = [];
$('#selectOptions').on('select2:select', function (e) {
if (e.params.data.element) {
let index = deletedOptions.indexOf(e.params.data.element.id.substr(9));
if (index > -1) {
deletedOptions.splice(index, 1);
}
} else {
newOptions.push(e.params.data.text)
}
});
$('#createEditAdvForm').submit(function () {
$(this).append(`<input type="hidden" name="deleted_options" value="${deletedOptions}" />`);
$(this).append(`<input type="hidden" name="new_options" value="${newOptions}" />`);
return true;
})
});

View File

@ -31,4 +31,5 @@ return [
'update_category' => [
'name' => 'Update Category'
],
'new_option' => 'New Option',
];

View File

@ -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?',
],
],
];

View File

@ -40,4 +40,7 @@ return [
'general' => 'General',
'ads' => 'Ads',
'user' => 'User',
'options' => [
'title' => 'Options',
],
];

View File

@ -19,4 +19,7 @@ return [
'cf_values' => [
'name' => 'Cf values',
],
'options' => [
'name' => 'Options',
],
];

View File

@ -127,7 +127,7 @@ return [
'sort' => 'Tipi',
'sort_by' => 'Rendit Sipas',
'pick_option' => 'Zgjidh një mundësi',
'pick_ordering' => 'Merr Porosin',
'pick_ordering' => 'Renditje',
'price_high' => 'Cmimi i larte deri tek i uleti',
'price_low' => 'Cmimi i ulet deri tek i larte',
'newest' => 'Më të Rejat',

View File

@ -34,7 +34,7 @@
</div>
<!-- Detail With Block -->
{{ addBlock('ad-detail/details',{'adv':adv})|raw }}
{{ addBlock('ad-detail/details',{'adv':adv, 'options':options})|raw }}
{{ addBlock('ad-detail/widget-details',{'adv':adv})|raw }}
<!-- Detail With Block -->

View File

@ -20,6 +20,7 @@
<div class="col-md-12">
{% 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 @@
</div>
</div>
<div class="row form-group select-options">
<label for="selectOptions" class="col-sm-2">
Options
</label>
<div class="col-sm-10">
<select id="selectOptions" class="form-control options-tags" multiple="multiple"
name="options[]">
{% if count(options) %}
{% for option in options %}
<option id="advOption{{ option.id }}" selected="selected">{{ option.name }}</option>
{% endfor %}
{% endif %}
</select>
</div>
</div>
<div class="row form-group brand-name">
<div class="col-md-12">
<div class="field-group advs_desc">

View File

@ -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());
}

View File

@ -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,
];
/**

View File

@ -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,26 @@ class AdvsController extends PublicController
}
}
// Create options
$deletedOptions = $request->deleted_options;
$newOptions = $request->new_options;
if (!empty($deletedOptions)) {
$deletedOptions = explode(',', $request->deleted_options);
$this->optionRepository->newQuery()
->whereIn('id', $deletedOptions)
->where('adv_id', $request->update_id)
->delete();
}
if (!empty($newOptions)) {
$newOptions = explode(',', $request->new_options);
foreach ($newOptions as $option) {
$this->optionRepository->create([
'name' => $option,
'adv_id' => $request->update_id,
]);
}
}
$adv->is_get_adv = $request->is_get_adv;
$adv->save();
@ -685,6 +716,8 @@ class AdvsController extends PublicController
}
}
$options = $this->optionRepository->findAllBy('adv_id', $id);
//Cloudinary Module
$isActiveCloudinary = new AdvModel();
$isActiveCloudinary = $isActiveCloudinary->is_enabled('cloudinary');
@ -705,7 +738,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 +997,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";

View File

@ -154,7 +154,7 @@ class CategoryController extends AdminController
}
return $this->view->make('visiosoft.module.cats::cats/admin-cat', compact('formBuilder'));
return $this->view->make('visiosoft.module.cats::cats/admin-cat');
}
public function endsWith($string, $test) {

View File

@ -47,7 +47,7 @@ class ValueTableBuilder extends TableBuilder
protected $buttons = [
'view' => [
'target' => '_blank',
'href' => 'admin/files/view/{entry.id}',
'href' => '/files/{entry.path}',
],
'remove' => [
'data-dismiss' => 'file',

View File

@ -77,7 +77,7 @@ return [
'separator' => ',',
'point' => '.',
'decimals' => 2,
'symbol' => 'L',
'symbol' => 'Leke',
],
'AMD' => [
'name' => 'Armenian Dram',