`How to display url of images of products of a certain category?
K
K
kryamk2020-10-31 07:57:44
MODX
kryamk, 2020-10-31 07:57:44

How to display url of images of products of a certain category?

[[!pdoResources?
  &class=`msProductFile`
  &where=`{"parent":0}`
  &sortby=`product_id`
  &sortdir=`asc`
  &tpl=`@CODE: [[+product_id]] - [[+url]]<br>`
]]

This code displays the id and url of the images of all products, but I need a specific category. I tried to write &parents but it didn't work

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
K
kryamk, 2020-10-31
@kryamk

Here's some crazy stuff I did:
get_id snippet:

$params = ['parents' => '11','tpl' => '@CODE:[ [+id] ],']; // параметры для получения id товаров
$id_list = $modx->runSnippet('pdoResources', $params); // запускаем сниппет и вносим id в переменную
$id_list = str_replace("\n", '', $id_list); // удаляем пробелы
$id_list = explode(",", $id_list); // преобразуем в массив
asort($id_list); // сортировка по значению, по возрастанию
foreach ($id_list as $id_item) {
$params1 = ['product'=>$id_item,'tpl'=>'my.tpl.msGallery'];
$result = $modx->runSnippet('msGallery', $params1);
echo $result;
}

Chunk my.tpl.msGallery:
{foreach $files as $file}
    <p>{$file['product_id']} - {$file['url']}</p>
{/foreach}

Conclusion:
[msGallery] The resource with id = 9 is not instance of msProduct.
18 - /assets/images/products/18/images-(2).jpg
18 - /assets/images/products/18/tes-tpkwmnvcpg-r-dflhzeyg.jpg
19 - /assets/images/products/19/gun.jpg
20 - /assets/images/products/20/den-17-yarost-keksa.jpg

Why it picks up id=9 (this is the current page id) is not clear..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question