Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
3

Indigo Viking's code will achieve what you want, but if you want a simpler solution (possibly a bit more performant since there's no second for loop), you could do this instead: {% set suitability = craft.categories.group('suitability').all() %} {% for category in suitability %} <dt class="data-list__item data-list__item--title"> {{ ...


3

I think you're misunderstanding what with does. Or I am. Ha! From what I understand with is for eager loading, but doesn't control anything in the relation itself. I don't think your relation makes any sense either because all you'll do is substitute a string into your spec variables. Try something more like: {% set products = craft.commerce.products({ ...


3

I think what you want here is the union of (products related to a or b) and (products related to c, d, or e). One good way to do these more complicated queries is to construct a set of the ids, and then do your final query based on that. So, we will get the ids of products related to a or b: {% set aOrBProductIds = craft.commerce.products({ relatedTo: ...


3

Your product element criteria is using a condition param: hasVariants, but it should be hasVariant as per the docs: https://craftcommerce.com/docs/craft-commerce-products#hasvariant That correctly only returns products (where a variant that belongs to that product) is in stock.


2

This should work: {% set image = block.chooseProduct.first().mainProductImage.first() %} Explanation: your field handle in your product is called recommendProduct (matrix) that contains a relation chooseProduct. Your block.chooseProduct is an object of type ElementCriteriaModel so in order to fetch the product you need to call the first() method (or ...


2

Found the answer. When creating the where clauses for the query, there's a line that checks empty($str), so passing a false boolean value, PHP interprets it as an empty string, so the where clause doesn't get created. So I fixed it by changing the query param to hideInEurope: 'false'.


2

After Marion Newlevant suggested the merging of arrays of productIds instead of doing complex relatedTo parameters, I modified my code to read as follows: {% if rangeCategories|length or sizeCategories|length or colourCategories|length %} {% set productIds = [] %} {% set rangeProductIds = "" %} {% set sizeProductIds = "" %} {% set ...


2

In Craft Commerce? promotable (true or false) Is this product and its variants able to be on sale or at a discount. https://craftcommerce.com/docs/product-model#promotable


2

I think you just need to create a dynamic route to either ignore customise/ in the url or serve up a different template altogether. See my answer on this ticket for more information. Secondary Template for Structure


2

I am sure you've worked this out by now, but in general terms, how you build this is entirely up to you, in front end terms. You can make it as fancy or as simple as you like, in terms of the UI. From simple checkboxes to some totally flash JS based UI, it's entirely up to you, as long as the form then submits the right values. You can display any fields ...


2

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').limit(null) %} {% set orderedProducts = products | supersort('sortAs', '{stateCat.first.stateImportance}' %}


2

{% set suitability = craft.categories.group('suitability').all() %} {% for category in suitability %} <dt class="data-list__item data-list__item--title"> {{ category.title }} </dt> <dd class="data-list__item data-list__item--value"> {% for selectedCategory in product.suitability.all() %} {% if ...


1

Try something like this: {% set found = false %} {% set orders = craft.orders() .customer(craft.commerce.customer) .all() %} {% for order in orders %} // here you could / should also check if the order was paid {% for lineItem in order.lineItems %} {% if lineItem.purchasableId == yourProductId %} {% set found = true %} ...


1

First you need to figure out which one you are using. LineItem Options: Here is the doc for it. https://docs.craftcms.com/commerce/v2/adding-to-and-updating-the-cart.html#line-item-options-and-notes One thing worth to mention is that options store in lineItem, which is one set of options for each purchasable/variant. So in your form you should put the ...


1

I've tried the following, but it "obviously" gives me duplicate rows and my SQL and Craft/Yii knowledge isn't good enough to solve it. It's basically its own subquery with no relation to the "filters" in the query above, except for the title. I'm thinking that I could innerJoin on the initial subquery (which is the query/result from above) but don't know how ...


1

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 exactly what you've described: alter the "default" completed order status in situations where it might not be desirable. From the docs: use craft\commerce\...


1

It looks like I'm trying to use variants the way options can be used. I'm going to go with options.


1

Have figured out that instead of setting a template path in my product type I can leave that blank and use a custom route instead. So in this case I set up a route for /type/*/* -> shop/variant It means I need to fetch the product entry manually in the template but that's no problem and it seems to be working.


1

Ended up creating a custom plugin to achieve this functionality. Also added some custom pagination logic. Set up a gist showing the variable and service files of the plugin as well as an example twig template to output the results. https://gist.github.com/matt-adigital/e79b2fd2e14327b3f306a907f4e7e02e All working well but it would be great if this was in ...


1

Unfortunately you would need to do 2 element query searches and combine the results on the front end. Most developers tend to go for https://algolia.com when they want fast advanced search, including searching across elements. Probably easiest to get started by searching for an Algolia plugin in the plugin store. I only know https://github.com/Rias500/...


1

Probably the most Craft-y way would be to use categories for classification and set your categories to have URLs. Alternatively, you could do this with a route that points shop/* (ie. shop/{some token} - at a template, say shop/product_type and in that template use the second segment of the url in retrieving products of the appropriate type (or, of course, ...


1

As Wonko said above, our fine art printing section (actually all our service sections) - are examples of the sort of thing you can do. The article mentioned is more of a Monkey Magic like epic quest to peace and redemption that an How-To though ;) ! It seems quite complicated but usually if you break it down you will find a lot of the data in forms like ...


1

I can't see this being a problem. All variants can have their own pricing. You can also use relations to mix and match different things if you'd like. There is a fine art printing section on the Image Science web site that may be an example of what you are thinking. There is a full write up of what it took to create the web site here: The Epic Journey to ...


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