/** * @param Request $request * @param Product $product * @return \Illuminate\Http\RedirectResponse */ public function update(Request $request, Product $product) { // if a plan is selected authorize first if ($planId = $request->input('plan')) { $plan = $this->shippingPlanRepository->find($planId); $this->authorize('update', $plan); $product->shippingPlans()->sync([$planId]); } else { $product->shippingPlans()->sync([]); } return $this->success('edit'); }
private function checkProductHasNoValidShippingPlanForAddress($product) { if (!$this->address) { return true; } $this->address->setFeeType($this->seller); $shippingPlans = $this->shippingPlanRepository->findWhereProduct($product); foreach ($shippingPlans as $shippingPlan) { foreach ($shippingPlan->shippingOptions as $option) { if (isset($option->{$this->address->getFeeType()}) and $option->{$this->address->getFeeType()}) { return false; } } } return true; }