Do you have some feature in mind that you'd love to see in Couch? Let us know.
21 posts Page 2 of 3
@scratz, you mentioned -
Sometimes, taxes on the full value of certain discounted products need to be charged, and sometimes there are items that don't require taxes to be charged.
From what I could understand, there are certain products that may have 'Item level discounts' configured (which serves to reduce their effective prices) but you'd still want to tax these products at their original prices (and this tax percentage could be product specific). Conversely. there are certain products that do not need to be taxed at all.

Did I get the use-case right?

Is there any way to create an option for each product that is something along the lines of "full tax / tax-discount / no-tax" to be taken into consideration during the tax calculations?
Assuming I got the use-case correct above, we can have a dropdown for every product with these four values where -

'normal tax' - Default. Calculate tax on the discounted price using the percentage specified in config file. Thus is how things normally work.
'full tax' - calculate tax on the original undiscounted price using the percentage specified in config file.
'tax-percentage ' - conditionally show a text-box where the user can specify a custom tax percentage and this would be then used to calculate tax on the original undiscounted price.
'no-tax' - zero tax.

As @trendoman mentioned, in the get_taxes() function of cart_ex.php, we can loop through all items in the cart and calculate tax according to the selected values.
Tax on shipping can be added to the calculated value if desired.

How does that sound?
Hello @KK.

Yes, you have the use case correct. I didn't even think about the idea that some items are taxed differently than others. Liquor for example would be taxed heavily, whereas a candy bar would be normally taxed, whereas tomatoes wouldn't be taxed at all. Imported or out of state items could be taxed differently as well. I wonder if the taxing could even be considered per user-created category?

So, as the store with the website, I can fill out a category for products, and in this category, I will also put the tax percent. Then any product assigned to that category would have that tax percent added. Even then a discounted price would still charge THAT percentage. In this way, there could be a category called "Food / Non-Taxable" with a percentage of 0. Italian imports tax 10%, toiletries 8.258%, etc.

Does that make sense? Is something like that doable?
Does that make sense? Is something like that doable?

We can have a separate clonable template for 'Tax Class' having an editable region for the percentage value.
Each tax class (e.g. 'zero tax' etc.) would be created as its page with the percentage value specified.
We can then put a relational field in the products template relating it with the tax class above.

Any product that does not have a relation value set would have the taxes calculated normally (i.e. using default value from the config against the discounted price).

However, if the user chooses to relate a product with any Tax class, the percentage value would be fetched and used for the calculation against the full price.

Would this suffice?
Would this suffice?


Hello @KK,

Yes, I think this is a great solution! This way the clonable template can have an authorization set so a normal user (say, one that inputs products) can't go and create their own tax category (something that should be reserved for admis).

The only other thing I would question and hope to see is, in the cart, will these taxable categories (cloned pages) be itemized in the total? So the user would be able to see the amount of tax in each?
will these taxable categories (cloned pages) be itemized in the total? So the user would be able to see the amount of tax in each?
Could you please elaborate on this point?
I'd like to see a table (representing the cart) showing how you'd like to see the items in it.
You're right @KK, that is confusing, I apologize.

What I meant to say, is in the Cart page, when all the totals and discounts are listed for the grand total like in this code:

Code: Select all
<table>
<tr >
<td colspace='2'>Cart Summary</td>
</tr>
<tr>
<td>Items</td><td>1</td>
</tr>
<tr>
<td>Sub Total</td><td>$55.00</td>
</tr>
<tr>
<td>Discounts</td><td>--</td>
</tr>
<tr>
<td>Taxes</td><td>$ 4.81</td>
</tr>
<tr>
<td>Shipping Cost</td><td>$ 3.00</td>
</tr>
<tr>
<td>Grand Total</td><td>$62.61</td>
</tr>
</table>



Could it be something like this?

Code: Select all
<table>
<tr >
<td colspace='2'>Cart Summary</td>
</tr>
<tr>
<td>Items</td><td>1</td>
</tr>
<tr>
<td>Sub Total</td><td>$55.00</td>
</tr>
<tr>
<td>Discounts</td><td>--</td>
</tr>
<tr>
<td>Taxes</td><td>$ 4.81</td>
</tr>
<tr>
<td>Liquor Tax</td><td>$ 5.26</td>
</tr>
<tr>
<td>Imported Goods Tax</td><td>$ 2.07</td>
</tr>
<tr>
<td>Shipping Cost</td><td>$ 3.00</td>
</tr>
<tr>
<td>Grand Total</td><td>$62.61</td>
</tr>
</table>

