Skip to main content
12 votes
Accepted

How to order or filter entries by their author's custom field?

This requires a bit of extra work on the ElementQuery, but it can be efficiently done in the same query. We first perform an inner join on the author's content table using the authorId so that the ...
Ben Croker's user avatar
  • 7,631
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,837
5 votes
Accepted

Craft Commerce: Sort Products By Price

Close! This should do it: {% set products = craft.commerce.products({ relatedTo: (category), order: 'defaultPrice', }) %} With the quotes it's a string. Without the quotes, Twig is ...
Brad Bell's user avatar
  • 67.5k
4 votes

How do I set the value of a custom entries order field from a plugin?

I was close. I was correct in assuming my syntax was incorrect for setting the value of an entries field. Since an entries field is an array of elements, not just a single element, I just needed to ...
jthomas's user avatar
  • 373
4 votes
Accepted

Order PDF in back-end error with Globals

Since the templates are rendered on the server and not in a regular http request (in the front end templates), the globals are not loaded automatically, into the global twig namespace. You can still ...
Luke Holder's user avatar
  • 6,837
4 votes
Accepted

Creating a sitemap/index page, ordered by A-Z and 0-9

The way to do this is with the group filter. You want to group the entries by the first character of the title. Get the entries as an actual array {% set allEntries = craft.entries.section('artists')...
Marion Newlevant's user avatar
3 votes

Option and notes fields after cart at checkout for order, not just line items

First, add a custom field to your orders, let's call it orderNotes. Then, in any updateCart form, you can use an input with name="fields[orderNotes]" to set the value of that field. (Line items ...
Jeremy Daalder's user avatar
3 votes

Sort entry titles alphabetically excluding 'The'?

According to SUBSTRING, the first character starts at 1. So if you wanted to start at the position immediate after The (with one space), you'd need to start at position 5. Just did a test locally ...
Brad Bell's user avatar
  • 67.5k
3 votes

ElementAPI: How to order and/or limit results?

Just setting the limit property doesn’t do the trick alone, you need to deactivate pagination, too: 'criteria' => [ 'section' => 'trucks', 'limit' => 10, 'orderBy' => '...
medoingthings's user avatar
3 votes
Accepted

Decimals missing in result after adding up order totals for a customer

The trouble you are running into is trying to add a string value to an integer to get your total. You have to use order.totalPrice without the currency filter to be able to add all the values ...
Luke Pearce's user avatar
  • 3,863
2 votes

Order grouped entries

Stumbled upon this looking to answer similar problem. You should be able to do this now without a plugin, using the multisort filter where you iterate through your profiles, e.g.: {% for profile in ...
littlered's user avatar
2 votes
Accepted

ElementAPI: How to order and/or limit results?

This should do the trick: 'criteria' => [ 'section' => 'trucks', 'limit' => 10, 'order' => 'title asc', ] The Element Criteria Model documentation has more information ...
Stephen Lewis's user avatar
2 votes
Accepted

Sort entries by custom date in Matrix field / Super Table

I did something like this as a workaround: Loop over entries, fetching all data you need and adding it to an array. Sorting that array with SuperSort and than displaying all info by looping over the ...
Tom De Smet's user avatar
  • 1,456
2 votes
Accepted

Sort products by category field value

This doesn't work out of the box with Craft as the category field is a relation field. However you should be able to use SuperSort plugin. {% set products = craft.commerce.products.type('coins')....
pauliusef's user avatar
  • 163
2 votes

Craft Commerce: Sort products by Sale price

What about this: {# Catch your products as you wish, here is just an example #} {% set categoryProducts = craft.products().relatedTo({ targetElement: currentCategory, field: 'productCategory' }...
RomanAvr's user avatar
  • 669
2 votes
Accepted

Option and notes fields after cart at checkout for order, not just line items

You could create a special product for the gift wrapping and offer to add it to the cart during the checkout process with a separate updateCart form. As for the notes, you can add a custom field to ...
foamcow's user avatar
  • 2,029
2 votes
Accepted

User Order History Not showing Up in CP

The Order History is the history of that particular order and not designed to pull in other prior orders from that customer. You might want to make a feature request if you want to be able to see ...
Jeremy Daalder's user avatar
2 votes
Accepted

Placing a Test Order (Craft Commerce)

If you are using the example templates, the dummy gateway should be enough to submit an order. Are you displaying any error flash message from the payment controller? <div class="flash">{{ ...
Luke Holder's user avatar
  • 6,837
2 votes

what does {% set order = 'pin desc, postDate desc' %} do?

Craft uses the the template engine twig and there is a set tag that is the same as it's php equivalent for $order = 'pin...' So you just set/declare a variable - in this case you set the string.
Robin Schambach's user avatar
2 votes
Accepted

Order products by lowest product variant

I managed to resolve this using the supersort plugin and using 'defaultPrice' instead of 'price'. Example below: {% set products = craft.products.type('accommodation').all() %} {% set order = ...
Amy's user avatar
  • 407
2 votes
Accepted

How to create ordered list of categories from multiple category groups

You can query on multiple category groups like so: craft.categories.group('suitability, finish, shape, material, edge, surface').all() It can also be done with an array: craft.categories.group([ '...
Sam Hernandez's user avatar
2 votes
Accepted

Can I set a Commerce order custom field from a plugin

You can use $order->setContent() craft()->on('commerce_orders.onBeforeOrderComplete', function($event) { $order = $event->params['order']; $content = array('myCustomField' => 3); $...
phaetons's user avatar
  • 705
2 votes

Commerce 1 create a new order programmatically

To add orders programmatically, you can do so by using the Commerce_OrderModel class. Like so: $order = new Commerce_OrderModel(); $order->email = '[email protected]'; // Add your products here ...
José Veríssimo's user avatar
2 votes

Commerce 1: Different default order status based on product types

Edit: I'm sorry! I missed Commerce 1 in the title! This answer only applies to Commerce 2. Take a look at the defaultOrderStatus event! The description is a bit misleading—it's actually used to do ...
August Miller's user avatar
2 votes
Accepted

How to update the lineItemStatus of an order on the front end with twig?

You can use the same technique to set the line item data like this: {% set order = craft.orders.id(123).one() %} {% for lineItem in order.lineItems %} {% do lineItem.setAttributes({...
James Smith's user avatar
  • 5,344
2 votes
Accepted

Commerce new order error : mail::getRenderLanguage() must be of the type string

I think I figured out the problem. This was my first time switching to the project.yaml configuration Deleting and rebuilding the project config allowed me to change the Commerce > System Settings &...
Jack's user avatar
  • 31
2 votes

Commerce email receipt not sent after order, but manual Send Email in Order screen works

Simple step missing on the setup of this. I needed to actually assign this email to the status New, to send when a New order is placed, in the Order Statuses section, as per this documentation. So ...
Laurence Cope's user avatar
2 votes
Accepted

sort by checkbox field with multiple options and by postDate desc

The equivalent SQL would be something like SELECT * FROM players ORDER BY teamName IS NOT NULL DESC, postDate DESC; but I'm not sure how that would translate in a simple element query. It'd be ...
Wallace's user avatar
  • 611
2 votes

OrderBy section when selecting multiple sections in entries query

I've faced this a few times and solved it like this: {% set entries = craft.entries.section([ 'section1', 'section2', 'section3', ]).all() %} {# group the results by section handle #} {% ...
James Smith's user avatar
  • 5,344
2 votes
Accepted

Return all orders from a list of countries in Commerce v3

The Order element query joins the billing address, and you can access the table with billing_address so something like this should work. Order::find()->andWhere(['billing_address.countryId' => 1]...
Luke Holder's user avatar
  • 6,837

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