Skip to content
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

Add RewriteController to allow easy handling of historic rewrites #37

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
require_once Mage::getModuleDir('controllers', 'Divante_VueStorefrontBridge') . DS . 'AbstractController.php';
class Divante_VueStorefrontBridge_RewriteController extends Divante_VueStorefrontBridge_AbstractController
{
public function targetAction()
{
if (!$this->_checkHttpMethod('GET')) {
return $this->_result(405, 'Method not allowed');
}

$requestPath = $this->getRequest()->getParam('request_path');
if ($requestPath) {
$reader = Mage::getSingleton('core/resource')->getConnection('core_read');

$select = $reader->select()
->from('core_url_rewrite', ['target_path'])
->where('request_path = ?', $requestPath)
->where('store_id IN (?)', [Mage_Core_Model_App::ADMIN_STORE_ID, (int)Mage::app()->getStore()->getId()])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally avoid using the globally set store id, had some issues in the past with having the wrong store.
might we require it to be set in the URL as param?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here i think we should have both, the Mage::app()->getStore()->getId() as a fallback when no storeId is set in the request?

Like for example:

$storeId = $this->getRequest()->getParam('storeId');
if (empty($storeId)) {
    $storeId = (int)Mage::app()->getStore()->getId();
}

What do you think about that? @sandermangel

->where('category_id is null')
->where('product_id is null')
->order('store_id DESC')
->limit(1);

$result = $reader->fetchOne($select);

if ($result) {
return $this->_result(200, $result);
}

return $this->_result(404, 'No matching request path found');
}

return $this->_result(400, 'Malforemd request');

}
}