Jump to content

Harmen

Members
  • Content Count

    122
  • Joined

  • Last visited

Community Reputation

58 Excellent

About Harmen

  • Rank
    Sr. Member

Profile Information

  • Gender
    Male
  • Location
    The Netherlands

Recent Profile Visitors

1,381 profile views
  1. PW: 3.0.39 Should probably update this soon ProField Table: 0.1.4
  2. Thanks, that did the job. It's not clear though, also could not find anything about it
  3. Whenever I try to modify the Multilanguage textarea fields to a multilanguage CKEditor field or create a new multilanguage CKEditor field in a Table field, I cannot use the field because it gives me the following error: Settings are all set (see image above) and I don't know where to look else. Also, when I modified the original field (which goes flawless for other field somewhere else) I lost all the data that was in there. How can I fix this and use the field?
  4. Doesn't work, $selectedProduct isn't a Page object but a string. -- 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: This returns a string, the exact same string that the product has stored in the reference field. 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.
  5. That's okay. It's weird but I can't figure it out either
  6. Yes, checked everything a couple times. Don't know why I can't set the values Yes No, they are published and not hidden Yes Can it be a problem that the page with this field has a template without a file?
  7. Tried that but doesn't work. Doesn't fix the problem either. I have no problems editing the other fields in the repeater, it's just the AsmSelect Page field
  8. 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?
  9. Hi All, I've made a previous regarding an issue which I solved but I stumbled across a new issue :). Below again the explanation needed. You need a short introduction for this. The company I am working for has approx. 80 products on their website and they all have their own features. The features are imported from an older system which isn't used anymore. Back then, when they changed from the old system to PW, we imported the features into the product pages as a JSON-array so the pages could load a bit faster as exploding a JSON array is a bit faster than loading in a lot of items from a table or a repeater field. How the JSON array looks like: { "2": { // The ID of the group that contains the actual features "name": "Model and function", // The name of the group "features": { "43": { // Attribute ID "name": "Resolution (DPI)", // Attribute name "values": { "896": "500-1500-2000-3500" // Value ID and value name } } } } } Now we are adding a few more products to the catalog with new features and some that are already in use by other products but I am really struggling to assign the right ID's with the correct values in 7 different languages without messing up filters etc. So I decided to develop a module that lets you easily add feature groups, attributes and values as pages and connect these to the product using a repeater. This started by exporting all the current groups, attributes and values and import them as pages in the following structure: - Features - Feature Groups - Group 1 - Group 2 - ... - Feature Attributes - Attribute 1 - Attribute 2 - ... - Feature Values - Value 1 - Value 2 - ... Secondly, I created a repeater field that I assigned to the 'Features'-page that can handle the JSON structure explained above by seeing each item of the repeater field as a group. Inside each item you can select the group page and you will find another repeater which contains 2 page selectors to select an attribute and a value. A single repeater field looks like this: Next step was to create a module that gets this field as an Inputfield from the Features page. Once the user has finished adding groups, attributes and values he can click on save and I export all the values in the same JSON array structure as earlier but now the ID's of the groups, attributes and values are just the page ID's. This works great to add new features to new products. BUT, sometimes the features of a product change or need to be changed and you don't want to change the JSON array manually. So my idea was to do the same thing as adding the features, but now you grab the values from the product first and populate the items of the repeater field. $featuresPage = wire("pages")->get("template=features"); $featureGroups = json_decode($product->features, true); foreach ($featureGroups as $featureGroupID => $featureGroup){ $row = $featuresPage->features_repeater->getNewItem(); $groupPage = wire("pages")->get($featureGroupID); $row->feature_group_selector = $groupPage; $row->save(); foreach ($featureGroup["features"] as $featureID => $feature){ $featuresRow = $row->feature_repeater->getNewItem(); $attributePage = wire("pages")->get($featureID); $valuePage = wire("pages")->get(key($feature['values'])); $featuresRow->feature_attribute_selector = $attributePage; $featuresRow->feature_value_selector = $valuePage; $featuresRow->save(); } $row->save(); } $featuresPage->save(); $f = wire('fields')->get('features_repeater'); $inputfield = $f->getInputfield($featuresPage); $form->add($inputfield); $f = $this->modules->get("InputfieldSubmit"); $f->name = 'updateFeatures'; $f->label = 'Update Features'; $f->icon = 'plus'; $f->value = 'Update Features'; $form->add($f); Then the user can change / add features, click save and done! It is possible to update the feature attributes and values, but when I change the feature group value, it seems like PW creates a new field behind the scenes and keeps the old value as well. So let's say I have the following feature structure: - Feature Group 1 - Feature attribute 1 - Feature value 1 Now I want to update Feature Group 1 to Feature Group 2, below is the desired result and the actual result: // === Desired result - Feature Group 2 - Feature attribute 1 - Feature value 1 // === Actual result - Feature Group 2 - Feature attribute 1 - Feature value 1 - Feature Group 1 - Feature attribute 1 - Feature value 1 I am using the following function to update the features: private function processForm5_UpdateFeatures(InputfieldForm $form){ $form->processInput($this->input->post); if (count($form->getErrors())) return false; $pageID = $this->session->selectedProduct; $product = wire('pages')->get($pageID); $product->of(false); $repeater = $form->get("features_repeater")->value; $languages = wire("languages"); foreach ($languages as $language) { $return_array = []; $i = 0; foreach ($repeater as $repeaterItem) { //$this->message($repeaterItem); $group = $repeaterItem->feature_group_selector; if ($group["id"] == 0) { continue; } else { $group = wire("pages")->get($group["id"]); $feature_group_name = &$return_array[$group->id]['name']; if (!isset($feature_group_name)) $feature_group_name = $group->title->getLanguageValue($language); $features = $repeaterItem->feature_repeater; foreach ($features as $feature) { $this->message($feature); $attribute = $feature->feature_attribute_selector; $value = $feature->feature_value_selector; if ($attribute["id"] == 0 || $value["id"] == 0) { continue; } else { $attribute = wire("pages")->get($attribute["id"]); $value = wire("pages")->get($value["id"]); $return_array[$group->id]['features'][$attribute->id]['name'] = $attribute->title->getLanguageValue($language); $return_array[$group->id]['features'][$attribute->id]['values'][$value->id] = $value->title->getLanguageValue($language); } } } } $product->features->setLanguageValue($language->name, json_encode($return_array, JSON_UNESCAPED_UNICODE)); } $product->save(); $featuresPage = wire("pages")->get("template=features"); $featuresPage->features_repeater->removeAll(); $featuresPage->save(); /* $this->messages("clear all"); $this->errors("clear all");*/ $this->message("Updated all features for {$product->title}"); $this->session->redirect("../"); } Is there a way to avoid the current result and get the desired result? Why is there even a new repeater page created for the new value? Anything that can help me is greatly appreciated! ~Harmen
  10. I managed to solve this issue. If you have questions about how I did that, do not hesitate to PM me
  11. Hi All, You need a short introduction for this. The company I am working for has approx. 80 products on their website and they all have their own features. The features are imported from an older system which isn't used anymore. Back then, when they changed from the old system to PW, we imported the features into the product pages as a JSON-array so the pages could load a bit faster as exploding a JSON array is a bit faster than loading in a lot of items from a table or a repeater field. How the JSON array looks like: { "2": { // The ID of the group that contains the actual features "name": "Model and function", // The name of the group "features": { "43": { // Attribute ID "name": "Resolution (DPI)", // Attribute name "values": { "896": "500-1500-2000-3500" // Value ID and value name } } } } } Now we are adding a few more products to the catalog with new features and some that are already in use by other products but I am really struggling to assign the right ID's with the correct values in 7 different languages without messing up filters etc. So I decided to develop a module that lets you easily add feature groups, attributes and values as pages and connect these to the product using a repeater. This started by exporting all the current groups, attributes and values and import them as pages in the following structure: - Features - Feature Groups - Group 1 - Group 2 - ... - Feature Attributes - Attribute 1 - Attribute 2 - ... - Feature Values - Value 1 - Value 2 - ... Secondly, I created a repeater field that I assigned to the 'Features'-page that can handle the JSON structure explained above by seeing each item of the repeater field as a group. Inside each item you can select the group page and you will find another repeater which contains 2 page selectors to select an attribute and a value. A single repeater field looks like this: Next step was to create a module that gets this field as an Inputfield from the Features page. Once the user has finished adding groups, attributes and values he can click on save and I export all the values in the same JSON array structure as earlier but now the ID's of the groups, attributes and values are just the page ID's. This works great to add new features to new products. BUT, sometimes the features of a product change or need to be changed and you don't want to change the JSON array manually. So my idea was to do the same thing as adding the features, but now you grab the values from the product first and populate the items of the repeater field. $feature_groups = json_decode($product->features, true); if (is_array($feature_groups) || is_object($feature_groups)) { foreach ($feature_groups as $feature_group_id => $feature_group) { $groupPage = wire('pages')->get($feature_group_id); if ($groupPage) { $row = $page->features_repeater->getNewItem(); $row->feature_group_selector = $groupPage; foreach ($feature_group['features'] as $feature_id => $feature) { $featurePage = wire("pages")->get($feature_id); if ($featurePage) { $valuePage = wire('pages')->get(key($feature["values"])); if ($valuePage) { $feature_row = $row->feature_repeater->getNewItem(); $feature_row->feature_attribute_selector = $featurePage; $feature_row->feature_value_selector = $valuePage; } else { continue; } } else { continue; } } $row->save(); } else { continue; } } } Then the user can change / add features, click save and done! Now the issue is that I can't detect any changes made to the repeater field! So when the user clicks the save button I execute the following code: private function processUpdateFeatures(InputfieldForm $form){ $form->processInput($this->input->post); if (count($form->getErrors())) return false; $feature_items = $form->get('features_repeater')->value; foreach ($feature_items as $feature_item){ $group = $feature_item->feature_group_selector; if ($group["id"] != 0){ $groupPage = wire('pages')->get($group["id"]); $this->message($groupPage->title); $features = $feature_item->feature_repeater; foreach ($features as $feature){ $attribute = $feature->feature_attribute_selector; $value = $feature->feature_value_selector; $attributePage = wire('pages')->get($attribute["id"]); $valuePage = wire('pages')->get($value["id"]); $this->message($attributePage->title); $this->message($valuePage->title); } } } } But the only thing that the messages show me is the old values and not the new values. What am I doing wrong here or am I missing a step? Anything that points me in the right direction is greatly appreciated! ~Harmen
  12. Yeah I finally found the culprit. This is a multi-lingual website with up to 9 languages. I guess the module created the pages with only one language enabled to be viewed and I had to click the checkbox for the other pages manually. I should've seen this earlier 😕 Thanks for the great and fast support though.
  13. Yep, that works. You can visit the blog page here: website
  14. So i've created 3 more posts with some sample content: The $blog->renderPosts("limit=$limit") function still returns that it can't find any posts. If I add include=all to the line to find the post, then I can find all the posts. IDK what is going on here
  15. Nothing. But the page is published, so it should be listed right? Yeah I use $content all the time. I just wanted to list the posts so I could apply my own CSS after the code for the listing is done. So my blog.php file looks like this now: <?php namespace ProcessWire; // CALL THE MODULE - MarkupBlog $blog = $modules->get("MarkupBlog"); // === Get the limit $settings = $pages->get('template=blog-settings'); $limit = $settings->blog_quantity; // === Initialize $content $content = ''; // Render limited number of posts on Blog Home Page $content .= $blog->renderPosts("limit=$limit"); // => Returns "No posts found" // === Code for testing purposes to see the difference //$posts = $pages->find('template=blog-post,limit=5, include=all'); => Returns 1 $posts = $pages->find('template=blog-post,limit=5'); // => Returns 0 $content .= $posts->count; $options = array( "Breadcrumbs" => true, ); // === Function to render the whole page, including some options and markup $content = renderPage($page, $content, $options);
×
×
  • Create New...