/** * Get Target Path * * @param \Magento\UrlRewrite\Model\UrlRewrite $model * @return string * @throws \Magento\Framework\Exception\LocalizedException */ protected function getTargetPath($model) { $targetPath = $this->getCanonicalTargetPath(); if ($model->getRedirectType() && !$model->getIsAutogenerated()) { $data = [UrlRewrite::ENTITY_ID => $model->getEntityId(), UrlRewrite::TARGET_PATH => $targetPath, UrlRewrite::ENTITY_TYPE => $model->getEntityType(), UrlRewrite::STORE_ID => $model->getStoreId()]; $rewrite = $this->urlFinder->findOneByData($data); if (!$rewrite) { $message = $model->getEntityType() === self::ENTITY_TYPE_PRODUCT ? __('The product you chose is not associated with the selected store or category.') : __('The category you chose is not associated with the selected store.'); throw new LocalizedException($message); } $targetPath = $rewrite->getRequestPath(); } return $targetPath; }