Child pages
  • [cms] Links in Breadcrumbs have incorrect urls, when using 'shift' parameter in c_CategoryPath tag [5.2.1-RC1]
Skip to end of metadata
Go to start of metadata

The c_CategoryPath is used to build a breadcrumbs. Usually they consists from following components:

  • Home
  • Path > To > The > Category
  • Item Name (e.g. Link/Product/etc)
  • Custom Template

When you don't want the strip first N elements from it, then shift parameter comes in handy. However it turns out that, when the 2 (or larger) value is used then links to the categories point back to homepage instead of corresponding category pages.

Here is the code which handles shift parameter and creates a problem:

navigation_bar.php
if ( isset($this->_params['shift']) && $this->_params['shift'] ) {
	array_splice($category_path, 0, $this->_params['shift']);
}

Used array_splice function removes first N categories from the array, but as a side effect resets indexes in the array, which are used to identify categories later on.

c_CategoryPath_breadcrumbs_fix1.patch

Related Tasks

INP-1349 - Getting issue details... STATUS

5 Comments

  1. Volodymyr Fedyk, have you come up with a solution to described problem?

    1. Alex, yes. We can replace usage of array_splice function with following fragment:

      navigation_bar.php
      $category_path = array_slice($category_path, $this->_params['shift'], null, true);
      1. I think that you can safely create a task and a patch for 5.2.x branch, that will go to the 5.2.1 release.

        After creating a task you need:

        1. mention it under the "Related Tasks" heading
        2. remove "task-missing" label
        3. add "task-created" label

        Remember, that in the task we don't copy/paste whole discussion. We only write what needs to be done to fix the problem described in here.

         

      2. Also please double check that element count in resulting array is correct. I'm asking because the shift parameter value for the array_splice is the length (starting from 1) and for the array_slice it's array index (starting from 0).

        1. According to http://php.net:

          Old code
          array_splice($category_path, 0, $this->_params['shift']);

          means that:

          • $category_path is input array;
          • 0 is offset;
          • $this->_params['shift'] is length of extraction;

          Also in

          New code
          $category_path = array_slice($category_path, $this->_params['shift'], null, true);
          • $category_path is an input array;
          • $this->_params['shift'] is offset;
          • null means that we going to end of array;
          • true is for preserving keys;

          To make sure everything is alright I made synthetic test:

          Synthetic test
          <?php
          /**
           * Custom test for array_splice and array_slice functions.
           */
          $a_arr = array(
          	'4' => '20',
          	'7' => '35',
          	'9' => '45',
          );
          $b_arr = array(
          	'4' => '20',
          	'7' => '35',
          	'9' => '45',
          );
          array_splice($a_arr, 0, 2);
          $b_arr = array_slice($b_arr, 2, null, true);
          var_dump($a_arr, $b_arr);

          Output will be:

          array (size=1)
            0 => string '45' (length=2)
          
          array (size=1)
            9 => string '45' (length=2)

          As we see, results are similar, but array_splice destroys numeric keys of array.