Fixes on new model
This commit is contained in:
@@ -25,17 +25,27 @@ class ArticleAttributes
|
||||
return ArticleAttribute::find($id);
|
||||
}
|
||||
|
||||
public static function storeAttributes($article_price_id, $attributes)
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
return ArticleAttribute::byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticleWithPrices($id)
|
||||
{
|
||||
return ArticleAttribute::with('prices')->byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function storeAttributes($article_id, $attributes)
|
||||
{
|
||||
foreach ($attributes as $key => $attribute)
|
||||
{
|
||||
self::storeAttribute($article_price_id, $attributes[$key]);
|
||||
self::storeAttribute($article_id, $attributes[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeAttribute($article_price_id, $attribute)
|
||||
public static function storeAttribute($article_id, $attribute)
|
||||
{
|
||||
$attribute['article_price_id'] = $article_price_id;
|
||||
$attribute['article_id'] = $article_id;
|
||||
unset($attribute['attribute_family_id']);
|
||||
return self::store($attribute);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,14 @@ use App\Models\Shop\ArticlePrice;
|
||||
class ArticlePrices
|
||||
{
|
||||
|
||||
public static function getPricesByArticle($id)
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
return ArticlePrice::with('ArticleAttributes.Value')->byArticle($id)->get()->toArray();
|
||||
return ArticlePrice::byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticleWithAttribute($id)
|
||||
{
|
||||
return ArticlePrice::with('article_attribute')->byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
@@ -34,11 +39,11 @@ class ArticlePrices
|
||||
return ArticlePrice::find($id);
|
||||
}
|
||||
|
||||
public static function storePrices($article_id, $prices)
|
||||
public static function storePrices($article_attribute_id, $prices)
|
||||
{
|
||||
if ($prices) {
|
||||
foreach ($prices as $key => $price) {
|
||||
$prices[$key]['article_id'] = $article_id;
|
||||
$prices[$key]['article_attribute_id'] = $article_attribute_id;
|
||||
self::store($prices[$key]);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -30,6 +30,7 @@ class Articles
|
||||
$data = $article->toArray();
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['tags'] = self::getTagsByArticle($article);
|
||||
// $data['attributes'] = self::getAttributesByArticle($article);
|
||||
$data['prices'] = self::getPricesByArticle($article);
|
||||
self::getMeta($data);
|
||||
return $data;
|
||||
@@ -56,9 +57,14 @@ class Articles
|
||||
return $article->tags->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAttributesByArticle($article)
|
||||
{
|
||||
return ArticleAttributes::getByArticleWithPrices($article->id)->toArray();
|
||||
}
|
||||
|
||||
public static function getPricesByArticle($article)
|
||||
{
|
||||
return ArticlePrices::getPricesByArticle($article->id);
|
||||
return ArticlePrices::getByArticleWithAttribute($article->id)->toArray();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
|
||||
Reference in New Issue
Block a user