From 79d25c7d2ee28f2d463a130b46f4ea73934e6219 Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Mon, 8 Jul 2019 15:09:42 +0530 Subject: [PATCH] issue #1060 --- packages/Webkul/Product/src/Helpers/View.php | 24 +++++++++++++++---- .../Product/src/Listeners/ProductFlat.php | 2 +- .../Webkul/Product/src/Models/ProductFlat.php | 10 +++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/Webkul/Product/src/Helpers/View.php b/packages/Webkul/Product/src/Helpers/View.php index 16bca34d5..80fd89b04 100755 --- a/packages/Webkul/Product/src/Helpers/View.php +++ b/packages/Webkul/Product/src/Helpers/View.php @@ -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[] = [ diff --git a/packages/Webkul/Product/src/Listeners/ProductFlat.php b/packages/Webkul/Product/src/Listeners/ProductFlat.php index 9634a53b1..bde6d1473 100644 --- a/packages/Webkul/Product/src/Listeners/ProductFlat.php +++ b/packages/Webkul/Product/src/Listeners/ProductFlat.php @@ -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; } diff --git a/packages/Webkul/Product/src/Models/ProductFlat.php b/packages/Webkul/Product/src/Models/ProductFlat.php index c23ecbefa..90caf6b23 100644 --- a/packages/Webkul/Product/src/Models/ProductFlat.php +++ b/packages/Webkul/Product/src/Models/ProductFlat.php @@ -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(); } /**