protected function selectRandomAttributesFromProduct(Product $product) { $attributeGroups = $product->attributeOptions()->with('attributeGroup')->get()->pluck('attributeGroup')->flatten(1)->unique(); return $attributeGroups->map(function (AttributeGroup $attributeGroup) { return $attributeGroup->getAttributeOptions()->random()->id; })->toArray(); }
public function getAttributesForProduct(Product $product) { $attributeOptions = $product->attributeOptions()->get()->groupBy('attribute_group_id'); $attributeGroups = $this->getAttributeGroupRepository()->whereIn('id', $attributeOptions->keys())->findAll()->keyBy('id'); // Recontsruct a nested {group.options} collection. return $attributeOptions->map(function ($attributeGroupOptions, $attributeGroupId) use($attributeGroups) { return $attributeGroups->get($attributeGroupId)->setRelation('attributeOptions', $attributeGroupOptions); }); }
public function index(Product $product) { $attributeGroups = $this->attributeManager->getAttributeGroupRepository()->with('attributeOptions')->whereSeller($this->shop())->findAll(); $attributeOptions = $product->attributeOptions()->get(['attribute_options.id'])->pluck('id'); return view('attribute::__shop.product.attributes', compact('product', 'attributeGroups', 'attributeOptions')); }