Jump to content

hellomoto

Members
  • Posts

    364
  • Joined

Everything posted by hellomoto

  1. My vessel template has a price field (actually field group: with price_currency, price_amount). But when the price is lowered, the listing should qualify to appear on a "Price Cuts" page automatically... so here's what I'm doing (or skip to the bottom): So I was thinking I could add another couple of read-only fields, price_amount_was (since it's unlikely that the currency would change) and price_cut_date. price_amount_was would default to the set price once one is set on save (starts empty, stays empty until a price is set and the page saved). price_cut_date would be null by default. Then another hook after page save would check if the price_amount is lower than price_amount_was, and if so, change the price_cut_date to the current day. Then my Price Cuts page could just show "template=vessel, limit=10, price_cut_date!='', sort=-price_cut_date". But if I wanted to keep a history of price cuts for each listing, that wouldn't work. I could use a repeater field but I don't think that's all that necessary, since only the current and last price (or I guess that'd be second-to-last, last is current) need be queryable. I could add another read-only textarea field, price_history, and on every save that the price is changed, append the price and date (comma-separated, followed by a newline). So that's what I'm trying to do now, but I don't know how to append to price_history. In my module init I hook after page save, this function: protected function setPriceHistory($event) { $page = $event->arguments('page'); if($page->template != 'vessel') return; if($page->price_amount) { //$this->message("Price exists"); if(!$page->price_amount_hold) { $page->set("price_amount_hold", $page->price_amount)->save(); // append price_amount, date(), newline to price_history $this->message("Updated hold price to current price."); } if($page->price_amount < $page->price_amount_hold) { $page->set("price_amount_was", $page->price_amount_hold)->set("price_amount_hold", $page->price_amount)->set("price_cut_date", wireDate('Y-m-d'))->save(); $this->message("Price Cut set on {$page->price_cut_date}."); } } } So you see that commented out line in if(!$page->price_amount_was){}... I could set the value, but I don't want to reset it, just add to it. Thanks.
  2. Thanks Lost. Good to know that that module keeps the originals too (and can back up the db), I don't see any reason not to use it next time. I was probably too fried from having tried doing that same tedious process a few times over already and messed something up... I got the site back by the way I feel like I must have mentioned it probably elsewhere, me with my multiple threads on the same topic... I just had to restore a db backup from 6 days prior instead of the site profile I had just created that day. No big deal, it's back up to date now.
  3. Oh so then the SMTP plugins are separate of PHP mail? Sounds good! But if that's the case, and my settings are supposed to be set up correctly in WireMailSmtp, why won't my email test work?
  4. What template file? I have rss.php in my templates directory. How is the feed accessed? I need to make a blank RSS template in PW? Never mind that worked
  5. And now... in a new PW master unzipped dir, I add my site-profile alongside all the others in its root, but it doesn't show up in the Installation Profiles select. Anything I might be able to do to get it to show up..? Yeah I undid my changes since they didn't work, I didn't want to just leave bogus settings =\ I should probably just hold off on these advanced user configurations. Now I just want my site back.
  6. ... Actually... now I can't log even log in, since trying to create a new user (got an error right when I clicked to add one); I get the below error, trying to access the front- or back-end. I exported my site profile just before upgrading though, so I'm not really worried... I have the original/stable wire dir and index.php too but I don't think restoring those will help much. Catchable fatal error: Argument 1 passed to Users::setCurrentUser() must be an instance of User, instance of Page given, called in /wire/core/Session.php on line 76 and defined in /wire/core/Users.php on line 39 Recoverable Fatal Error: Argument 1 passed to Users::setCurrentUser() must be an instance of User, instance of Page given, called in /wire/core/Session.php on line 76 and defined (line 39 of /wire/core/Users.php) This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. Ah, gotcha. Thanks Lost.
  7. Thanks Cstevensjr. & Sorry, Lost. I'm running around like a chicken without a head forgetting all my other threads... I'll be sure to check the ones I got going before posting any new topics from now on. So 2.5.14... that's a 14, not like .14, huh? So that it's greater than 3? Now I get it. Thanks a lot guys. I have upgraded to dev Now I should have success.
  8. Oh! Sorry Cstevens, hadn't seen that yet, thanks.
  9. Well I have WireMailSmtp enabled and it says my settings appear to work correctly... so now I'm testing my php mail. Do my WireMailSmtp SMTP settings need to match my server/php settings?
  10. Or the repeater subfields could be added to the select list for the field connections directly... that would simplify the importPageValue part. But still... if I do /** * Build the "Step 2" form to connect the fields * */ protected function buildForm2() { $form = $this->modules->get("InputfieldForm"); $form->method = 'post'; $form->action = './'; $form->description = "Step 2: Connect the fields"; $form->value = "Below is a list of fields found in your CSV file. " . "For each of them, select the field it should import to. " . "Leave any fields you want to exclude blank. " . "Once finished, click 'Start Import' at the bottom of this page. " . "Note: any field names in your CSV file that match those in your site " . "will be automatically selected."; $fp = fopen($this->csvFilename, "r"); $data = fgetcsv($fp, 0, $this->session->csvDelimeter, $this->session->csvEnclosure); foreach($data as $key => $value) { $f = $this->modules->get("InputfieldSelect"); $f->name = "csv" . $key; $f->label = $value; $f->addOption(''); foreach($this->template->fieldgroup as $field) { $valid = false; foreach($this->fieldtypes as $ft) { if($field->type instanceof $ft) { $valid = true; break; } } if(!$valid) continue; if($field->type instanceof FieldtypeRepeater) { echo count($field->repeaterFields); foreach($field->repeaterFields as $item) { echo wire("fields")->get($item)->name . '<br/>'; //$label = wire("fields")->get($item); //$label = $item->name; //$f->addOption($item->name); } } $label = $field->name; $f->addOption($field->name, $label); if($field->name == $value) $f->attr('value', $field->name); } $form->add($f); } fclose($fp); $this->addSubmit($form, 'Start Import'); return $form; } That returns 8 for count($field->repeaterFields), which is correct. Yet, executing the next foreach statement echoes 23 iterations of name of each subfield. For example: repeater field = "engines", its repeaterFields = ["engine_field1", "engine_field2", "engine_field3", "engine_field4", "engine_field5", "engine_field6", "engine_field7", "engine_field8"] and each of those are echoed out together -- 23x. Should just be once, for a total of 8 lines, not 184...
  11. Resources (Ryan's own): ImportPagesCSV FieldtypeMapMarker So I edit the accepted $fieldtypes on :76: /** * List of Fieldtypes that we support importing to * */ protected $fieldtypes = array( 'FieldtypePageTitle', 'FieldtypeText', 'FieldtypeTextarea', 'FieldtypeInteger', 'FieldtypeFloat', 'FieldtypeEmail', 'FieldtypeURL', 'FieldtypeCheckbox', 'FieldtypeFile', 'FieldtypePage', 'FieldtypeMapMarker', 'FieldtypePassword', 'FieldtypeRepeater' ); Page, MapMarker, Password and Repeater were added by me. Then alter importPageValue: /** * Assign a value to a page field * */ protected function importPageValue(Page $page, $name, $value) { $field = $this->fields->get($name); if($field->type instanceof FieldtypeFile) { $value = trim($value); // split delimeted data to an array $value = preg_split('/[\r\n\t|]+/', $value); if($field->maxFiles == 1) $value = array_shift($value); $data = $page->ImportPagesCSVData; $data[$name] = $value; $page->ImportPagesCSVData = $data; } elseif($field->type instanceof FieldtypePage) { $value = trim($value); if(wire("pages")->find("$name=$value")) $page->set($name, $value); } elseif($field->type instanceof FieldtypeMapMarker) { $value = trim($value); $page->set($name->address, $value); } elseif($field->type instanceof FieldtypeRepeater) { // } else { $page->set($name, $value); if($name == 'title') $page->name = $this->sanitizer->pageName($value, 2); // Sanitizer::translate elseif($name == 'fullname') { $page->name = $this->sanitizer->pageName($value, true); } } } Page import works with ID values, which was trivial to incorporate; passwords too. MapMarker and Repeater as you might guess do not. How can I save the map->address value? Hopefully it will update the corresponding map fields too but one thing at a time. As for the repeaters... LostKobrakai tipped me off to foreach($page->engines as $e) { foreach($e->fields as $field) { echo $field; echo $e->get($field); } } which works for their names and values, but in this function you're passed the field, and something like foreach($page->$field as $e) { foreach($e->fields as $field) { echo $field; echo $e->get($field); } } doesn't work... and what it would need to do inside anyway is check for a subfield whose name is equal to the column header (choose the repeater field itself e.g., engines in the select per repeater subfield value, e.g., engine_fueltype), then explode that cell value by pipes ('|'), and for each subvalue, populate the repeater#->subvalue... but before all that I need to be able to iterate through the subfields from the field in this function. Anyone have any ideas?
  12. I'm working with a PW 2.5.3 install. Here http://processwire.com/blog/posts/processwire-core-updates-2.5.14/ there is a quick tutorial on setting up an alternate user template and parent. I followed it to the T, but it didn't work; when adding a new user, there was no choice of template, and once the user was created the alternate template I had set wasn't even among the select options. Has anyone managed to do this or even just an alternate template successfully? The alt. tpl. is what I rly. need... I just tried it twice over and then erased and undid everything 2x too, so... Then I only unchecked "Don't allow pages to change their template?", cloned user template (id=75), added "$config->userTemplateIDs = array(3, 75);" to config.php created a new user No alternate template option still. This should be able to work right? Because I don't see a date for that blog post but do only see comments from 5 days ago, but it says 2.5.13, I'm using 2.5.3.
  13. I follow the instructions exactly and when I add a new user, there's only the name field, not template, and once I enter a name and create, go to Settings tab, the one I have set for the alternate user tpl doesn't appear in the list. What a shame.
  14. Of course! I have to use include=all for other things already (like field options for public pages, which themselves are hidden)... man. Thank you. Okay, so that I did and it works as expected. However, since posting this thread I did go ahead and try the alternate user template/parent example given in that blog post I linked, and followed every step... but it didn't work. I try, try again.
  15. MatthewSchenker: I like DynaTable.
  16. Hey thanks guys. I've realized the ease of simply exporting a site profile, which is serving me well. Someone else pointed Migrator out to me too, but with the profile export I haven't even gotten around to trying that yet... I do have it installed...
  17. I have a page /team/ with url segments [1] enabled, that must equal the name of a user with a 'broker' role. On /team/ a list of all users with the 'broker' role is rendered. It does not appear if I am not logged in though. How can I enable this info to appear universally? I mean for public visitors to be able to view it as well... Then this http://processwire.com/blog/posts/processwire-core-updates-2.5.14/ has got me curious about user hierarchy, as my site will require entirely different types of users that might as well have different input fields per type, hence different templates... Are they still accessible via the $user variable if an alternative template is used? or a different parent? Thanks.
  18. That link has much interesting info... Not just the multiple-modules, but alternate user templates (wasn't really sure on the status of that being supported) and different user parents, even.
  19. I had too little faith starting over again...
  20. Thanks for the reply, Jan. Sorry about the vagueness. Understandable that that error would come up due to invalid input, but now it's not saying for which field? It did just say that the field 'roles' is not present, which I know... so I removed that specification from the visibility, but then I can't restrict visibility based on user role(s)? Then I remove the field and again it only says, "Session: Profile not saved".
  21. Thanks for trying it out. I'm using 2.5. Debug was set to false... =\ But so I went back to the screwy installation and set its config->default to true, saved my profile successfully, though sans the supposed trouble field. Then I set config->debug back to false and could still save my profile... strange... Then, once I added the office_location field back to the user template, I got "Profile not saved" again. I set debug to true and it says: above the regular "Profile not saved" red message. So I removed the visibility selector, 'roles!=37'. Now when I try to save my profile, it just says: ... You did add the field to be editable via the edit-profile screen right? Not just editing the user page? Like you add the field to the template, then make it editable in the profile via ProcessProfile config, then go to /processwire/profile/ (or whatever you have as your admin path if not processwire) and you are able to save it?
  22. I know that say I have a repeater field engines, I can do foreach($page->engines) or $page->engine_field... but is there any way to do like foreach($page->engines as $e) { foreach($e->field as $field) { echo $field->val; } } That itself doesn't work. But is there some way of iterating through a repeater field's subfields? I'm trying to add repeater field support to Import Pages CSV module... If not I may just have to figure out how to write a separate module specifically for imports of a particular page template... if I can... I can try... Anybody know about this?
  23. Bump... Must I create corresponding userinfo pages per user? Has anyone else successfully added page fields to the user template? What am I doing wrong?
×
×
  • Create New...