public function assign(Request $request, Product $product, VariantManager $variantManager) { // Filter attributes to only authorized ones. $attributeOptions = $this->attributeManager->getAttributeOptionRepository()->whereHas('attributeGroup', function ($query) use($request) { $query->where([['seller_type', '=', $this->shop()->getMorphClass()], ['seller_id', '=', $this->shop()->getKey()]]); })->whereIn('id', $request->input('attributes', []))->get(); return DB::transaction(function () use($attributeOptions, $product, $variantManager) { // First we need to sync to product itself. // If there's no attribues to add simply clean up and exit. $product->setAttributeOptions($attributeOptions, true); if ($attributeOptions->isEmpty()) { $variantManager->cleanUpVariants($product); return $this->redirectBack(); } // Otherwise we need to work out the cartesian product // delete and create variants as necessary $variantManager->refreshVariants($product); return $this->success('edit'); }); }
public function handle(VariantManager $variantManager) { $variantManager->refreshVariants($this->product); }