authorize('associateInco', $product); try { $preview = $this->executor->execute( $query, $request->toGetArcadiaIncoPreviewQueryInput(), ); } catch (\RuntimeException $e) { return response()->json([ 'message' => __('Arcadia API error: :error', ['error' => $e->getMessage()]), ], 502); } if ($preview === null) { return response()->json([ 'message' => __('No INCO sheet found on Arcadia for this article number.'), ], 404); } return response()->json($preview); } public function associate(AssociateProductIncoRequest $request, Product $product, AssociateProductInco $action): RedirectResponse { $this->authorize('associateInco', $product); try { $inco = $this->executor->execute( $action, $request->toAssociateProductIncoInput($product), ); } catch (\RuntimeException $e) { return back()->with('danger', __('Arcadia API error: :error', ['error' => $e->getMessage()])); } return to_route('bo.products.incos.edit', compact('product', 'inco')) ->with('success', __('The INCO sheet has been successfully associated with the product.')); } public function sync(SyncProductIncoRequest $request, Product $product, SyncProductInco $action): RedirectResponse { $this->authorize('syncInco', $product); try { $inco = $this->executor->execute( $action, $request->toSyncProductIncoInput($product), ); } catch (\RuntimeException $e) { return back()->with('danger', __('Arcadia API error: :error', ['error' => $e->getMessage()])); } return to_route('bo.products.incos.edit', compact('product', 'inco')) ->with('success', __('The INCO sheet has been successfully synchronized from Arcadia.')); } public function create(Product $product): View { return $this->edit($product); } public function edit(Product $product, ?ProductInco $inco = null): View { $this->authorize('associateInco', $product); $productDto = ProductDto::fromModel($product); $incoModel = $inco ?? $product->inco; $incoDto = $incoModel instanceof ProductInco ? ProductIncoDto::fromModel($incoModel) : null; return view('bo.product-incos.edit', [ 'product' => $productDto, 'inco' => $incoDto, ]); } }