Skip to main content
added 71 characters in body
Source Link

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) {

    $coupon = $matches[1];
    $realPath = str_replace($matches[0], '', $requestPath);

    if (!$realPath) {
        $realPath = '/';
    }

    $this->request->setPathInfo($realPath);
}

This does exactly what I need. Hope it can also help someone else in the future.

EDIT: MyThe plugin I was writing can be found here: https://github.com/crankycyclops/DiscountCodeUrl It's a free and open source means to automatically apply coupon codes via the URL. Hope someone finds it useful :)

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) {

    $coupon = $matches[1];
    $realPath = str_replace($matches[0], '', $requestPath);

    if (!$realPath) {
        $realPath = '/';
    }

    $this->request->setPathInfo($realPath);
}

This does exactly what I need. Hope it can also help someone else in the future.

EDIT: My plugin can be found here: https://github.com/crankycyclops/DiscountCodeUrl It's free and open source. Hope someone finds it useful :)

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) {

    $coupon = $matches[1];
    $realPath = str_replace($matches[0], '', $requestPath);

    if (!$realPath) {
        $realPath = '/';
    }

    $this->request->setPathInfo($realPath);
}

This does exactly what I need. Hope it can also help someone else in the future.

EDIT: The plugin I was writing can be found here: https://github.com/crankycyclops/DiscountCodeUrl It's a free and open source means to automatically apply coupon codes via the URL. Hope someone finds it useful :)

added 212 characters in body
Source Link

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) {

    $coupon = $matches[1];
    $realPath = str_replace($matches[0], '', $requestPath);

    if (!$realPath) {
        $realPath = '/';
    }

    $this->request->setPathInfo($realPath);
}

This does exactly what I need. Hope it can also help someone else in the future.

EDIT: My plugin can be found here: https://github.com/crankycyclops/DiscountCodeUrl It's free and open source. Hope someone finds it useful :)

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) {

    $coupon = $matches[1];
    $realPath = str_replace($matches[0], '', $requestPath);

    if (!$realPath) {
        $realPath = '/';
    }

    $this->request->setPathInfo($realPath);
}

This does exactly what I need. Hope it can also help someone else in the future.

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) {

    $coupon = $matches[1];
    $realPath = str_replace($matches[0], '', $requestPath);

    if (!$realPath) {
        $realPath = '/';
    }

    $this->request->setPathInfo($realPath);
}

This does exactly what I need. Hope it can also help someone else in the future.

EDIT: My plugin can be found here: https://github.com/crankycyclops/DiscountCodeUrl It's free and open source. Hope someone finds it useful :)

fixed code
Source Link

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) { 

    $coupon = $matches[1];
    $this->request->setPathInfo($realPath = str_replace($matches[0], '', $requestPath);

    if (!$realPath) {
        $realPath = '/';
    }

    $this->request->setPathInfo($realPath);
}

In essence, I look for the coupon code, and if it exists, I extract it from the URL, then modify the request URL to remove it so that Magento can continue to route normally.

This is doingdoes exactly what I wantedneed. Hope it can also help someone else in the future.

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) {
    $coupon = $matches[1];
    $this->request->setPathInfo(str_replace($matches[0], '', $requestPath));
}

In essence, I look for the coupon code, and if it exists, I extract it from the URL, then modify the request URL to remove it so that Magento can continue to route normally.

This is doing exactly what I wanted. Hope it can also help someone else in the future.

I figured out a solution that works for me. In the beforeDispatch() method of my FrontControllerInterface plugin, I have the following block of code:

$requestPath = $this->request->getPathInfo();

// If a coupon code was included in the URL, fix the URL
// after extracting it so that we can continue to route normally
if (preg_match("#/discount/([^/]+?)/*$#", $requestPath, $matches)) { 

    $coupon = $matches[1];
    $realPath = str_replace($matches[0], '', $requestPath);

    if (!$realPath) {
        $realPath = '/';
    }

    $this->request->setPathInfo($realPath);
}

This does exactly what I need. Hope it can also help someone else in the future.

Source Link
Loading