Jump to content

Can't add pages to Page field [Asmselect]


Recommended Posts

I want to add a few pages to an AsmSelect Page field inside a repeater using the following code:

$trialsPage = wire("pages")->get(28422); // Get the page
$trialsPage->of(false);
$newTrial = $ordersPage->trial_repeater_orders->getNewItem(); // Add item to repeater
foreach ($selectedProducts as $selectedProduct){
	$productPage = $pages->get("template=product, reference=$selectedProduct");
	$newTrial->trial_selected_products->add($productPage);
}
$newTrial->save();
$trialsPage->save();

However, when I check the page where the field is located it doesn't have the new values as expected. The selected pages exist, the field is in the right location, made sure that the output formatting is turned off: $page->of(false); But it still doesn't work with a variable. No matter what I try, it doesn't work.

It only works when I replace $selectedProduct with a hardcoded string. Am I doing something wrong here?

Link to post
Share on other sites

Does it work with $selectedProduct in curly brackets like this {$selectedProduct}?

$trialsPage = wire("pages")->get(28422); // Get the page
$trialsPage->of(false);
$newTrial = $ordersPage->trial_repeater_orders->getNewItem(); // Add item to repeater
foreach ($selectedProducts as $selectedProduct){
	$productPage = $pages->get("template=product, reference={$selectedProduct}");
	$newTrial->trial_selected_products->add($productPage);
}
$newTrial->save();
$trialsPage->save();

 

Link to post
Share on other sites

And another thing with repeaters via API. At least I save after each new repeater - as seen below.

$trialsPage = wire("pages")->get(28422); // Get the page
$trialsPage->of(false);
$newTrial = $ordersPage->trial_repeater_orders->getNewItem(); // Add item to repeater
foreach ($selectedProducts as $selectedProduct){
	$productPage = $pages->get("template=product, reference={$selectedProduct}");
	$newTrial->trial_selected_products->add($productPage);
	$newTrial->save();
}
$trialsPage->save();

 

Link to post
Share on other sites
14 minutes ago, wbmnfktr said:

Does it work with $selectedProduct in curly brackets like this {$selectedProduct}?

Tried that but doesn't work.

 

9 minutes ago, wbmnfktr said:

At least I save after each new repeater - as seen below.

Doesn't fix the problem either.

 

I have no problems editing the other fields in the repeater, it's just the AsmSelect Page field

Link to post
Share on other sites

Ok... just some other thoughts.

Is that page field setup correctly?

Are the pages you want to add matching the parent/template settings within the page field?

Are those pages you want to add hidden or unpublished?

Does your query find those pages?

 

 

Link to post
Share on other sites
12 minutes ago, wbmnfktr said:

Is that page field setup correctly?

Yes, checked everything a couple times. Don't know why I can't set the values

12 minutes ago, wbmnfktr said:

Are the pages you want to add matching the parent/template settings within the page field?

Yes

12 minutes ago, wbmnfktr said:

Are those pages you want to add hidden or unpublished?

No, they are published and not hidden

12 minutes ago, wbmnfktr said:

Does your query find those pages?

Yes

Can it be a problem that the page with this field has a template without a file?

Link to post
Share on other sites

What sort of field is "reference"? What sort of data is $selectedProduct?

14 hours ago, Harmen said:

It only works when I replace $selectedProduct with a hardcoded string.

If that is so then it indicates that the data held in $selectedProduct is not the same as the data in your hardcoded string.

Tracy Debugger is your friend here...

$trialsPage = wire("pages")->get(28422); // Get the page
$trialsPage->of(false);
$newTrial = $ordersPage->trial_repeater_orders->getNewItem(); // Add item to repeater
foreach ($selectedProducts as $selectedProduct){
	// See what is in $selectedProduct
	bd($selectedProduct, 'selectedProduct');
	$productPage = $pages->get("template=product, reference=$selectedProduct");
	// Check that $productPage is not a NullPage (i.e. no matching page found)
	// and that is the right kind of page (template, parent, etc) to add to trial_selected_products
	bd($productPage, 'productPage');
	$newTrial->trial_selected_products->add($productPage);
}
$newTrial->save();
$trialsPage->save();

 

  • Like 1
