P
P
photosho2017-09-01 11:17:33
1C-Bitrix
photosho, 2017-09-01 11:17:33

How to get the full path from the categories to the product?

Let's say there is a certain product located at the following address:

- Категория 1
-- Категория 2
--- Товар

The parameter "#SECTION_CODE_PATH#" appears in the infoblock settings in the "URL of the detailed view page" item. How can I get the full path to an element from the category IDs to generate the corresponding link?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Emelyanov, 2017-09-01
@photosho

https://dev.1c-bitrix.ru/api_help/iblock/classes/c...

A
Artyom Luchnikov, 2017-09-01
@lu4nik

It's a bad idea to use SECTION_CODE_PATH when generating a URL. If you "rebuild" the directory in the future, then all links will change, which will lead to problems with SEO.
Well, on the topic - you can get a link for a specific element like this:

$iterator = \CIBlockElement::GetList(
    [],
    [
        'ID' => $elementId,
    ],
    false,
    false,
    [
        'DETAIL_PAGE_URL',
    ]
);
if ($item = $iterator->GetNext()) {
    echo $item['DETAIL_PAGE_URL'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question