validationResultFactory = $validationResultFactory; $this->generalMessage = $generalMessage; } /** * @inheritdoc */ public function validate(Quote $quote): array { $validationErrors = []; if (!$quote->isVirtual()) { $shippingAddress = $quote->getShippingAddress(); $shippingAddress->setStoreId($quote->getStoreId()); $shippingMethod = $shippingAddress->getShippingMethod(); $shippingRate = $shippingAddress->getShippingRateByCode($shippingMethod); $validationResult = $shippingMethod && $shippingRate; if (!$validationResult) { $validationErrors = [__($this->generalMessage)]; } } return [$this->validationResultFactory->create(['errors' => $validationErrors])]; } }