Forum

Thread tagged as: Problem, Shop

Empty discount variables on result page

I'm trying to display free shipping discounts on my order result page with:

<perch:if id="total_discounts_with_tax_formatted" match="gt" value="0.00">
<dt>Discount (<perch:shop id="discount_code" />)</dt>
<dd>- <perch:shop id="total_discounts_with_tax_formatted" /></dd>
</perch:if>

But only the voucher code is display correctly, the discount value is 0

Discount (FREESHIPPING)
- £0.00

Looking at <perch:showall /> I can see that some of the variables are at 0, even though the order* variables have values. eg:

orderShippingSubtotal   2.49
orderShippingDiscounts  2.49
orderShippingTax    0.50
orderShippingTaxDiscounts   0.50
orderShippingTotal  2.99
orderDiscountsTotal 2.49
orderTaxDiscountsTotal 0.50

But these are all 0:

total_shipping_discount 0.00
total_shipping_discount_formatted   £0.00
total_shipping_tax_discount 0.00
total_shipping_tax_discount_formatted   £0.00
total_tax_discount  0.00
total_tax_discount_formatted    £0.00
total_discounts 0.00
total_discounts_formatted   £0.00
total_discounts_with_tax    0.00
total_discounts_with_tax_formatted  £0.00

Should these be populated, or should I be using the order* variables?

If I should be using the order* variables, could I put a feature request in for the variables to match, so there's an equivalent to total_discounts_with_tax_formatted, orderDiscountsWithTaxFormatted for example.

Diagnostic report:

    Perch Runway: 3.0.14, PHP: 7.2.6, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $, with PDO
    Server OS: Darwin, fpm-fcgi
    Installed apps: content (3.0.14), assets (3.0.14), categories (3.0.14), perch_blog (5.6.1), perch_forms (1.10), perch_shop_orders (1.2.5), perch_shop_products (1.2.5), perch_shop (1.2.5), perch_members (1.6.2)
    App runtimes: <?php $apps_list = [ 'perch_forms', 'perch_members', 'perch_shop', 'perch_blog', ];
    PERCH_LOGINPATH: /juniper
    PERCH_PATH: /Users/garrettc/sandbox/collagin/htdocs/juniper
    PERCH_CORE: /Users/garrettc/sandbox/collagin/htdocs/juniper/core
    PERCH_RESFILEPATH: /Users/garrettc/sandbox/collagin/htdocs/juniper/resources
    Image manipulation: GD
    PHP limits: Max upload 20M, Max POST 20M, Memory: 128M, Total max file upload: 20M
    F1: 3b606135b33e6a102526838f4152a807
    Resource folder writeable: Yes
    SCRIPT_NAME: /juniper/core/settings/diagnostics/index.php
    REQUEST_URI: /juniper/core/settings/diagnostics/
    DOCUMENT_ROOT: /Users/garrettc/sandbox/collagin/htdocs
    HTTP_HOST: collagin.local
Garrett Coakley

Garrett Coakley 0 points

  • 3 years ago

I've been doing some more testing this morning, and a promotion that offers a discount on the main price, either by percent or fixed price, does display the correct discount on the results page. So it looks like this is just limited to free shipping vouchers.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'd suggest comparing on 0 rather than 0.00, which PHP might be interpreting as a string.

Sorry Drew, I wasn't clear enough.

(I did try changing the comparison, but that didn't change the behaviour, I'm seeing).

I want to have one check on the results page to display any promotions against the order, whether they are free shipping or against the item price.

total_discounts_with_tax_formatted seemed to be the correct variable to check, and it does work with a promotion against the main price.

It doesn't seem to work with a free shipping promotion though.

In the example above with a free shipping promotion the order* variables for total discounts are populated, but the relevant total_* variables are empty:

orderDiscountsTotal 2.49
orderTaxDiscountsTotal 0.50

[...]

total_discounts 0.00
total_discounts_formatted   £0.00
total_discounts_with_tax    0.00
total_discounts_with_tax_formatted  £0.00

Compared to an order with a promotion applied to the main item price, and both are populated:

orderDiscountsTotal 0.50
orderTaxDiscountsTotal  0.10

