Forum

Thread tagged as: Question, Shop

Filter purchased files based on category

My client is selling a mixture of physical and digital goods as well as courses.

At the moment I have a template when the user is logged in that displays their purchased files:

perch_shop_purchased_files([
    'template' => 'products/files_list.html',
]);

I have setup the course products to tag the user as coursepaid and so what I am trying to do is find the best method to seperate the files downloaded as part of the courses and those that are part of digital products, so they can be listed seperately. What's the best method for this? A function in my page or can it be done via the template?

I thought from the docs I could filter the files and exlcude any related to a product from a certain category:

perch_shop_purchased_files([
    'template' => 'products/files_list.html',
    'category' => array('!products/courses/'),
]);

But that doesn't seem to do as I had hoped as it still lists files purchased from this category.

Mathew Doidge

Mathew Doidge 2 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Sorry, that's our mistake - the docs are wrong. There's no category or other filters available on that function.

You'll need to use a tag comparison in the template to filter it.

Drew McLellan said:

Sorry, that's our mistake - the docs are wrong. There's no category or other filters available on that function.

You'll need to use a tag comparison in the template to filter it.

Ok thanks Drew, no problems.

My file_list.hmtl looks like:

<perch:before>
<div class="account-Member_Downloads">
    <p><strong>Your purchased files</strong></p>
</perch:before>

<perch:if different="productID">
    <perch:if not-exists="perch_item_first">
        </ul>
    </perch:if>

    <ul class="download-List">
</perch:if>

    <li>
        <span><perch:shop id="title" type="text" /></span> — <a href="/shop/download_file.php?file=<perch:shop id="fileID" />" class="download">Download</a>
    </li>

<perch:after>
    </ul>
</div>
</perch:after>

If I add the member tag part, both parts seem to validate and get output, which is confusing me:

<perch:before>
<div class="account-Member_Downloads">
    <p><strong>Your purchased files</strong></p>
</perch:before>

<perch:member has-tag="coursepaid">
    <p>True</p>
<perch:else:member />
    <p>False</p>
</perch:member>

<perch:if different="productID">
    <perch:if not-exists="perch_item_first">
        </ul>
    </perch:if>

    <ul class="download-List">
</perch:if>

    <li>
        <span><perch:shop id="title" type="text" /></span> — <a href="/shop/download_file.php?file=<perch:shop id="fileID" />" class="download">Download</a>
    </li>

<perch:after>
    </ul>
</div>
</perch:after>

However, to ensure the tag is being set I added this to the page itself, and it validates only on the members I'd expect to see it on:

if (perch_member_has_tag('coursepaid')) {
    echo("<p><strong>True</strong></p>");
}

Because my client wants to add / remove course on the fly, my original idea where I was going to just use perch_content would be insufficient. I'm struggling to work out how I could define the course products for the members screen so they are seperated so the user can differntiate from the digital downloads and physical products.