Jump to content
charger

Matrix/table built with children of two pages

Recommended Posts

I don't now if this is already possible to build with one of the available modules/fieldtypes. I so far tried Table, PageTable, Repeater and Multiplier but couldn't get them work exactly as I want.

I'm looking for a way to create a matrix/table that uses the children of two pages to build the row and column headers. In my case (an online shop), I want it to take the children of the page product variants and the children of the page currencies. In the end, it should render a matrix/table, where I can enter a fixed price for every variant in every currency.

Has anyone ever done something similar? Is there a fieldtype for this?

Share this post


Link to post
Share on other sites

Not sure what you want to archive with that but I think there is a better way to solve that. So could you add some more details?

Share this post


Link to post
Share on other sites

@charger

Have you considered just keeping everything in a single currency and using something like Ryan's currency conversion module to create other currency prices on-the-fly as needed?

That's a good idea, however, I don't want automatic price conversion. Price politics is more about psychology than mathematics ;)

  • Like 2

Share this post


Link to post
Share on other sites

Not sure what you want to archive with that but I think there is a better way to solve that. So could you add some more details?

I want to be able to set the price of a product (e.g. a T-Shirt) by its category (well, T-Shirts). Now for all products within the category T-Shirts, there are the same options (size S, M, L and color red, green, blue). So if I go to the category page of T-Shirts, I want a matrix that lists all the options of this product category and then let me set a price for each currency I'm offering the product in. I hope that's understandable :)

Share this post


Link to post
Share on other sites

Thanks for the tip, but I don't think that module can help me. It doesn't create the rows/columns based on the children of pages (so that I can add another child page and that the matrix would be extended automatically). If I would do it manually, I would prefer the fieldtype table.

Share this post


Link to post
Share on other sites
I want to be able to set the price of a product (e.g. a T-Shirt) by its category (well, T-Shirts). Now for all products within the category T-Shirts, there are the same options (size S, M, L and color red, green, blue). So if I go to the category page of T-Shirts, I want a matrix that lists all the options of this product category and then let me set a price for each currency I'm offering the product in. I hope that's understandable

I am still not 100% clear, but it sounds to me like maybe you don't want a new way of storing product/price info, but just a new way of entering it. It sounds like you still want the data stored in the product's page fields. Is that correct?

If so, you might be looking at implementing something custom with AdminDataTable (core module often used by other modules), or HandsOnTable. Here are a couple of links for inspiration:

http://modules.processwire.com/modules/data-table/

https://processwire.com/talk/topic/4147-excel-like-crud-in-pw-using-handsontable/

and of course the ProTable field type. 

I think with ideas from those you could build a process module that builds an editable table using the product/price info from the fields from product pages. When saving the table, the data would be written back to the appropriate pages.

Am I on track at all?

  • Like 1

Share this post


Link to post
Share on other sites

It might help if I add a screenshot of what it looks like if it's manually built with the fieldtype table. The downside is that I have to create all possible variations by hand, and that if I add a new currency or a new product option, it's not populated automatically to this table.

One solution (at least for the product options size and color) to this would be if the fieldtype table would allow columns to be of the type page and then output them as radios/checkboxes.

It would be even cooler of course if the variants (all possible combinations of the product options size and color) would also be built automatically ;)

post-2284-0-06979500-1412440640_thumb.pn

Share this post


Link to post
Share on other sites

It sounds like you still want the data stored in the product's page fields. Is that correct?

No, the product itself (T-Shirt) is assigned to a category (T-Shirts), and all the pricing information is stored within the category page.

  • Like 1

Share this post


Link to post
Share on other sites

It really sounds like you want ProFields, the table plugin is extremely flexible. Are you wanting to make changes to all of you separate pages via one template, or are you still wanting to edit all of the pages directly?

Share this post


Link to post
Share on other sites

It really sounds like you want ProFields, the table plugin is extremely flexible. Are you wanting to make changes to all of you separate pages via one template, or are you still wanting to edit all of the pages directly?

As I mentioned at the beginning, I already tried to use the ProFields Table, Multiplier and Page Table. The screenshot in my post above is actually from the ProFields Table fieldtype.