[...]

total_discounts 0.50
total_discounts_formatted   £0.50
total_discounts_with_tax    0.60
total_discounts_with_tax_formatted  £0.60

Feels like a bug. Unless I'm missing a difference between free shipping and item discount promotions?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Shipping is calculated separately from the order totals and discounts. You should be able to see shipping costs when those are applied. Shipping isn't a product in the cart, and it's often based on what's in the cart, so they can't be the same.

Okay, so on the results page and confirmation email it's best if I stick with the order* variables?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't understand at all.

Maybe I'm over-explaining (this heat!)

The behaviour of the total_discounts_* variables differs before and after checkout.

cart_static.html displays totals on the "checkout" page, before checkout:

<h1 class="title">
    <perch:content id="page_title" type="hidden" />
</h1>
<table class="cart">
    <tr>
        <th class="item">Item</th>
        <th class="quantity">Quantity</th>
        <th class="price">Price</th>
        <th class="total">Total</th>
    </tr>
    <perch:cartitems>
        <tr>
            <td>
                <b><perch:cartitem id="title" /></b>
                <p>
                    <perch:cartitem id="variant_desc" />
                </p>
                </p>
            </td>
            <td>
                <perch:cartitem id="quantity" />
            </td>
            <td class="money">
                <perch:cartitem id="price_with_tax" format="$:%.2n" />
            </td>
            <td class="money">
                <perch:cartitem id="total_with_tax" format="$:%.2n" />
            </td>
        </tr>
    </perch:cartitems>

    <perch:if id="shipping_with_tax" match="gt" value="0.00">
        <tr class="total">
            <th colspan="3">
                Shipping
            </th>
            <td class="money">
                <perch:shop id="shipping_with_tax_formatted" />
            </td>
        </tr>
    </perch:if>

    <perch:if id="total_discounts_with_tax" match="gt" value="0.00">
        <tr class="total">
            <th colspan="3">
                Discount (
                <perch:shop id="discount_code" />)
            </th>
            <td class="money">
                - <perch:shop id="total_discounts_with_tax_formatted" />
            </td>
        </tr>
    </perch:if>

    <tr class="total">
        <th colspan="3">
            Grand total
        </th>
        <td class="money">
            <perch:shop id="grand_total_formatted" />
        </td>
    </tr>
</table>

items.html displays the totals on the "order success" page after checkout:

<dl>
    <dt>Order ID</dt>
    <dd><perch:shop id="orderID" /></dd>

    <dt>Date</dt>
    <dd><perch:shop id="orderCreated" type="date" format="d F Y H:i" /></dd>

    <dt>Shipping</dt>
    <dd><perch:shop id="shipping_with_tax_formatted" /></dd>

    <perch:if id="total_discounts_with_tax" match="gt" value="0.00">
    <dt>Discount (<perch:shop id="discount_code" />)</dt>
    <dd>- <perch:shop id="total_discounts_with_tax_formatted" /></dd>
    </perch:if>

    <dt>Total</dt>
    <dd><perch:shop id="grand_total_formatted" /></dd>

    <dt>Status</dt>
    <dd><perch:shop id="orderStatus" format="UC" /></dd>
</dl>

I'm using <perch:shop id="total_discounts_with_tax_formatted" /> in both files.

Using <perch:showall> to list all the variables available with a free shipping promotion, this is what I see (I've cut out lots of variables for brevity):

# These are correct
orderDiscountsTotal 2.49 
orderTaxDiscountsTotal 0.50

[...]
# These are all empty
total_discounts 0.00
total_discounts_formatted   £0.00
total_discounts_with_tax     0.00
total_discounts_with_tax_formatted  £0.00

The total_shipping_discount_* and total_discounts_* values aren't being populated with any values.

My confusion is this:

In the cart, before checkout, I can use total_discounts_with_tax and it will show any discount applied, for both a free shipping promotion, or an item discount promotion.

On the success page, after checkout, total_discounts_with_tax behaviour has changed, and it only has a value if the promotion was an item discount.

Does that make my problem clearer?

Hi, any further thoughts on this?