1
votes

I am considering the possibility of working with a merchant in my region who offers payment gateway services. The specific merchant works with the "Payment Page" concept, i.e a specific uri of my site e.g http://www.mysite.com/culture1/cart/index will be authorized from the merchant side in order to proceed with the user's payment.

My site is built with symfony 1.4 and supports i18n, so all of my routes have the culture embeded in the url (/:sf_culture/...)

i.e for culture1 (which is the default one):

http://www.mysite.com/culture1/cart/index

for culture2:

http://www.mysite.com/culture2/cart/index

However if the payment goes from the second url it will simply fail on the authorization from the merchant site.

So, is there any way in symfony to create a uniform url (using routing) for a specific action in a specific module without embedded culture information by keeping at the same time the user's culture?

In this scenario the goal would be to be authorized using the following url:

http://www.mysite.com/cart/index
2

2 Answers

2
votes

Sure. You just have to add it to your routing.yml without the :sf_culture. The culture is kept on the user's attribute. So that :sf_culture is only needed if you change your language and SEO.

1
votes

Rout with culture for example:

contacts:  
  url:   /:sf_culture/contacts
  param: { module: static, action: contacts }
  requirements: { sf_culture: (?:uk) } 

Same rout without culture:

contacts:  
  url:   /contacts
  param: { module: static, action: contacts }

Just set default culture for each user when :

    homepage:
      url: /
      param: { module: static, action: about}
      requirements: { sf_culture: (?:uk }

    localized_homepage:
      url: /:sf_culture
      param: { module: static, action: about}
      requirements: { sf_culture: (?:uk) }

apps/frontend/modules/static/action.class.php

    public function executeAbout(sfWebRequest $request)
  {


   if (!$request->getParameter('sf_culture'))
        {
        if ($this->getUser()->isFirstRequest())
            {
            $culture = $request->getPreferredCulture(array('uk'));
            $this->getUser()->setCulture($culture);
            $this->getUser()->isFirstRequest(false);
            }
        else
            {
            $culture = $this->getUser()->getCulture();
            }

            $this->redirect('localized_homepage');
        }
  }

// apps/frontend/lib/myUser.class.php

public function isFirstRequest($boolean = null)
{
  if (is_null($boolean))
  {
    return $this->getAttribute('first_request', true);
  }

  $this->setAttribute('first_request', $boolean);
}

If the user enters the link, which contains no culture, it's okay,importantly, that it was previously determined. Just try)

You can also set culture in action:

$this->getUser()->setCulture('uk');

Update:

If the sf_culture variable is not present in the request, it means that the user has come to the / URL. If this is the case and the session is new, the preferred culture is used as the user culture. Otherwise the user's current culture is used.

It from Jobeet tutorial.(click)