owldesign / QARR

Grow your business by allowing visitors to leave reviews or ask a questions.
https://qarr.tools
Other
6 stars 5 forks source link

[Feature request] Ability to Modify front-end templates. #7

Open 23d1 opened 5 years ago

23d1 commented 5 years ago

Is there a way to modify the templates from within the /craft/templates folder, for example; if there's a _qarr folder in there?

Would be great if the plugin looked there first to determine if it should render the templates from craft/vendors/owldesign/qarr. The ability to override non-destructively (and end up losing the changes when updating the plugin), essentially.

owldesign commented 5 years ago

Ok I added some templates, I'd like to know more about if there any other templates you'd want to have control over.

Check these docs for what is there: https://docs.qarr.tools/custom/templates/

23d1 commented 5 years ago

Excellent work! I'll leave this issue open with the following comments;

owldesign commented 5 years ago

Great, I'd like to keep this thread going for all frontend templates that I should create (lets keep this open untill it becomes dead)

This is helpful for me because I really don't know which templates you guys need and this helps me work on that.

jonXmack commented 5 years ago

It would be nice if we could just access the reviews/ratings in our templates themselves without having to resort to custom template overrides. Something like the following (which uses my code but should be fairly self explanatory).

{% set averageRating = craft.qarr.getAverageRating(product.id) %}
{% set reviews = craft.qarr.reviews(product.id) %}

<div class="rating-section">
    <div class="star-rating rating-{{ averageRating }}">&nbsp;</div>
    <a id="scrollReviews" class="reviews-total">{{ reviews|length }} customer review{{ reviews|length != "1" ? 's' }}</a>
</div>

<h3>Customer Reviews</h3>

{% if reviews|length == "0" %}
    <p>Sorry, no reviews have been submitted for this product yet.</p>
{% else %}
    <ul>
        {% for review in reviews %}
        <li class="review">
            <div class="rating-section">
                <div class="star-rating rating-{{ review.rating }}">&nbsp;</div>
            </div>
            <span class="label">
                {{ review.headline }}
            </span>
            <p>
                {{ review.feedback }}
            </p>
            <p class="author">
                By {{ review.fullName }} on {{ review.dateCreated|date('F j, Y') }}
            </p>

            <!-- START Comments -->
            {% if review.reply %}
            <div class="replied">
                {{ review.reply }}
            </div>
            {% endif %}
        </li>
        {% endfor %}
    </ul>
{% endif %}

Having the "views" separate from the main templates is very unfamiliar to me as a user of ExpressionEngine for the last 9 years and Craft for the last 3 years. I can't think of many other plugins that essentially force you to work this way. I ended up having to look through the source to find the right functions because I've got the rating displayed in multiple places across my site, some with more info than others, so having to use the {{ craft.qarr. displayRating(model) }} tag didn't really work for me. I've also had to use the getCount function as follows {% set reviewCount = craft.qarr.getCount('reviews', 'approved', product.id) %} just so I can check to see if there are any reviews as I couldn't see another way of being able to use a simple |length filter.

owldesign commented 5 years ago

@jonXmack I have this function displayReviews() that I will extend to return object as an option.

You can use it like this {% set reviews = craft.qarr.displayReviews(product, false) %} passing false will return object rathern than html markup.

The object returned will be

array[
   "averageRating" => 3.888888889,
   "reviews" => array[...],
   "total" => "54"
]

(the same will be added to displayQuestions())

Is this enought for you, em I in the right direction?

jonXmack commented 5 years ago

That's great, I'll have a play around with it.

owldesign commented 5 years ago

@jonXmack I've pushed up version 1.20 with that stuff in there. Test it out let me know if any issues and/or other suggestions you migh thave.

Thanks.

jonXmack commented 5 years ago

Looks like the version number in composer.json is still set to 1.1.9 but I've updated it manually and so far it's looking good.

owldesign commented 5 years ago

Ahh good catch, I forced updated tag (1.2.0) with updated composer file. Thanks for letting me know!