Mailing List Archive

proposal: Interchange6 Cart costs change
Yesterday I started working on extending the Interchange6::Cart costs
framework to allow costs to be applied to cart products in addition to
the cart itself. One major issue that was discovered is the handling of
taxes along with discounts which is currently messed up. Having
discussed this with racke we now propose to change the way discounts are
handled.

Currently discounts can only be applied to the cart as a whole as a
negative cost. You may continue to do that if you wish but do NOT expect
that to work correctly with taxes. The new proposal is as follows:

Interchange6::Cart::Product will have the following attributes added:

discount
discount_percent
original_price
subtotal

With no discount applied 'original_price' will hold the same value as
'price' and both discount and discount_percent will be zero. Discount
can be applied to the product as it is added to the cart using ::Cart's
'add' method:

$cart->add({ sku => 'ABC', name => 'product1', price => 3.45,
discount_percent => 30, quantity => 2 });

This would result in a product like this:

{
sku => 'ABC',
name => 'product1',
original_price => 3.45,
discount_percent => 30
discount => 1.04
price => 2.41
quantity => 2
subtotal => 4.82
}

Rounding is performed as sprintf("%.2f", $number) on single unit price.

If a simple fixed discount amount in currency is required then the
following is also possible:

$cart->add({ sku => 'ABC', name => 'product1', price => 3.45, discount
=> 1, quantity => 2 });

This would result in a product like this:

{
sku => 'ABC',
name => 'product1',
original_price => 3.45,
discount_percent => 29.99
discount => 1
price => 2.45
quantity => 2
subtotal => 4.90
}

Rounding of discount_percent is applied in the same way as price in the
previous example.

If both discount and discount_percent are passed as args this will cause
an exception.

The subtotal attribute will have its value updated automatically
whenever quantity or discount/discount_percent is changed.

Cart-wide discounts effectively become per-product discounts. This is
essential for countries which charge varying rates of sales tax (e.g. EU
VAT).

A new ::Cart method will be added: apply_discount

This can be called with a single numeric as argument:

$cart->apply_discount(4);

This 4% discount is then applied to the current 'price' attribute of
each product and other attributes are then recalculated to reflect the
change. When applied to the second example above this would result in
this product:

{
sku => 'ABC',
name => 'product1',
original_price => 3.45,
discount_percent => 31.88
discount => 1.1
price => 2.35
quantity => 2
subtotal => 4.70
}

The following would produce the same result:

$cart->apply_discount({ discount_percent => 4 });

Currently there are no plans to allow a fixed amount of cart discount to
be applied though this is left as a possibility for the future if there
is demand.

In addition to the existing cart costs for taxes, handling, shipping,
etc we also now support per-product costs for the same uses. Product
costs are applied to the product subtotal in the same way that cart
costs are applied to the cart subtotal.

There is nothing to stop you from using the existing costs
infrastructure for discounts: just be aware that they are all applied to
subtotal so a combination of discount and tax costs may not produce the
total you are expecting.

This has NOT yet been implemented but it will be very soon unless there
are objections. Feel free to throw in you 1c worth.

Cheers
PeteM







_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: proposal: Interchange6 Cart costs change [ In reply to ]
On Wed, Sep 17, 2014 at 4:43 AM, Peter Mottram <peter@sysnix.com> wrote:
>
> Yesterday I started working on extending the Interchange6::Cart costs
> framework to allow costs to be applied to cart products in addition to
> the cart itself. One major issue that was discovered is the handling of
> taxes along with discounts which is currently messed up. Having
> discussed this with racke we now propose to change the way discounts are
> handled.
>
> Currently discounts can only be applied to the cart as a whole as a
> negative cost. You may continue to do that if you wish but do NOT expect
> that to work correctly with taxes. The new proposal is as follows:
>
> Interchange6::Cart::Product will have the following attributes added:
>
> discount
> discount_percent
> original_price
> subtotal
>
> With no discount applied 'original_price' will hold the same value as
> 'price' and both discount and discount_percent will be zero. Discount
> can be applied to the product as it is added to the cart using ::Cart's
> 'add' method:
>
- snip -

+1 for this idea! We do something very similar for our
coupon/discount processing in IC 5.x.

The only possible difference is that we always truncate the new
discounted price, rather than rounding. If we are advertising "10%
off" we want to be sure that the customer is always getting at least
10% off. So, a calculated discount price of $9.9975 would be $9.99,
not $10.00.


>
> Currently there are no plans to allow a fixed amount of cart discount to
> be applied though this is left as a possibility for the future if there
> is demand.
>

We also take a cart discount and apply it to each item in IC 5.X (so
the taxes will come out correct.) And, again, we want to make sure
our customers are getting the full discount amount, so a $10 off
coupon on a cart with 3 items will actually end up being $3.34 off of
each item, for a total of $10.03 discount.

Dan

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users