Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-06-06 04:41:36

code365
Member
From: California
Registered: 2009-08-16
Posts: 110
Website

Multi-able Item

Hi,

I am building a simple product website. Trying to figure out if possible with txp to have the same item (article) to have multi-able colors and id for each item.

Thank you.

Offline

#2 2020-06-06 06:54:58

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: Multi-able Item

Can you tell us more about what you mean with “multi-able colors”?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2020-06-06 08:00:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: Multi-able Item

Yes with custom fields and pageless sections. Untested, but you could:

  1. Create your main article in your products section.
  2. Create a second section with no page assigned to it called product-variants.
  3. Define each variant as its own article in the product-variants section. E.g. title them “Cashmere sweater (navy blue)” just so you don’t get duplicate title warnings. The body can describe the product fully, or just its differences compared with the main one.
  4. Define a custom field Colour.
  5. In your variants articles, put the colour name in the Colour custom field.
  6. In the main article, list the IDs of the article variants in the Colour custom field. This ties your main article to the relevant (hidden) variants.

You can then use article_custom to pull out the variants by passing in the Colour custom field to the id attribute:

<txp:article_custom id='<txp:custom_field name="colour" />' section="product-variants">
Display some stuff from each variant in form fields.
</txp:article_custom>

As long as you use the id somehow in your form field value (e.g. in your colour select list you build) then you’ll know which variant was picked when submitted.

Note for bonus points that each variant can have its own article image and description which you could display on change of the select list. Either via some JS or an Ajax call back to the DB to fetch the relevant variant.

Hope that gets you started. Please share your journey here, as I’d love to find out how well this works and if we can do anything to improve core in this endeavour.

(Aside: this only works for one variant. If you wanted to vary on two custom fields like size and colour, it gets tricky. Would need some more thought here.)

Last edited by Bloke (2020-06-06 08:04:41)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2020-06-07 19:42:23

code365
Member
From: California
Registered: 2009-08-16
Posts: 110
Website

Re: Multi-able Item

Thank You Colak and Blok for your awesome help.

Offline

Board footer

Powered by FluxBB