23 votes
Accepted

Why choose Craft Commerce over Magento

Obviously it's going to depend on each specific project, and I can only talk from my own (store owning) perspective, but over the years I have evaluated and installed and played with just about every ...
Jeremy Daalder's user avatar
12 votes
Accepted

How can I update custom order fields in the frontend

Correct, you need to use fields[customFieldName] as the input name. The following form should do it: <form method="POST"> <input type="hidden" name="action" value="commerce/cart/...
Luke Holder's user avatar
  • 6,767
11 votes
Accepted

Using Commerce to pay for posting entry

You will need to write a plugin with three responsibilities: Keep track of which entries have been purchased Set an entry to enabled when it has been purchased Ensure that entries always have the ...
Brandon Kelly's user avatar
9 votes
Accepted

Craft Commerce: Detecting & Styling Flash Messages?

Getting a flash message also deletes it, so you should set it to a variable first, otherwise, when you try to access it a second time, it will be empty. So you need to do something like this: {% set ...
Steve Rowling's user avatar
9 votes
Accepted

Commerce & PayPal - What does "Solution Type" mean?

Ignore the terminology, it really makes no sense. What it should say is this... Require customers to use a PayPal account? [Sole] No, a PayPal account is optional. Customers can still choose to pay ...
Lindsey D's user avatar
  • 23.9k
9 votes
Accepted

Structuring products variants

Usually when selling goods that come in different size and colors, a different SKU would exist for any size/color combination that you sell, thus a unique variant. So, when that item becomes low in ...
Luke Holder's user avatar
  • 6,767
8 votes
Accepted

Order Confirmation Email in Craft Commerce

To setup/debug email issues in commerce it's easiest to set up the simplest possible email and work your way up from there. Check your Craft email settings - can you send & receive the test email ...
Jeremy Daalder's user avatar
8 votes
Accepted

Craft Commerce: Dynamic Product Price

[** Updated Dec 2016] I think at this stage the best approach will be plugin based. Create a business logic plugin if you haven't already. Two good ways of doing that are : Business Logic Plugin ...
Jeremy Daalder's user avatar
8 votes
Accepted

Update Commerce Cart using Ajax

Yes, you can do all the normal commerce actions via ajax. How this is done changed slightly with Craft 4/Commerce 4, so use the appropriate approach below. (Basically, they used to use an attribute ...
Jeremy Daalder's user avatar
8 votes

Craft Commerce not sending E-Mails immediately

Thanks to @PhilipBoomy for his answer. The problem were missing cron jobs. Additionally I want to add one more solution from the craft support team: If you don't have the queue set up to run ...
pepe's user avatar
  • 315
7 votes
Accepted

3 for 2 etc with Craft Commerce

The documentation for adjusters is here: https://craftcommerce.com/docs/adjusters and https://craftcommerce.com/docs/order-adjustment-model Essentially your plugin creates a class that fulfils the ...
Jeremy Daalder's user avatar
7 votes
Accepted

Ordering of products?

Product types are really all about data concerns - so if the data you're storing for your canines/equines (hereafter known as dogs and horses to save some typing ;) ) - is the same, then you're right ...
Jeremy Daalder's user avatar
7 votes
Accepted

Check if an order has been refunded in a template?

You get the related transactions for an order with order.transactions So you can loop over the transactions like so: {% for transaction in order.transactions %} {{ transaction.type|title }} {{ ...
Luke Holder's user avatar
  • 6,767
7 votes
Accepted

One-Page Commerce Checkout

You won't be able to collect all information and take payment using one form/action. The customer information is added to the cart using commerce/cart/updateCart and payment is processed using ...
Luke Pearce's user avatar
  • 3,863
6 votes
Accepted

Display custom product field in cart

You could set a variable to access the products model like so: {% set product = item.purchasable.product %} and then access the fields like normal {{ product.myCustomField }} The snapshot holds the ...
Luke Pearce's user avatar
  • 3,863
6 votes
Accepted

Craft Commerce: Displaying Individual Product Options in the Cart?

Answer is the example code for the cart: {{ item.options.giftWrapped }}
Dan Lee's user avatar
  • 1,107
6 votes

Craft Commerce: Detecting & Styling Flash Messages?

You can use hasFlash() instead, or pass false as a third argument, otherwise the flash message is discarded after the first time it is accessed. {% if craft.session.getFlash('notice', null, false) %} ...
Mike Pepper's user avatar
  • 4,391
6 votes
Accepted

Craft Commerce: Sub total before tax in cart?

As of Commerce 1.1.1212, cart.itemSubtotalWithSale is deprecated. Use {{ cart.itemSubtotal|currency(cart.currency) }} instead. {{ cart.itemSubtotalWithSale|currency(cart.currency) }}
jhanshew's user avatar
6 votes

Craft Commerce: Validation on Address Fields

In Craft3 you can do it like this: use Craft; use craft\base\Plugin; use craft\commerce\models\Address; use yii\base\Event; class Custom extends Plugin { public function init() { ...
cornernote's user avatar
6 votes
Accepted

Cart Items Total to include qty of variants

You can get the total quantity of items with: cart.totalQty Docs: https://craftcommerce.com/docs/order-model#totalqty
Luke Holder's user avatar
  • 6,767
6 votes
Accepted

Transaction Error Message in Template

The error messages are returned to the template as flash messages. Handling those is documented here: https://craftcms.com/docs/templating/craft.session One thing to watch out for is that flash ...
Jeremy Daalder's user avatar
6 votes
Accepted

Setting Shipping Country and Method for the Cart screen

I agree with the basic underlying premise that showing full cost - i.e. with shipping - is essential on the cart index page for a modern checkout. Customers loathe what they see as a hidden surprise ...
Jeremy Daalder's user avatar
6 votes
Accepted

How do I check if a product has stock in any of it's variants?

I managed do this with the following: {% set variants = craft.commerce.variants({ product: product, hasStock: true }) %} {% if variants|length <= 0 %} Sold out {% else %} Add to ...
Luke Pearce's user avatar
  • 3,863
6 votes
Accepted

Changing base currency

Click on USD under Commerce->Settings->Payment Currencies and change the dropdown from USD to EUR. That will become Commerce's new base/primary currency. If you also want to support USD, you can add ...
Brad Bell's user avatar
  • 67.2k
6 votes
Accepted

Custom status based on chosen payment gateway

Listen for the onBeforeOrderComplete event and do something like this (replacing values to match your setup). craft()->on('commerce_orders.onBeforeOrderComplete', function($event){ $order = $...
Jamie Pittock's user avatar
6 votes
Accepted

Set Entries field in Commerce order on completion

See What is getContent() / the ContentModel, and how do I use it to get and set custom field values? So you needed to change the method used for setting content on an element. Also see In a plugin, ...
Luke Holder's user avatar
  • 6,767
6 votes

How do you reset a cart under Craft Commerce 2?

Depending on context, here's another handy way of clearing the cart for Commerce 2/3 In a template, you can put: {% do cart.setLineItems([]) %} {% do craft.app.elements.saveElement(cart) %} You ...
Jeremy Daalder's user avatar
6 votes

Need somebody to help us with our existing Craft web page

Sorry to hear about your disappearing developer. Stack Exchange as a Q&A site usually isn't the best place to find a developer, unless you'd like to post to Stack Overflow Jobs (https://...
Brad Bell's user avatar
  • 67.2k
6 votes
Accepted

Commerce: what is the purpose of a line item's snapshot?

The snapshot is there so that the key details of an order are forever more available on the order record. Imagine living with Commerce for a long time - you will of course most likely add, change and/...
Jeremy Daalder's user avatar
6 votes
Accepted

Get order shipping address in module

You can use the Addresses service to get the shipping address: $address = craft\commerce\Plugin::getInstance()->getAddresses()->getAddressById($order->shippingAddressId); This is the more ...
Martin Spain's user avatar
  • 1,484

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