-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Decouple the Url rewite modules #1296 #1338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@tzyganu Thank you for the contribution!!! We will review the code and get back to you once we complete the analysis. |
Internal reference: MAGETWO-38050 |
@tzyganu The code and functionality looks great! However, there are few things which block pull request from being merged to the mainline:
Could you please fix these points? |
@kokoc
Please reply to my comment above and I will get started on the fixes. |
I think the easiest possible ways to fix second point without mixing the system layers are: keep only first two methods in interface; add constant to some exisitng class and remove interface;
|
@kokoc But here is what I don't understand: Also I have some concern regarding the |
@kokoc Note: if at one point you want to stop wasting time with me, just because I can't manage to make it work just tell me. I won't mind. |
@tzyganu sorry for silence. I'll analyze the latest code and get back to you with some suggestion about "getters". We greatly appreciate your contribution! |
Regarding getters, the part of complex logic here is required to detect the entity type for some HTTP request. However, we know the entity type from very begging. It’s stored in UrlRewrite model or transferred directly in GET request(currently it uses three different params: category, product, cms). So, I suggest to use explicit entity_type GET param for these purposes. That will significantly simplify getters logic and make them useless ( Regarding observer, I propose you to replace it with polymorphism. Seems like the logic behind observer responsible for two main things: target_path creation and GET request validation. So, let’s create separate interface for this and call it directly from controller: <?php
namespace Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite;
class Save extends \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite
{
public function execute()
{
// ...
$type = $this->getRequest()->getParam('entity_type') ?: \Magento\UrlRewrite\Model\Mode\Custom::ENTITY_TYPE;
$model->setEntityType($type)
->setRequestPath($requestPath)
->setTargetPath($this->getRequest()->getParam('target_path', $model->getTargetPath()))
->setRedirectType($this->getRequest()->getParam('redirect_type'))
->setStoreId($this->getRequest()->getParam('store_id', 0))
->setDescription($this->getRequest()->getParam('description'));
$handler = $handlerFactory->getByType($type);
$handler->prepareUrlRewrite($model, $request);
$model->save();
$this->messageManager->addSuccess(__('The URL Rewrite has been saved.'));
// ....
}
}
class ProductHandler implements UrlSaveHandlerInterface{
function prepareUrlRewrite($urlRewrite, $request) {
$product = ProductRepositoryInterface::getById($request->getParam('product')); //got validation inside
$category = null;
if ($request->getParam('category')) {
$category = CategoryRepositoryInterface::getById($request->getParam('category')); //got validation inside
$urlRewrite->setMetadata(serialize(['category_id' => $category->getId()]));
}
$targetPath = $this->productUrlPathGenerator->getCanonicalUrlPath($product, $category);
if ($urlRewrite->getRedirectType() && !$urlRewrite->getIsAutogenerated()) {
$data = [
UrlRewriteService::ENTITY_ID => $urlRewrite->getEntityId(),
UrlRewriteService::TARGET_PATH => $targetPath,
UrlRewriteService::ENTITY_TYPE => $urlRewrite->getEntityType(),
UrlRewriteService::STORE_ID => $urlRewrite->getStoreId(),
];
$rewrite = $this->urlFinder->findOneByData($data);
if (!$rewrite) {
throw new LocalizedException(__('Chosen product is not associated with the chosen store or category.'));
}
$targetPath = $rewrite->getRequestPath();
}
$urlRewrite
->setTargetPath($targetPath)
->setEntityId($product->getId());
}
} Does something like this make sense? |
@kokoc Sorry for the late response. I was away for a while. Thanks for the feedback. I will try to follow your guide, but for the moment I put this on hold because of the lack of time. I will get back to this as soon as I have some spare time. |
We have automated a Magento Contributor License Agreement verifier for contributions sent to our GitHub projects. |
@kokoc hey did we ever made progress on this one? |
@piotrekkaminski @kokoc I didn't. I kind of neglected this. I was hoping the core team will pick it up 😄 |
this issue seams to be solved by the core team. I will close this PR now. |
@tzyganu, how do you see it? As to me it seems like |
@orlangur Damn. you are right. I didn't look very careful at it. Maybe you can open an other issue. If I reopen this one most probably it will be ignored for a while. |
@tzyganu thanks, just want to be sure I'm not missing something 👍 This is one of mine "personal TD" which I would like to work on :) So, I would like to prepare a PR (maybe, stealing a part of your implementation) if you don't mind. The only tricky part here I see is BC preserving. Probably will have to leave all old classes but make them ready for removal (thus literally module dependencies will remain until classes may be simply removed in some |
…onProcessor Cannot create shipment via REST API.
I've removed the references to
CatalogUrlRewrite
andCmsUrlRewrite
modules from the mainUrlRewrite
module.I moved every block, controller and template from the main module to the appropriate module.
I introduced a new class
Magento\UrlRewrite\Model\Mode
that is basically a collection of url rewrite modes. Any additional mode can be added to these modes viadi.xml
and each mode must implement a certain interface.I'm almost sure that some things could have been done differently, but at least it's a place to start. Any of the
CatalogUrlRewrite
andCmsUrlRewrite
can now be disabled without impacting theUrlRewrite
module's prper functioning.If you have other suggestions after the code review, please send them my way.