1

I have a category that represents different store vendors, which are then assigned to the appropriate product.

The goal is to attach a unique URL to the category relationship, so each product assigned to the category will have its own URL associated with it.

The idea is to create a Buy Now where each product has its own vendor specific URL. So, the URL cannot be stored in the category, but needs to be stored as metadata of the relationship.

Any ideas on how to accomplish this? After searching I'm starting to think it will be a custom solution, but even then I'm not sure exactly where to start.

Thanks in advance.

1

Depending on your needs and the size of this project, I see there are two ways of accomplishing this. The first, and most straightforward is the comment by @fabien-blechschmidt response (https://gist.github.com/byjujohn/5508233) of creating a URL rewrite.

Mage::getModel('core/url_rewrite')
    ->setIsSystem(0)
    ->setOptions('RP')
    ->setIdPath('Imported-Old-Website-URL-test1')
    ->setTargetPath('new-product-path')
    ->setRequestPath('old-product-path')
    ->save();

If you would like more granular control or to be able to customize the response, this is an interesting way of doing it.

Please note: as this is not typical convention, I would put a blank file in Controller/CustomPath.php that shows that the routing is happening in an observer.

config.xml

<frontend>
    <events>
        <controller_front_init_before>
            <observers>
                <Company_Module>
                    <class>Company_Module_Model_Observer</class>
                    <method>controllerFrontInitBefore</method>
                </Company_Module>
            </observers>
        </controller_front_init_before>
    </events>
</frontend>

Model/Observer.php

/**
 * This is the event that sets up the router.
 * 
 * @param $observer
 */
public function controllerFrontInitRouters($observer)
{
    /* @var $front Mage_Core_Controller_Varien_Front */
    $front = $observer->getEvent()->getFront();

    $front->addRouter('custom_path', $this);
}

/**
 * This is the match request. It will just alias it to a controller
 * 
 * @param Zend_Controller_Request_Http $request
 * @return bool
 */
public function match(Zend_Controller_Request_Http $request)
{
    $identifier = explode('/', trim($request->getPathInfo(), '/'));
    $frontName = $this->_getFrontName(); // retrieved the frontname from xml

    if (count($identifier) <= 1 || $identifier[0] !== $frontName) {
        return false;
    }

    $action = '';
    $paramValue = '';

    // CUSTOM ACTION PERFORMED HERE:

    $request->setModuleName($frontName)
        ->setControllerName('attribute')
        ->setActionName($action)
        ->setParam('attribute', $paramValue);

    $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, implode('/', $identifier));

    return false;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.