diff --git a/app/Http/Controllers/Shop/Admin/ArticleController.php b/app/Http/Controllers/Shop/Admin/ArticleController.php index 168fef21..b39e929f 100644 --- a/app/Http/Controllers/Shop/Admin/ArticleController.php +++ b/app/Http/Controllers/Shop/Admin/ArticleController.php @@ -29,6 +29,8 @@ class ArticleController extends Controller public function store(Request $request) { $data = $request->all(); +// dump($data); + // exit; Articles::storeFull($data); return redirect()->route('Shop.Admin.Articles.index'); } diff --git a/app/Models/Shop/ArticleAttribute.php b/app/Models/Shop/ArticleAttribute.php index a4c3938e..67fceee5 100644 --- a/app/Models/Shop/ArticleAttribute.php +++ b/app/Models/Shop/ArticleAttribute.php @@ -7,16 +7,16 @@ use Illuminate\Database\Eloquent\Model; class ArticleAttribute extends Model { protected $guarded = ['id']; - protected $table = 'shop_article_attribute_attributes'; + protected $table = 'shop_article_attributes'; public function Price() { - return $this->belongsTo('App\Models\Shop\ArticlePrice'); + return $this->belongsTo('App\Models\Shop\ArticlePrice','article_price_id'); } 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) diff --git a/app/Repositories/Shop/ArticlePrices.php b/app/Repositories/Shop/ArticlePrices.php index 99091644..3ce00e22 100644 --- a/app/Repositories/Shop/ArticlePrices.php +++ b/app/Repositories/Shop/ArticlePrices.php @@ -13,6 +13,11 @@ use App\Models\Shop\ArticlePrice; class ArticlePrices { + public static function getPricesByArticle($id) + { + return ArticlePrice::with('ArticleAttributes.Value')->byArticle($id)->get()->toArray(); + } + public static function getDatatable() { $model = ArticlePrice::orderBy('name'); @@ -65,9 +70,12 @@ class ArticlePrices 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) diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 1ef05500..7094df5f 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -30,11 +30,12 @@ class Articles $data = $article->toArray(); $data['categories'] = self::getCategoriesByArticle($article); $data['tags'] = self::getTagsByArticle($article); - $data = self::getMeta($data); + $data['prices'] = self::getPricesByArticle($article); + self::getMeta($data); return $data; } - public static function getMeta($data = []) + public static function getMeta(&$data = []) { $data['categories_options'] = Categories::getOptions(); $data['families_options'] = ArticleFamilies::getOptions(); @@ -55,6 +56,11 @@ class Articles return $article->tags->pluck('id')->toArray(); } + public static function getPricesByArticle($article) + { + return ArticlePrices::getPricesByArticle($article->id); + } + public static function get($id) { return Article::find($id); diff --git a/resources/views/Shop/Admin/Articles/partials/prices.blade.php b/resources/views/Shop/Admin/Articles/partials/prices.blade.php index 0317b676..2f8a1e6f 100644 --- a/resources/views/Shop/Admin/Articles/partials/prices.blade.php +++ b/resources/views/Shop/Admin/Articles/partials/prices.blade.php @@ -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) { $.ajax({ 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); + }) + } + + + @endpush diff --git a/resources/views/Shop/Admin/Articles/partials/prices/block_attribute.blade.php b/resources/views/Shop/Admin/Articles/partials/prices/block_attribute.blade.php new file mode 100644 index 00000000..8b5f2725 --- /dev/null +++ b/resources/views/Shop/Admin/Articles/partials/prices/block_attribute.blade.php @@ -0,0 +1,28 @@ +
- @include('components.button-delete', ['class' => 'delete-price-btn']) - Autre tarif -
- +