Jump to content

Juergen

Members
  • Posts

    1,306
  • Joined

  • Last visited

  • Days Won

    13

Everything posted by Juergen

  1. Doesnt work Warning: Attempt to assign property of non-object in /home/.sites/24/site1275/web/site/modules/HookAfterPagesSave/HookAfterPagesSave.module on line 57 Fatal error: Call to a member function save() on integer in /home/.sites/24/site1275/web/site/modules/HookAfterPagesSave/HookAfterPagesSave.module on line 58 Line 57: $parent->offercheck = "2"; //example value to store in the parent page Line 58: $parent->save("offercheck"); //save the parent page
  2. I stuck with Pages:saved. Nothing will be added and stored in the parent page. Here is the code that I call from the module: public function init() { $this->addHook('Pages::saved', $this, 'saved'); } public function saved($event) { $page = $event->arguments[0]; if($page->template == "productpricelistitem"){ //page which will be edited $parent = $page->parent_id;//grab the parent page id -> works //HERE STARTS THE PROBLEM $parent->offercheck = "2"; //example value to store in the parent page in the field "offercheck" $pages->save($parent); //save the parent page } } $parent->offercheck = "2": This line of code should add the value 2 in this case to the offercheck field of the parent page. $parent is the id of the parent page. $pages->save($parent): This line of code should save the parent page (identified by its id $parent). This 2 lines of code make troubles - Maybe its not the right syntax or way to store a value in another page.
  3. Ok that make sense. I was inspired by this topic https://processwire.com/talk/topic/2331-doing-additional-logic-after-saving-a-new-page/ So I will dive into it to solve it with Pages::saved.
  4. I use a Hook module from Soma which adds the save action: https://gist.github.com/somatonic/11206761 Sorry wrong link - I look for the right one Cant find the page but this is the code of the Hook module, where I have added all my Hook events. <?php /** * Hook the saving of pages to add own processes. * * ProcessWire 2.x * Copyright (C) 2014 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://processwire.com * */ class HookAfterPagesSave extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'HookAfterPageSave', 'version' => 1, 'summary' => 'Delete offer price if standard price is selected.', 'singular' => true, // Limit the module to a single instance 'autoload' => true, // Load the module with every call to ProcessWire ); } public function init() { // init() is called when the module is loaded. // saveReady is a hook after processing the previous changes of the page, // but just before those changes are saved to the database. // It's called for each page that's being saved, no matter if it's in // the backend or in your templates via the api. $this->addHookAfter('Pages::saveReady', $this, 'afterSaveReady'); } public function afterSaveReady($event) { // 1) Get the soon to be saved page object from the given event $page = $event->arguments[0]; if(($page->template == "pricelistitem") AND ($page->parents("template=products"))){ $parentid = $page->parent_id; $parentpage = $pages->get($parentid); /* if(){ $this->message("Produkt wurde auf Angebot gesetzt"); $page->parents->offercheck = "1";//this should add the value 1 to the field "offercheck" in the parent template } else { */ $page->parent->offercheck = "1";//this should add the value 0 to the field "offercheck" in the parent template //} } // delete offerprice if standard price is choosen if(($page->template == "pricelistitem") AND ($page->pricetype == "1")){ $this->message("Angebotspreis wurde entfernt"); $page->offertprice = ""; } //delete all prices if pricekind is 3 or 4 if(($page->template == "pricelistitem") AND ($page->pricelistselect >= "3")){ $this->message("Standardpreis wurde entfernt"); $this->message("Angebotspreis wurde entfernt"); $page->offertprice = ""; $page->standardprice = ""; } //delete all dates if service is unlimited in time if(($page->template == "pricelistitem") AND ($page->timelimit >= "2")){ $this->message("Startdatum wurde auf jetzt geändert"); $this->message("Enddatum wurde entfernt"); $page->publish_from = $date = date('Y-m-d H:i'); $page->publish_until = ""; } // 2) delete event texts if event is cancelled or not //clean all up if event is cancelled if(($page->template == "events") AND ($page->cancelled == "1")){ $this->message("Folgende Felder wurden geleert: Einleitungssatz, Hauptteil, Preis, Preiszusatz, Veranstaltungsortname, Downloaddateien"); $page->body = ""; $page->introtext = ""; $page->eventprice = ""; $page->eventpriceadd = ""; $page->eventcosttype = "1"; /* foreach($page->downloadrepeater as $dp){ $dp->delete($p->downloadfield); $dp->downloadfieldtitle = ""; $dp->downloadfiledesc = ""; } */ $page->singleimage->deleteAll(); $page->editorimages->deleteAll(); } if(($page->template == "events") AND ($page->cancelled != "1")){ $this->message("Der Absagetext wurde entfernt"); $page->eventcancelledreason = ""; } } }
  5. Thanks KobraKai I guess I need a Hook because I run it from a Hook module in the backend after page save. Main problem at the moment is how to add a value from this page to the parent page. F.e. $page->parent->fieldname = "1" doesnt work
  6. Hello at all, I want to use a Hook after page save of a child page to add a specific value to the parent page under a certain condition. Here is the scenario. Page structure: - productoverviewpage -product detail page - productprice page 1 - productprice page 2 - productprice page 3 and so on The product overview page includes all product pages - so its the overview of all available products. The product page itself is the detailpage for the product. Every productpage consists of different sub pages with price information, because every product has more than 1 price (depending on size and amount). Examples: Productprice page 1 has the price of 5 Euro for a small bottle. Productprice page 2 has the price of 9 Euro for a big bottle. So every productprice page consists of a specific price for the same product. On the productprice page you can choose wheater this price is an offerprice or not (simple select form field) My Goal: I need to check all the productprice pages if there is an offer available or not. If there is an offerprice in one or more productprice pages than I want to add for example the value "1" to a text field of the parent page (product detail page) via a Hook after saving the productprice page. So this is what I have tried to add the value. //selectors $productpricepageselector = $page->template == "pricelistitem";//check if page is a productprice page $offerselector = 'pricetype *= "2"';//selector if any of the children contain an offervalue (value = 2 in pricetypefield) $productdetailpageselector = "template=products";//selector of the product detail page //condition if(($productpricepageselector) AND ($page->children($offerselector)) AND($page->parents(productdetailpageselector))){ $this->message("Produkt wurde auf Angebot gesetzt"); $page->parents->offercheck = "1";//this should add the value 1 to the field "offercheck" in the parent template } But nothing happens. Maybe this condition is not true : ($page->children($offerselector)) It should be like $parent ->children($offerselector) because it should check all the other children of the product detail page. Has anyone an idea? Best regards
  7. Hello @ all, I have tried to approve a comment via clicking the link in the notification email, but nothing happens. The comment is still in pending status. Here is the approval link: http://www.my-exampledomain.at/produkte/testprodukt/?field=commentsrating&page_id=2407&code=7yOVt2mdJGTcVnJoUZwdDe9piBaNpNWi_JbqcW7NLdI4e3PxOG_D71EFFlN3hm7RDXF9mMg6YbDcYCQJWvftaoSeGsnxDCt9vdqcfzoNAPDoR4DQHexVXQZhaEYcCgkr&comment_success=approve - commentsfield name is "commentsrating" - page id is "2407" - the code is the same as in the database - the URL to the page is correct (I only changed the true domain name to "my-exampledomain" for this posting) So everything seems fine. The only thing that comes to my mind is that I use the extended version with star rating https://processwire.com/talk/topic/10829-comments-fieldtype-with-star-rating/ - so the approval link could be not correct. I have tried "&commentrating_success=approve" and "&commentRating_success=approve" at the end of the link instead of the original "&comment_success=approve" but nothing happens. What could be the cause? Best regards Jürgen
  8. I have found an error: The voting system doesnt work because the field "field_commentsrating_votes" is not present. It seems that this field will not be produced during the installation. Only the standard field " field_comments_votes" from the standard comments without rating is present. SQLSTATE[42S02]: Base table or view not found: 1146 Table '7232549db11.field_commentsrating_votes' doesn't exist
  9. Question: Has anyone tried to add a user image to the comments? In my case people can upload a user image to their profile if they want. Now I also offer the possibility to add a comment to products (if you are a registered user or not). My goal: If the user is logged in and he has a profile image added to his profile, this image should be shown next to his comment. If the user is not logged in or has no profile image than a avatar should be displayed instead. I have checked the database columns for the comments and there is no column which stores f.e. the user id if a user was logged in. My idea was to add a new column for user identification that stores f.e. the user id so the user is identified as a registered user and the profile image could be added via the id (because the user is identified). Has anyone tried to achieve the same or has an better idea. I use a custom output for my comments so I can add everything I want. SOLVED: The user id will be stored. In my case an unregistered user has always the id "40" and a registered user has its own id. The value can be displayed in the comments by calling it inside the foreach loop with this name: created_users_id. Example: foreach ($comments as $comment) { $userid = $comment->created_users_id; } With the id it is possible to find and load the image of the user. Best regards Jürgen
  10. Its quite awesome how many items (products) are included on this site. A lot of hours of content entering.
  11. PHP string replacement is what I would do. I dont think that you really need an extra module for such a simple thing. I always try to avoid JS for output manipulation because its not cacheable and depends on that JS is activated by the user. So your solution seems to me as the best way for this purpose.
  12. Hello @ all, I have made my own custom comment form with Twitter Bootstrap markup in the template where the comment form is located. Unfortunately I am not able to store the entered data in the db. I have searched the forum and found some hints but it doesnt work. Here is my code that should be executed if there are no errors: $c = new CommentRating(); $c->text = $commentsvalue; $c->cite = $namevalue; $c->created = time(); $c->email = $emailvalue; $c->title = $ratingtitle; $c->rating = $ratingvalue; $c->user_agent = $_SERVER['HTTP_USER_AGENT']; $c->ip = $_SERVER['REMOTE_ADDR']; $c->created_users_id = $user->id; $c->sort = count($this->comments)+1; //$c->parent_id = (int) $data->parent_id; $c->status = 1; // just for testing $c->commentsrating->add($c); $c->save(); I use the modified version of the comment field with star rating (https://processwire.com/talk/topic/10829-comments-fieldtype-with-star-rating/ Therefore I call a new instance with the name "CommentRating" and not "Comment". After that i add all fields that should be stored in the db. Then I try to add it to my field "commentsrating" which is the comment field in my template. Here I always get the error for this function: Fatal error: Call to a member function add() on null in .... on line 307 Has anyone an idea how to store the values via API from the template correctly? Best regards EDIT: Nevermind, I did it this way https://processwire.com/talk/topic/696-quick-guide-to-the-comments-system/?p=41520
  13. Thanks for your efforts. I have implemented it and it works quite well.
  14. Another problem: If fields are declared as "required" and the fields are not filled out there will be no error message. The modal window will be closed and you have no hint that something is missing. PS.: I use Reno theme and latest dev version of PW.
  15. Thats true, but it saves much time. What I like on such frameworks is, that all the files are reachable via cdn for free (maxcdn, cdnjs.com,...). This makes the loading of huge amount of data very fast.
  16. Bootstrap 4 is coming soon (http://blog.getbootstrap.com/) - the alpha release is out there.
  17. Only to mention: This only works if the number of files is set to 1. If it is unlimited (0) only the PW short syntaxes for files (more than 1) work. I ran also into this mistake and I wondered why I didnt got a result. Maybe you have to use an foreach loop if you have more than 1 file (I have not tried it).
  18. You are right - thanks for the hint.
  19. And I have never heard about that
  20. Is there a possibility to get the size of the file? Usually I get the filesize like this: $file = "path-to-the-file"; $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB $filesize = round($filesize, 2);//rounding But in this case it is not possible to use the path to the file.
  21. Yep I use it on frontend. I will try your suggestion. Thanx
  22. This opens the file automatically if the page is called. What should be the command to open it only when a link is clicked?? Best regards
  23. Got the error too, but it is really only by pushing the saving button.
  24. I think you are right - I will create fields for that! Thanks
×
×
  • Create New...