Jump to content

Copy predefined fields to child-page per category


pixelschiff.net
 Share

Recommended Posts

Hey there!

I've got a shop with product-categories and the template "product-category". The childs are articles "product-page".
As soon as I'm creating a new product, it will copy the defined dynamic fields from the parent and add them to itself.

Each product-category can have different dynamic fields (within a repeater maybe):
- Simple textfield
- Number input
- Page references
- Options select

My problem at the moment is that I would like to predefine "sizes" or "color" in each product-category.
For example an options field. But they have to be different in each category and should be fetched by their children.

Would it be easily doable with the "pro fields" module?

 

Best regards

Link to comment
Share on other sites

41 minutes ago, pixelschiff.net said:

My problem at the moment is that I would like to predefine "sizes" or "color" in each product-category.

I'd approach this with either Page fields.  Would it matter if the available sizes available for selection in appear on every product-category??

Link to comment
Share on other sites

The easiest solution would probably be to add all fields to your template and then just hide the ones you don't need via hook:

<?php
$wire->addHookAfter("ProcessPageEdit::buildForm", function(HookEvent $event) {
  $page = $event->object->getPage();
  $form = $event->return;
  if(...) $form->remove('yourfield');
});

 

  • Like 1
Link to comment
Share on other sites

3 hours ago, bernhard said:

The easiest solution would probably be to add all fields to your template and then just hide the ones you don't need via hook:

<?php
$wire->addHookAfter("ProcessPageEdit::buildForm", function(HookEvent $event) {
  $page = $event->object->getPage();
  $form = $event->return;
  if(...) $form->remove('yourfield');
});

 

Thanks for that idea. I will think about it in detail.

Link to comment
Share on other sites

7 hours ago, pixelschiff.net said:

That's the tricky part. Each category should have his own selection. I already thought about page fields but then they will repeat everywhere. For example T-Shirts have got "sizes (S, L, M, etc.)" and Batteries will also have the sizes field. Just an example.

Something else I've done is dynamically manage the options available for a page reference field depending on where it is in the page tree through a few hooks. So, say each product category has as children two more "parent pages", one for the products, and one for the specific categories of that product page. I won't go into much detail right now as I don't even know if if suits your case.

Link to comment
Share on other sites

Thank you all for your help and ideas.

I solved my issue with creating some magic with dynamic options, hiding fields depending on their parent and using some kind of namespace for the fields to match them to the categories.


While developing this I learned a lot about the fields API and remembered how awesome processwire is ? 
 

 

  • Like 1
Link to comment
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
 Share

×
×
  • Create New...