It should be one template in the end that I can use on different pages (-> product categories).

Share this post


Link to post
Share on other sites

Are you basically creating a main page and the variants are children of that page?

So, they all have the same prices, for instance, but other variations are possible with the children?

If so, you could do something like this:

Parent - T-Shirts

Field: Default price (USD)

Child page - 

T-shirt crazy style

Field: override price (USD) - normally left blank.

In your template for the child, you can call the price from the parent page (see the API for parents), checking whether the override price as been set. If it hasn't you display from the parent, if it has been set, you display from the child.

You can do this will any field - set defaults in the parent, but allow for overrides for the children.

  • Like 1

Share this post


Link to post
Share on other sites

I'm not sure if I can follow your example. Let me add another screenshot to clarify my setup. I have a product page (T-Shirt) that is displayed on the frontend. Then, there's the Tools page (only for backend), where I define a products attributes and categories.

Now, within the page T-Shirts (which represents a product category) I want to be able to have the table I mentioned above where I can set the prices for each product variant of the attributes size and color – pretty much as in my other screenshot above.

The product page T-Shirt then actually just has a drop-down to select a product category (in this case T-Shirts).

post-2284-0-83345600-1412457938_thumb.pn

Share this post


Link to post
Share on other sites

Okay, I am probably going to get this wrong, but let me think this through.

You want a list of attributes, but without prices - you add the price later in the T-Shirt page?

So, for instance, you could have a repeater (possibly better with a page table) that has two fields:

Page Field, picking up a list of attributes and a text field for the price.

You add a line, choose the attribute type from the page field drop down (must be single select, of course) and you put in your price.

You can then loop through the repeater to list out all the attributes and associated prices for that product..

When it comes to a category, if you are creating the product page under its parent, then it already has a category - its parent! :)


Oh, I should add, that the attributes can have more than just a title - they can have images, extra info, anything you like as they are pages in their own right - but you only use the title field when selecting them.

  • Like 2

Share this post


Link to post
Share on other sites

I think we got tangled up in my use case. Maybe I have to go back to the beginning, because what I'm looking for has different use cases in my opinion.

What I'm looking for is to have some kind of matrix fieldtype where I can define the row and column headers. Now, these headers should automatically be built by the page title of definable pages (actually their respective child pages).

Say I have two pages (Size and Color) with the following child pages:

Size

   – S

   – M

   – L

 

Color

   – Red

   – Blue

   – Green

Now in this matrix fieldtype, I could apply Size to be the row header and Color the column header. This would result in a matrix like this:

   | Red | Blue | Green |

–––––--------------------

S  |     |      |       |

–––––--------------------

M  |     |      |       |

–––––--------------------

L  |     |      |       |

–––––--------------------

 
Now, if I add another child to the page Color (e.g. Black), the matrix would be automatically extended: 

   | Red | Blue | Green | Black |

–––––----------------------------

S  |     |      |       |       |

–––––----------------------------

M  |     |      |       |       |

–––––----------------------------

L  |     |      |       |       |

–––––----------------------------

Is there already a fieldtype like that?

Share this post


Link to post
Share on other sites

OK, let me wade in as well :-)

@Charger,

I don't think there is a module like that. Does this have to be a fieldtype or would a ProcessModule do? i.e. a custom view/page within the admin. The table cells would be input fields that contain any data you want. This is a similar idea to what Adrian mentioned above. The ProcessModule would just be a means of easily entering your data but these would be stored within the fields of your pages themselves. The advantage with this approach is that you could have a table of all your products, then clicking on an edit button/link would bring up the matrix. This would be built on the fly based on the number of your 'child pages'...Anyway, just thinking out loud here...

  • Like 1

Share this post


Link to post
Share on other sites

Hmmm...

Creating the matrix is the easy part. The problem is deciding where and how that data will be stored. At the end of the day you want to be able (preferably) to easily query your data using PW API, say find the price of 'small red' t shirts.... The problems with my solution are, e.g. where do you store the price of a 'Large Blue' t-shirt? If you had a fixed number of variations, fine, but in your case they are dynamic. A 'pink' variant can be added later and you want to be able to accommodate that...hmm...

