This commit is contained in:
rahul shukla 2019-07-08 15:09:42 +05:30
parent 746a17dcf6
commit 79d25c7d2e
3 changed files with 30 additions and 6 deletions

View File

@ -7,22 +7,38 @@ class View extends AbstractProduct
/**
* Returns the visible custom attributes
*
* @param Product $product
* @param Product $product
* @return integer
*/
public function getAdditionalData($product)
{
$data = [];
$attributes = $product->product->attribute_family->custom_attributes()->where('attributes.is_visible_on_front', 1)->get();
$attributes = $product->attribute_family->custom_attributes()->where('attributes.is_visible_on_front', 1)->get();
$attributeOptionReposotory = app('Webkul\Attribute\Repositories\AttributeOptionRepository');
foreach ($attributes as $attribute) {
$value = $product->{$attribute->code};
if ($attribute->type == 'boolean') {
$value = $value ? 'Yes' : 'No';
} else if ($attribute->type == 'select' || $attribute->type == 'multiselect') {
$value = $product->{$attribute->code . '_label'};
} else if($value) {
if ($attribute->type == 'select') {
$attributeOption = $attributeOptionReposotory->find($value);
if ($attributeOption)
$value = $attributeOption->label ?? $attributeOption->admin_name;
} else if ($attribute->type == 'multiselect') {
$lables = [];
$attributeOptions = $attributeOptionReposotory->findWhereIn('id', explode(",", $value));
foreach ($attributeOptions as $attributeOption) {
$lables[] = $attributeOption->label ?? $attributeOption->admin_name;
}
$value = implode(", ", $lables);
}
}
$data[] = [

View File

@ -102,7 +102,7 @@ class ProductFlat
*/
public function afterAttributeCreatedUpdated($attribute)
{
if(!$attribute->is_user_defined) {
if(! $attribute->is_user_defined || $attribute->is_visible_on_front) {
return false;
}

View File

@ -13,6 +13,14 @@ class ProductFlat extends Model implements ProductFlatContract
public $timestamps = false;
/**
* Get the product attribute family that owns the product.
*/
public function getAttributeFamilyAttribute()
{
return $this->product->attribute_family;
}
/**
* Get the product that owns the attribute value.
*/
@ -104,7 +112,7 @@ class ProductFlat extends Model implements ProductFlatContract
*/
public function getReviewsAttribute()
{
return $this->images()->get();
return $this->reviews()->get();
}
/**