Vayu Robins
Members-
Posts
98 -
Joined
-
Last visited
Everything posted by Vayu Robins
-
Input data loss on saveReady on Publish
Vayu Robins replied to Vayu Robins's topic in General Support
Thanks Soma, but I need to update another page (a partner page) when a transaction page is published. I use $partner->save() to do this. If uncomment this, then the problem disappears. What could be wrong with the code? -
Hi. I am hooking into the saveReady hook in order to update data on other pages, when a page is published. In other words, when a transaction is published, the user is updated. Certain fields are reset on Publish for some reason. It's only on publish, so if I insert data into input fields again and press save, then it works. So i have added this bit of code to the admin.php file in my template. $page->addHook( 'Pages::saveReady', null, 'credit_published' ); function credit_published( $event ) { $page = $event->arguments[0]; if( $page->template == "credit-log" && $page->id && !$page->isTrash() && $page->isChanged( 'status' ) && !$page->is( Page::statusUnpublished ) && $page->credit_action->id === 3 ) { // Add credit to user. $partner = $page->partner; $partner->of( false ); $partner->credit = intval( $partner->credit + $page->credit ); $partner->save(); } }
-
Hey Wanze. Thanks, that works great!
-
Hi. I need to compare two pagefields. I tried this: $page->locations->has($user->locations) But this doesn't work. I need to compare them and find out if the $page->locations has one or more of the same locations as the $user->locations. Hope it makes sense.
-
Hi, is the Fieldtype: Select (AKA Drop Down) moduel (version 1.2.0) compatible with ProcessWire 2.6.1? It says it's compatible with ProcessWire 2.4.
-
Yeah, I didn't think of mentioning it and had of course no clue that this is where the problem was. Anyways, thanks for helping, I appreciate it!
-
Okay, so maybe I have found the cause. I have been using the WireMailMandrill module to send mails with. So after uninstalling this module and instead installed the WireMailSmtp module, then the problem disappeared. I guess that it must have something to do with the WireMailMandrill module? What, I have no idea.
-
Thanks tpr. I have testet with your code, but it still sends 3 emails. Two emails are sent to mail1@yourmail.com and one email is sent to mail2@yourmail.com. Please see attached screenshot. For some reason the $to variable is not reset on each loop. I cannot for the life of me understand why though. Could it be that the loop runs faster than wireMail() handles the send function? So maybe the loop runs twice before wireMail sends and the email adresses are added inside that function? Stikki: I have also testet with $mail->to(); but it doesn't help.
-
Okay, I have now tried many different things, but no luck. I tried calling WireMail() and wireMail() at the end inside the foreach. Any other ideas?
-
Thanks. I have now tested your suggestion, but now it doesn't send any emails.
-
Hi. I have a setup that sends an email to all users that have subscribed to a category. When a post i published in a category, emails needs to be sent to all those users. For instance, I have 3 user subscribed, so 3 emails should be sent. However, 6 emails are sent and some of the emails are sent to 2 and 3 person at the same time. Please see attached file for what I mean. if( $page->template == "post" && !$page->isTrash() ){ if( $page->id && $page->isChanged( 'status' ) && !$page->is( Page::statusUnpublished ) ) { $from = wire('config')->adminEmail; foreach( wire( 'users' )->find( "roles=partner, location=$page->location, branch=$page->branch" ) as $user_data ){ $mail = wireMail(); $mail->to( array( $user_data->email => $user_data->contact_name ) ); $mail->from( $from, 'My Company' ); $mail->subject( 'Hi '.$user_data->contact_name.'<br>My subject' ); $mail->bodyHTML( 'My message' ); $mail->send(); } } }
-
Great, thanks I had not seen that. Thank you.
-
Hi. I get this error when saving menu items. The problem only arises when language support installed. Error: Call to a member function getLanguageValue() on a non-object (line 1750 of /Users/vayu/Sites/processshop.dev/site/modules/ProcessMenuBuilder/ProcessMenuBuilder.module) This error message was shown because you are logged in as a Superuser. Error has been logged. I have tested this on a clean install of Processwire version 2.6.1.
-
Hi, is it possible to use this ProcessForgotPassword module but where the username is the email? We will not be giving our users their username, but instead they must login with their email. Hence, the user must insert email to reset password.
-
Create & publish new page with specific filed data
Vayu Robins replied to Vayu Robins's topic in API & Templates
Thanks again! I used and modified your code to fit my needs and it works nicely. Here is the code I ended with: / In Admin area, create Refundering btn on cases. $page->addHookAfter( 'ProcessPageEdit::buildForm', null, 'addButtons' ); /** * Add a button besides "Save", which lets the user accept the application * */ function addButtons($event) { $page = $event->object->getPage(); if( $page->template == "credit-log" && $page->id && !$page->isTrash() && !$page->is( Page::statusUnpublished ) && $page->credit_action->id === 1 ){ $refunded_page = wire('pages')->find("template=credit-log, product=$page->product, partner=$page->partner, credit_action=2"); if( $refunded_page->count() == 0 ) { $form = $event->return; $refund = wire()->modules->get('InputfieldSubmit'); $refund->attr('id+name', 'create_refund'); $refund->class .= ' ui-priority-secondary'; $refund->attr('value', wire()->_('Refunder')); $event->return = $event->return->insertBefore( $refund, $form->get("id") ); }else{ // echo out a message that this case has been refunded. $form = $event->return; $refund = wire()->modules->get('InputfieldMarkup'); $refund->attr('id+name', 'create_refund'); $refund->attr('value', wire()->_('This case is now refunded!')); $event->return = $event->return->insertBefore( $refund, $form->get("id") ); } } // When submitted save new page and update user. if( wire()->input->post->create_refund ){ if(!$page->id){ wire()->error("Invalid case to be refunded."); return; } // Create credit log $credit_page = new Page(); // create new page object $credit_page->of( false ); $credit_page->template = 'credit-log'; // set template $credit_page->parent = $page->parent; // set the parent $credit_page->title = date( 'd-m-Y-H-i-s' ); $credit_page->credit = intval( $page->credit ); $credit_page->partner = $page->partner; $credit_page->product = $page->product; $credit_page->credit_date = date( 'd-m-Y H:i:s' ); $credit_page->credit_action = intval( 2 ); $credit_page->save(); // Subtract case credit from user credit. $partner = $page->partner; $partner->of( false ); $partner->credit = intval( $partner->credit + $page->credit ); $partner->save(); } } -
Create & publish new page with specific filed data
Vayu Robins replied to Vayu Robins's topic in API & Templates
Thanks, but I don't think I am following. Do you mean that I should hook into Pages::saveReady and publish a new page and then make a redirect? -
Hi. I am trying to create a button on specific admin pages, that when pressing this button, it creates and publishes a new page with some of the input data from the current page. I have been able to add a button to the admin pages with this code in the admin.php template file: $page->addHook('ProcessPageEdit::buildForm', null, 'addButton'); function addButton(HookEvent $event) { $page = $event->arguments(0); $href = wire()->config->urls->admin.'page/add/?parent_id=1089&credit='.$page->credit->value.'&partner='.$page->partner->value; $field = wire()->modules->get('InputfieldButton'); $field->attr('id+name', 'create_new_log'); $field->attr('class', $field->class); $field->attr('value', 'Create new log'); $field->attr('href',$href); $event->return = $event->return->append($field); } require($config->paths->adminTemplates . 'controller.php'); I have attempted to add some url parameters, but this method does nothing good. Is it possible to do what I am trying to do?
-
Yes, that seems to be the only way. Thanks
-
Well I could, but that would mean that I would have to change the source code of the module. When updates arrive, that code would be overwritten. As far as I understand, the blog module uses a function called renderPosts, which prints markup, that cannot be modified, unless I have overseen something? If there is another way to change the markup, then please do inform me, I will be very appreciative.
-
Hi, yes I have tried that, and as mentioned, it is not possible to edit the markup.
-
Hi. I have site already running in Processwire. I would like to add a Blog to it. I tried to install the Blog module, but it is not possible to edit the markup. I really need to do that. Therefore, I would like to use the Blog profile by Ryan: http://modules.processwire.com/modules/blog-profile/ Is it possible to install that on a site that already is running another profile/template?
-
Okay, I finally found the cause of it all. During one of the last few days, I must have changed the Access level for the child pages, which in turn prevented me from searching them, when not logged in. This works. wire('pages')->count("parent=/case-references/, check_access=0"); Thank you everyone for helping me!
-
Thanks. I now tested the form in Preview via the admin dasboard and there everything works perfectly. So something in the frontend is happening. I will try to set it up in a clean install.
-
Hi, thanks for the quick response. However, it's not working either way. I have already tested all these methods and they all return the correct answer when I print it in a page template, but not from my module. Here's what I am trying to do. When a user submits the form, two new pages are created. One case and one reference. The case must have a sequential reference number, which I get from creating a new reference page and count the total of. In the module I am calling the code from the Pages::saveReady hook. It was working up until recently, so something must have happened somewhere. I have a parent page named "case-references". On this parent page I am creating a new child page. The child page must be named the number of total child pages. My problem is that I can't get that total number. wire('pages')->count("parent=/case-references/"); wire('pages')->get("/case-references/")->count(); wire('pages')->get("/case-references/")->children->count(); wire('pages')->find("template=case-reference")->count(); I wonder if another module I have installed lately, could interfere or could it be something in Processwire 2.6.1 that changed, because a few days ago, it was working perfectly. Here is the whole code: public function init() { $this->addHookAfter( 'Pages::saveReady', $this, 'createReferenceCase' ); } public function createReferenceCase( $event ) { // Get the soon to be saved page object from the given event $page = $event->arguments[0]; if( $page->template == "case" && !$page->isTrash() ){ // When form is submitted, create page and update reference input field. if( ! $page->id && $page->is( Page::statusUnpublished ) ) { // Get references parent page $references_parent = wire( 'pages' )->get('/case-references/' ); // Create new reference page $r = new Page(); // create new page object $r->template = 'case-reference'; // set template $r->parent = $references_parent; // set the parent $reference_num = wire('pages')->count("parent=/case-references/") + 1; $r->title = '#'.$reference_num; // set page title (not neccessary but recommended) // populate fields $r->reference = wire( 'sanitizer' )->fieldName( $reference_num ); // populate a single $r->save(); // Add reference id to case $reference_name = date('Y') . $reference_num; $page->name = wire( 'sanitizer' )->name( $reference_name ); $page->reference = '#'. wire( 'sanitizer' )->fieldName( $reference_name ); } } }
-
Hi. I have a weird problem. I have a form on a page built with FormBuilder. When a user submits this form, I use this code to get the number of pages like this from a module: if( ! $page->id && $page->is( Page::statusUnpublished ) ) { $references_parent = wire( 'pages' )->get('/case-references/' ); $num = $references_parent->count(); } This code returns nothing wire( 'pages' )->get('/case-references/' ); It's as if it can't find anything. I am really stuck on this one. Hope someone has an idea.