Fixes on attributes on prices
This commit is contained in:
@@ -29,6 +29,8 @@ class ArticleController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
|
// dump($data);
|
||||||
|
// exit;
|
||||||
Articles::storeFull($data);
|
Articles::storeFull($data);
|
||||||
return redirect()->route('Shop.Admin.Articles.index');
|
return redirect()->route('Shop.Admin.Articles.index');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class ArticleAttribute extends Model
|
class ArticleAttribute extends Model
|
||||||
{
|
{
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
protected $table = 'shop_article_attribute_attributes';
|
protected $table = 'shop_article_attributes';
|
||||||
|
|
||||||
public function Price()
|
public function Price()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Models\Shop\ArticlePrice');
|
return $this->belongsTo('App\Models\Shop\ArticlePrice','article_price_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Value()
|
public function Value()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Models\Shop\ArticleAttribute');
|
return $this->belongsTo('App\Models\Shop\ArticleAttributeValue','attribute_value_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeByPrice($query, $article_price_id)
|
public function scopeByPrice($query, $article_price_id)
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ use App\Models\Shop\ArticlePrice;
|
|||||||
class ArticlePrices
|
class ArticlePrices
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static function getPricesByArticle($id)
|
||||||
|
{
|
||||||
|
return ArticlePrice::with('ArticleAttributes.Value')->byArticle($id)->get()->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
public static function getDatatable()
|
public static function getDatatable()
|
||||||
{
|
{
|
||||||
$model = ArticlePrice::orderBy('name');
|
$model = ArticlePrice::orderBy('name');
|
||||||
@@ -65,9 +70,12 @@ class ArticlePrices
|
|||||||
return ArticlePrice::create($data);
|
return ArticlePrice::create($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function update($data)
|
public static function update($data, $id = false)
|
||||||
{
|
{
|
||||||
return ArticlePrice::find($id)->update($data);
|
$id = isset($data['id']) ? $data['id'] : false;
|
||||||
|
$article = ArticlePrice::find($id);
|
||||||
|
$article->update($data);
|
||||||
|
return $article;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function destroy($id)
|
public static function destroy($id)
|
||||||
|
|||||||
@@ -30,11 +30,12 @@ class Articles
|
|||||||
$data = $article->toArray();
|
$data = $article->toArray();
|
||||||
$data['categories'] = self::getCategoriesByArticle($article);
|
$data['categories'] = self::getCategoriesByArticle($article);
|
||||||
$data['tags'] = self::getTagsByArticle($article);
|
$data['tags'] = self::getTagsByArticle($article);
|
||||||
$data = self::getMeta($data);
|
$data['prices'] = self::getPricesByArticle($article);
|
||||||
|
self::getMeta($data);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getMeta($data = [])
|
public static function getMeta(&$data = [])
|
||||||
{
|
{
|
||||||
$data['categories_options'] = Categories::getOptions();
|
$data['categories_options'] = Categories::getOptions();
|
||||||
$data['families_options'] = ArticleFamilies::getOptions();
|
$data['families_options'] = ArticleFamilies::getOptions();
|
||||||
@@ -55,6 +56,11 @@ class Articles
|
|||||||
return $article->tags->pluck('id')->toArray();
|
return $article->tags->pluck('id')->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getPricesByArticle($article)
|
||||||
|
{
|
||||||
|
return ArticlePrices::getPricesByArticle($article->id);
|
||||||
|
}
|
||||||
|
|
||||||
public static function get($id)
|
public static function get($id)
|
||||||
{
|
{
|
||||||
return Article::find($id);
|
return Article::find($id);
|
||||||
|
|||||||
@@ -58,6 +58,18 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function init_attribute_values() {
|
||||||
|
$('.attributes-family').each( function() {
|
||||||
|
var family_id = $(this).val();
|
||||||
|
var $family = $(this);
|
||||||
|
var $parent = $family.parent().parent();
|
||||||
|
var $selector = $parent.find('.attributes-value');
|
||||||
|
load_attribute_values($selector, family_id);
|
||||||
|
value_id = $selector.data('id');
|
||||||
|
$selector.val(value_id).trigger('change');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function load_attribute_values($selector, family_id) {
|
function load_attribute_values($selector, family_id) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : "{{ route('Shop.Admin.ArticleAttributeValues.getOptionsByFamily') }}",
|
url : "{{ route('Shop.Admin.ArticleAttributeValues.getOptionsByFamily') }}",
|
||||||
@@ -69,5 +81,35 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handle_delete_price() {
|
||||||
|
$('.delete-price-btn').click(function() {
|
||||||
|
var $selector = $(this).parents('.row-price');
|
||||||
|
var id = $selector.find('.price_id').val();
|
||||||
|
|
||||||
|
confirm_delete(id, laroute.route('Shop.Admin.ArticlePrices.destroy', {id : id}), function() {
|
||||||
|
$selector.remove();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_prices() {
|
||||||
|
$('.price-item').change(function() {
|
||||||
|
tax_selected = $(this).parent().prev().find('select option:selected').text();
|
||||||
|
price_taxed = $(this).val() * (1 + (tax_selected / 100));
|
||||||
|
$(this).parent().parent().find('.price-taxed-item').val(price_taxed);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_prices_taxed() {
|
||||||
|
$('.price-taxed-item').change(function() {
|
||||||
|
tax_selected = $(this).parent().prev().find('select option:selected').text();
|
||||||
|
console.log($(this).parent().prev());
|
||||||
|
price = $(this).val() / (1 + (tax_selected / 100));
|
||||||
|
$(this).parent().parent().find('.price-item').val(price);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<div class="row row-attribute">
|
||||||
|
|
||||||
|
<input type="hidden" name="prices[{{ $key }}][attributes][quantity]" value="1">
|
||||||
|
<input type="hidden" name="prices[{{ $key }}][attributes][id]" value="{{ (isset($attribute['id'])) ? $attribute['id'] : null }}">
|
||||||
|
|
||||||
|
<div class="col-12 col-lg-6">
|
||||||
|
{{ Form::label('attribute_family_id', 'Attributs') }}<br/>
|
||||||
|
@include('components.select', [
|
||||||
|
'name' => "prices[$key][attributes][attribute_family_id]",
|
||||||
|
'value' => (isset($attribute['value']['attribute_family_id'])) ? $attribute['attribute_family_id'] : null,
|
||||||
|
'list' => $attribute_families_options,
|
||||||
|
'required' => true,
|
||||||
|
'class' => 'select2 form-control form-control-sm attributes-family'
|
||||||
|
])
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 col-lg-6">
|
||||||
|
{{ Form::label('attribute_value_id', 'Valeur') }}<br/>
|
||||||
|
@include('components.select', [
|
||||||
|
'name' => "prices[$key][attributes][attribute_value_id]",
|
||||||
|
'value' => (isset($attribute['attribute_value_id'])) ? $attribute['attribute_value_id'] : null,
|
||||||
|
'list' => (isset($attribute_values)) ? $attribute_values : null,
|
||||||
|
'required' => true,
|
||||||
|
'class' => 'select2 form-control form-control-sm attributes-value',
|
||||||
|
'meta' => (isset($attribute['attribute_value_id'])) ? 'data-id="' . $attribute['attribute_value_id'] . '"' : ''
|
||||||
|
])
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,11 +1,46 @@
|
|||||||
<div class="row-price p-3 col-12">
|
<div class="col-12 row-price">
|
||||||
|
|
||||||
<input type="hidden" name="prices[{{ $key }}][id]" value="@if (isset($price['id'])){{ $price['id'] }}@endif" class="price_id">
|
<input type="hidden" name="prices[{{ $key }}][id]" value="@if (isset($price['id'])){{ $price['id'] }}@endif" class="price_id">
|
||||||
|
|
||||||
<p>
|
<div class="card card-light">
|
||||||
@include('components.button-delete', ['class' => 'delete-price-btn'])
|
<div class="card-body pt-2">
|
||||||
Autre tarif
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-lg-1">
|
||||||
|
{{ Form::label('quantity', 'Quantité') }}<br/>
|
||||||
|
@include('components.number', ['name' => "prices[$key][quantity]", 'value' => (isset($price['quantity'])) ? $price['quantity'] : 1, 'required' => true, 'class' => 'form-control-sm'])
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-5">
|
||||||
|
@include('Shop.Admin.Articles.partials.prices.block_attribute', ['attribute' => $price['article_attributes'][0]])
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-1">
|
||||||
|
{{ Form::label('tax_id', 'TVA') }}<br/>
|
||||||
|
@include('components.select', ['name' => "prices[$key][tax_id]", 'value' => (isset($price['tax_id'])) ? $price['tax_id'] : null, 'list' => isset($taxes_options) ? $taxes_options : null, 'required' => true, 'class' => 'form-control form-control-sm'])
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-2">
|
||||||
|
{{ Form::label('price', 'Prix HT') }}
|
||||||
|
@include('components.money', ['name' => "prices[$key][price]", 'value' => (isset($price['price'])) ? $price['price'] : 0, 'required' => true, 'class' => 'form-control-sm price-item'])
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-2">
|
||||||
|
{{ Form::label('price_taxed', 'Prix TTC') }}
|
||||||
|
@include('components.money', ['name' => "prices[$key][price_taxed]", 'value' => (isset($price['price_taxed'])) ? $price['price_taxed'] : 0, 'required' => true, 'class' => 'form-control-sm price-taxed-item'])
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-1 text-right">
|
||||||
|
<br/>
|
||||||
|
<button type="button" class="btn btn-xs btn-danger delete-price-btn mt-2" data-card-widget="collapse" data-toggle="tooltip" title="supprimer">
|
||||||
|
<i class="fas fa-trash"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,22 +1,17 @@
|
|||||||
@if (isset($prices) && (count($prices)))
|
@if (isset($prices) && (count($prices)))
|
||||||
@for ($i = 1; $i < count($prices); $i++)
|
@for ($i = 0; $i < count($prices); $i++)
|
||||||
@include('Shop.Admin.Articles.partials.block_price', ['key' => $i, 'price' => $prices[$i]])
|
@include('Shop.Admin.Articles.partials.prices.block_price', ['key' => $i, 'price' => $prices[$i]])
|
||||||
@endfor
|
@endfor
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@push('js')
|
@push('js')
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
|
handle_delete_price();
|
||||||
$('.delete-price-btn').click(function() {
|
init_attribute_values();
|
||||||
var $selector = $(this).parents('.row-price');
|
handle_change_attribute();
|
||||||
var id = $selector.find('.price_id').val();
|
handle_prices();
|
||||||
|
handle_prices_taxed();
|
||||||
confirm_delete(id, laroute.route('Hestimmo.ArticlePrices.destroy', {id : id}), function() {
|
|
||||||
$selector.remove();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
@include('components.input', ['type' => 'number', 'meta' => "step = '.01'"])
|
@include('components.input', ['type' => 'number', 'meta' => "step=0.01"])
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
{{ Form::label('civilite', 'Civilité') }}
|
{{ Form::label('civilite', 'Civilité') }}
|
||||||
<select name="civilite" id="civilite" class="form-control">
|
<select name="civility" id="civility" class="form-control">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<option value="1">M.</option>
|
<option value="1">M.</option>
|
||||||
<option value="2">Mme</option>
|
<option value="2">Mme</option>
|
||||||
@@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
<div class="col-md-5">
|
<div class="col-md-5">
|
||||||
{{ Form::label('prenom', 'Prénom') }}
|
{{ Form::label('prenom', 'Prénom') }}
|
||||||
<input type="text" name="prenom" id="prenom" value="@if (isset($prenom)){{ $prenom }}@endif" class="form-control">
|
<input type="text" name="firstname" value="@if (isset($firstname)){{ $firstname }}@endif" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-5">
|
<div class="col-md-5">
|
||||||
{{ Form::label('nom', 'Nom') }}
|
{{ Form::label('nom', 'Nom') }}
|
||||||
<input type="text" name="nom" id="nom" value="@if (isset($nom)){{ $nom }}@endif" class="form-control">
|
<input type="text" name="name" value="@if (isset($name)){{ $name }}@endif" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
@if (isset($style))style="{{ $style }}" @endif
|
@if (isset($style))style="{{ $style }}" @endif
|
||||||
@if (isset($required))required="required"@endif
|
@if (isset($required))required="required"@endif
|
||||||
@if (isset($multiple))multiple="multiple"@endif
|
@if (isset($multiple))multiple="multiple"@endif
|
||||||
|
@if (isset($meta)){{ $meta }}@endif
|
||||||
>
|
>
|
||||||
@if (isset($with_empty))
|
@if (isset($with_empty))
|
||||||
<option>{{ $with_empty }}</option>
|
<option>{{ $with_empty }}</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user