Link to post
Share on other sites
18 hours ago, Autofahrn said:

Did you try (shouldn't be necessary, though)


$productPage = $pages->get("template=product, reference={$selectedProduct->id}");

 

Doesn't work, $selectedProduct isn't a Page object but a string.

--

7 hours ago, Robin S said:

What sort of field is "reference"? What sort of data is $selectedProduct?

The reference field is just a Text field. $selectedProduct is a string. The reference field holds the reference of the product which is unique for each product. 

Used TracyDebugger, and this are the results:

Quote

bd($selectedProduct, 'selectedProduct');

This returns a string, the exact same string that the product has stored in the reference field.

Quote

bd($productPage, 'productPage');

This returns a Page Object, containing the actual page that I want to add to the AsmSelect Page field.

Conclusion: $productPage contains an actual page that exists, but for some reason I cannot add this page to the AsmSelect Page Field.

Did some more digging and found the following:

There are 7 categories: each containing a different kind of products. I have no problem with adding the products of the first 4 categories, but for the remaining 3 categories it doesn't work, a hardcode string for these pages doesn't help either, even though I can find the pages manually in the selector.

 

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 opalepatrick
      I am working on my first Process Module. I am creating forms. Fairly straightforward. However, I really can't work out how to create multiple fieldsets?
      $fieldset = $this->modules->get('InputfieldFieldset'); $fieldset->label = 'Customer Source'; $field = $this->modules->get('InputfieldPage'); $field->inputfield = 'InputfieldSelect'; $field->findPagesSelector = 'parent_id=1449, include=hidden'; $field->labelFieldName = 'yff-lead'; $field->name = 'yfflead'; $field->columnWidth = 16; $fieldset->add($field); $field = $this->modules->get('InputfieldPage'); $field->inputfield = 'InputfieldSelect'; $field->findPagesSelector = 'parent_id=1452, include=hidden'; $field->labelFieldName = 'customer-type'; $field->name = 'customertype'; $field->columnWidth = 16; $fieldset->add($field); //Rinse and Repeat $fieldset->label = 'Contacts'; $field = $this->modules->get('InputfieldPage'); $field->inputfield = 'InputfieldSelect'; $field->findPagesSelector = 'parent_id=1538, include=hidden'; $field->labelFieldName = 'salutation'; $field->name = 'salutation'; $field->columnWidth = 16; $fieldset->add($field); I can create the first fieldset (Customer Source) but then get into trouble as the second fieldset overwrites the first. I understand why, but trying to use the open and close fieldset routine has flummoxed me. Any help appreciated.
    • By Neue Rituale
      https://github.com/neuerituale/FieldtypeOembed
      or in the modules directory: https://processwire.com/modules/fieldtype-oembed/
    • By VeiJari
      Hello forum, we're trying to use Processwire as our REST-API. We are having problems with our API login to Processwire from frontend. It gives us 403 error.
      We have installed ProcessWire to subdirectory (/api/*) and our frontend is static JS files at root ( / ). Apache access logs gives 404 to our POST-request, but browser devtools shows 403 for our POST /api/login request. 
      Processwire backend panel works. We also have a GET endpoint for the API that returns 200 with correct payload.  So we're wondering why does our GET works but POST doesn't?
      Does this have something to do with Processwire .htaccess, or is this because of our webhost? What should we check first? Any help would be appreciated.
    • By carlitoselmago
      It's been twice this year as a PW developer where clients have asqued me to have a way to put content on specific coordinates of a picture. Something like what image maps are made of. But not necesarly on links, sometimes text, sometimes images and links. 
      So I've been thinking to build an inputfield for that purpose. But I'm not sure how could it be the most flexible so I can share it in github/modules page.
      Ideally it would need to work like a repeater field where you start uploading an image and then adding any custom field like title, url etc. So the user could add multiple elements floating over that image.
      Does anybody here know the ideal way to start the arquitecture of something like that? I could just hardcode the fields I need for the website I have to code this month but it would be nice to be something more flexible.
    • By rjgamer
      Hi,
      is there a hook after the current (active) page got created? Or which method got called in the Page class after the Constructor of the current page got initialized?
      Thanks.
       
×
×
  • Create New...