5

Try something like this: {% set currentDiscount = craft.commerce.getDiscountByCode(cart.couponCode) %} {% if currentDiscount %} {% set cartProductIds = [] %} {% for item in cart.lineItems %} {% set cartProductIds = cartProductIds|merge([item.purchasable.product.id]) %} {% endfor %} {% for product in currentDiscount.products %} {% if not product.id ...


2

Something like this? {% if item.discount %} <tr> <td>Your discount is {{ item.discount|commerceCurrency( currency ) }}</td> </tr> {% endif %}


2

(There can be only one code on a cart at any one time) Here's some example code that does the sort of thing you want: {% if cart.couponCode %} {% set coupon = craft.commerce.getDiscountByCode(cart.couponCode) %} {% endif %} {% if cart.totalDiscount or coupon is not null %} {% for adjustment in cart.adjustments if adjustment.type == "Discount" %} ...


2

You've sort of answered your own question - Commerce only allows one coupon on a cart at any time (currently). To determine if a coupon is set, and print the code, it's basically: {% if cart.couponCode %} {{ cart.couponCode }} {% endif %} You CAN have discounts applied as well as coupons, though. With those, you can look through with something like ...


2

Commerce 1: {% set paymentMethod = null %} {% for pm in craft.commerce.paymentMethods %} {% if pm.id == 2 %}{% set paymentMethod = pm %}{% endif %} {% endfor %} {{ paymentMethod.name }} Commerce 2: {{ craft.commerce.gateways.getGatewayById(2).name }}


2

The reason for the discount not being applied is that nearly all your products have not been marked as promotable (by looking at your database): Screenshot: http://jmp.sh/3FAK6NH No sales or discounts can be applied to a non-promotable product.


2

The following code can be used in the init method of a custom module. Event::on( View::class, View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE, function($event) { // Check query string for coupon code $couponCode = Craft::$app->getRequest()->getQueryParam('coupon', null); if ($couponCode) { // Check there is a ...


2

We will need to uncomment this line to allow |filter used in condition formulas: https://github.com/craftcms/commerce/blob/develop/src/services/Formulas.php#L198 If you do that manually yourself this formula works: order.lineItems|filter(v => (v.sku == 'BBB' and v.qty >= 3) ) You were missing the v. in front of qty. Look in the next version of commerce ...


1

The Commerce GUI doesn't let you set a whole cart discount but you can do it as an adjuster in a module/plugin. Setup the scaffolding for a module at pluginfactory then add a folder inside called the src folder adjusters and name it OrderAdjuster.php Throw this code in that file (modified from a another project): <?php namespace modules\yourmodule\...


1

Found the answer: in both discounts "Don’t apply any subsequent discounts to an order if this discount is applied" has to be active. and the discount with the higher value (in my case > 200$ -> 10%) has to be above the other discount in the control panel. and to check on the page itself, use the "update cart" button and not the ...


1

Got to bottom of this - is down to how the Tax Rules are set-up. Taxable Subject was set to Line Item but should have been set to Order Total.


1

In Commerce 1, craft.commerce.discounts will return an array of Commerce_DiscountModel objects of all available discounts. public function getAllDiscounts($criteria = []) { $records = Commerce_DiscountRecord::model()->findAll($criteria); return Commerce_DiscountModel::populateModels($records); } Commerce_DiscountModel objects have a dateFrom ...


1

I don't think avoiding an adjuster or plugin approach here really gains you anything much and it probably creates potential issues - it will likely just make the discount rules confusing as you can't really document the special conditions anywhere on those rules etc (and experience shows over time editors are likely to forget the special conditions and make ...


1

Hmm, something else is at play here. I use: {% if cart.totalDiscount != 0 or cart.couponCode %} - {{ cart.totalDiscount | currency(cart.currency) }} ...and it works. Are you sure the promotion is actually being applied? I guess it is if you can calculate the discount.


1

It would probably be best to make your own shipping adjuster. I have attached an example plugin here: http://jmp.sh/wC95ZPj The adjuster plugin I have linked can look at the weight of the cart, it's line item contents, and then reduce (or add to) the shipping costs after the regular shipping calculations are run.


1

For some reason the {% if item.discount %} isn't working for me. I've solved it by comparing the item.discount value. If not 0.0000 then it may show up {% if item.discount != '0.0000' %} {{"Discount"|t}}: {{ item.discount|commerceCurrency(cart.currency) }}<br> {% endif %}


1

So this is for coupons? If a coupon can't be applied during an updateCart, you'll get back the rather unhelpful response in JSON of {"error":"Cart not completely updated."} We intercept this, and because we know it's a coupon operation just replace the text of that to 'Could not apply coupon'. But it does not give you a reason or anything, unfortunately.


1

You can achieve this with a custom adjuster. Please refer the code snippet below. Create a new adjuster and apply your logic here // check each line item foreach($lineItems as $lineItem) { .... <your business logic here .... $discount_total = <amount>; } $order->baseDiscount = $order->baseDiscount - $discount_total; $myAdjuster->type = "...


1

As far as the release notes from Commerce 1.2: https://craftcommerce.com/changelog#build1323 It can only be given a minimum quantity of items now.


1

I have now updated this code for Craft Commerce 2: {% set codeError = null %} {% set cartProductIds = [] %} {% set discountCodeOK = null %} {# THIS CHECKS THE DISCOUNT CODE FOR IF THERE ARE ANY VALID/ELIGIBLE PRODUCTS IN THE CART #} {% set currentDiscount = craft.commerce.discounts.discountByCode(cart.couponCode) %} {% if currentDiscount %} {% for item in ...


1

So some persistence I have this working as follows: {% set currentDiscount = craft.commerce.getDiscountByCode(cart.couponCode) %} {% if currentDiscount %} {% set cartProductIds = [] %} {% set codeError = null %} {% for item in cart.lineItems %} {% set cartProductIds = cartProductIds|merge([item.purchasable.product.id]) %} {% endfor ...


Only top voted, non community-wiki answers of a minimum length are eligible