Something like that? Where the tax categories (or cloned pages) are listed? Does that make more sense?
So basically something like the 'sub-totals' you mentioned a few posts back, right?
Yes, sure it should be doable.
So basically something like the 'sub-totals' you mentioned a few posts back, right?
Yes, sure it should be doable.


Well, not subtotals of the items purchased, only totals of the tax that's being charged in that category.

I'm not sure if that's what you're saying, but just a point for clarification.
@scratz,

I have coded up a proposed solution for your perusal.
Haven't done much testing so I leave it to you to test it with some real-world data and see it things come up as expected.

I created a template named 'tax-class.php' -
Code: Select all
    <?php require_once("couch/cms.php"); ?>
    <cms:template title='Tax Classes' clonable='1' hidden='0'>
        <cms:editable
            name='tax_rate'
            label='Tax Rate'
            desc='in percentage (correct upto 2 decimal points)'
            maxlength='10'
            required='1'
            search_type='decimal'
            validator='non_negative_decimal'
            width='150'
            type='text'
        />
    </cms:template>
    <?php COUCH::invoke(); ?>


and created the following cloned-pages for it (for testing) -
Code: Select all
Category    Tax%
========    ======
General     8.75
Imports     10.62
Ammo        9.65
Food        0.00

Next added the following relation field to my 'products' template -

Code: Select all
    <cms:editable name='pp_tax_class' label='Tax Class' desc="if not selected, the 'tax_percent' setting in cart/config.php will be used as default" type='relation' has='one' searchable='0' order='101' orderby='page_name' order_dir='asc' masterpage='tax-class.php' />

and then created the following products as its cloned-pages (for testing) -

Code: Select all
    Products            Category    Price   Qty
    =========           ========    ======  ===
    Boxed Cereal        Food        15.00   3
    Bag Apples          Food        4.98    1

    Leather Wallet      Import      25.00   1
    Handmade Basket     Import      8.99    4

    Box Arrowheads      Ammo        32.99   10
    10-pk Blk Cats      Ammo        15.47   20

    Table w/4 Chairs    General     29.99   2
    Kids Bicycle        General     53.75   1


Finally, used the following modified 'cart_ex.php' (please place it in your 'couch/addons/cart' folder) -

cart_ex.zip
(5.92 KiB) Downloaded 56 times

Using this mod, we get access to a variable named 'pp_custom_taxes' - an array that contains the breakdown of the taxes applied to the cart e.g.
Screenshot from 2024-11-20 19-45-46.png
Screenshot from 2024-11-20 19-45-46.png (29.95 KiB) Viewed 4644 times

I used the said variable as follows in my cart template -
Code: Select all
    <cms:if "<cms:pp_taxes />">
        <cms:each pp_custom_taxes>
            <tr class="row-extras">
                <td class="col-extras-label" colspan="4"><i>Taxes <cms:show key /></i>:</td>
                <td class="col-extras"><i>$<cms:number_format "<cms:show item />" /></i></td>
            </tr>
        </cms:each>

        <tr class="row-extras">
            <td class="col-extras-label" colspan="4">Taxes Total:</td>
            <td class="col-extras">$<cms:number_format "<cms:pp_taxes />" /></td>
        </tr>
    </cms:if>


I think this should be sufficient for you to tweak it to your liking.

Please test everything and let me know if there is something you need to be done differently.
Hello @KK,

This is great! I've tested this and worked it into my ecommerce site. Each new cloned page's title is the category and then the percentage of tax is the rate calculated. I created a "food/grocery" category with 0% and I see that no taxes are applied to the items added to that category. Each category, if there is a value, will list out in the subtotal section. I appreciate this addon. It gives my end user much more control over their sales inventory and opens up the products they can offer across the country and globally.

Earlier, I asked for a checkbox where the tax will be applied to the base price and not the discounted price. I thought my testing showed that taxes were applied to the discounted price. You assured me this is not the case and further testing showed this to be true, that the taxes are applied to the base price, not any discounted price. This is how it should be and how it is.

Thank you KK. I'd love to know any feedback from anyone else where different types of taxes are applied in different situations.
21 posts Page 2 of 3