Maybe the fieldtype route is the way to go :-). I am not sure how Martijn's FieldtypeJson works but it seems to be able to accommodate any number of columns. If you want to go down that route, then you can adjust that Fieldtype to suit your use case. It's a matter of rewriting the code and renaming the module class. Of course, you need to know what you are doing... :-). There's also Ryan's event fieldtype that could be modified to do what you are after...

Share this post


Link to post
Share on other sites

Me again... :-)

Will your product sizes be fixed, i.e, always S, M, L? If yes, can your matrix be like this instead?

           |  S  |  M   |  L   |
–––––------------------------
Red   |      |        |       |
–––––------------------------
Blue    |     |        |       |
–––––------------------------
Green  |     |       |       |
–––––------------------------
Black   |     |       |       |
–––––------------------------
 
meaning....only add rows with new variants but columns will be fixed...
  • Like 1

Share this post


Link to post
Share on other sites

@kongondo,

I like the thinking but you never know when an extra X will get added to a size; particularly medium. In other words, I suspect the table would need to accept changes in either dimension.

How about simply concatenating the x and y variable to give a key that can then have a simple value stored against it? So you'd end up with a table that had an indexed product page id, an indexed "key" and an "amount" column. The function to make the key would just do something like...

function makeKey($size, $variation)
{
    $size      = wire()->sanitizer->name($size);
    $variation = wire()->sanitizer->name($variation);

    $key = "$size/$variation";

    return $key;
}
  • Like 2

Share this post


Link to post
Share on other sites

@Steve,

Good point. I was thinking along those lines (the indexed key) but wasn't sure how search would work (i.e. grab 'red small' t-shirts) using PW API and related performance issues. Back then, I was thinking storing the pairs using json like syntax $size:$variation - something similar to yours. 

Share this post


Link to post
Share on other sites

@Steve,

Just to answer my own question about how the search for the 'indexed key' would work [database side of things] - this could either work  the way PW handles repeater fields - data stored as comma separated integers (1234, 5688), i.e. $size,$variation ID pages respectively as you suggested, or why not store them as PW multiple page fields - i.e. a row for each addition, consisting of page id (integers) i.e. 

E.g. assuming Red = ID 1124, small = 2545 and medium = 2745

$variation    $size   $amount

1124           2545    $20

1124           2745   $10

On the inputfield side of things, the user will still be able to see a table similar to the one I posted above that would grow both vertically and horizontally with each new addition of size and variation...Of course horizontal growth could get very messy very quickly... :-)

Edited by kongondo
  • Like 2

Share this post


Link to post
Share on other sites

Wow, lots of action here :) I'm sorry, but I can't keep up with the discussion. It's too low-level for me. I don't know the interns of PW that well yet. But I'm happy to help where I can.

Share this post


Link to post
Share on other sites

Hi Charger,

I thought you'd given up on this given your absence :P   :-)

I'd started to work on something (it was actually working, i.e. dynamically adding rows and columns - except for saving to the DB) but then I hit a few snags and was wondering whether this wouldn't be best achieved by a dedicated ProcessModule or an extended PageTable....If you are about later, I could try and explain...

ps: low-level or high-level?? :unsure: 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!
    • By Jeannette
      Hello Fellows,

      I have a wonderful webshop, using PL and Padopt, a module developed by Julien Vaubourg and highlighted in ProcessWire Newsletter. Here is our shop: cheval-ami.fr
      I am looking for a new developer, helping me to keep the shop smooth and up to date.
      We would like to improve automated invoicing and worldwide shipping, getting DHL integrated and give people the possibility to create their personal accounts and be the nicest shop in the equine industry. We are still a young company, working all in german, english and french. We are very interested in a long time, kind and friendly relationship without any stress, but reliable reactivity in case of urgency. 
      We are based in Hamburg and near Paris and would prefere to work with somebody who is available to catch up around a table, at least sometimes.
      Contact: mail@cheval-ami.fr or +33 626 22 1000 or +49 170 20 28 215
      Thank you, Have a beautiful day,
      Jeannette
×
×
  • Create New...