Prestashop - customer registration management module - slight modification - prestashop

I am struggling with modifying some code in Customer registration management module. Instant checkout is not working the way it should. When the Customer registration management module is disabled, the Instant Checkout is working fine, on submit and with no errors we go to the next step/screen. When Customer registration module is enabled, once we click on submit button under Instant checkout, we do not go to the next step/screen, instead we come back to the same screens, forms empty, and in url we have this: authentication?back=order.php%3Fstep%3D1
I managed to identify a piece a code which is preventing a customer from going to the following screen from Instant checkout form. It is the code in function hookCreateAccount($params)
function hookCreateAccount($params)
{
require_once (dirname(__FILE__).'/ApprovedCustomer.php');
global $cookie, $back;
$registration_code = pSQL(Tools::getValue('registration_code'));
if ($registration_code != '' AND $registration_code == $this->_registrationCode) {
$customer = $params['newCustomer'];
$customer->cleanGroups();
$customer->addGroups ($this->_defaultGroups);
}
$cookie->logged = $this->_isCustomerRegistredByDefault;
$cust = $params['newCustomer'];
$approval = new ApprovedCustomer($cust->id);
$approval->is_approved = $this->_isCustomerRegistredByDefault;
$approval->privilege_request = intval(Tools::getValue('privilege_request'),0);
$approval->privilege_message = pSQL(Tools::getValue('privilege_message'), '');;
if (! $approval->save())
Tools::D('Unable to save approval information');
if ($this->_sendAdminMail)
$this->sendMail('pending_registration', array('customer' => $cust, 'approval'=>$approval));
if (! $approval->is_approved) {
$back = 'modules/'.basename(__FILE__, '.php').'/messages.php?msg=noconnect&back=my-account.php';
$cookie->logged = 0;
$cookie->id_customer = 0;
}
elseif ($back == '')
$back = 'my-account.php';
}
Anybody has any ideas what in this code is causing this? any help would be really appreciated.
exactly what happens: once the user fill in Instant checkout form and clicks on submit, the form is redirected to the same page: ... /authentication?back=order.php%3Fstep%3D1
but it should go to: /order?step=2
the Instant Checkout form action:
<form action="{$link->getPageLink('authentication.php', true)}?back={$back}" method="post" id="new_account_form" class="std">
so, should I change the action part then? how does this work? could somebody point me to the right direction? any help would be really appreciated.

I suspect that the conflict occurs because by definition your customer isn't registering as part of the One Page Checkout functionality (I assume this is what you mean by Instant Checkout).
You could try refactoring the first block of code as:
global $cookie, $back;
$customer = $params['newCustomer'];
if ($customer->is_guest)
return;
require_once (dirname(__FILE__).'/ApprovedCustomer.php');
$registration_code = pSQL(Tools::getValue('registration_code'));
if ($registration_code != '' AND $registration_code == $this->_registrationCode) {
$customer->cleanGroups();
$customer->addGroups ($this->_defaultGroups);
}

Related

I would like to grey out the submit button until required fields in a pdf form have been filled out

I am recently task with collecting data using a pdf form, some fields in the form are required but not all fields, I have created a submit button and the department will received the form fill out, now the form needs to be reset when submitted. so i add a button to submit the form and then reset it. the problem is that if someone fills the form and hits submit missing a required field then when they hit ok all the fields are being reset and the person needs to start over. Please Advice.
My idea is to gray out the submit button until all the required fields are fill out, no idea how to do this on adobe pro.
Thanks
As you immediately reset the form after submitting (what happens when the submit fails?), greying out or making read-only is a way to go.
Assuming that you did set the required property for the required fields, you could add the following snipped to your Calculation script:
var cnt = 0 ;
for (var i = 0 ; i < this.numFields ; i++) {
var mf = this.getNthFieldName(i) ;
if (mf.type != "button" && mf.type != "signature") {
if (mf.required == true && mf.value == mf.defaultValue) {
cnt++ ;
}
}
}
if (cnt > 0) {
this.getField("mySubmitButton").readonly = true ;
} else {
this.getField("mySubmitButton").readonly = false ;
}
And that should do it.
However, this approach is not very efficient, and for bigger number of fields and just a few required ones, it might be better to create an array of the required field names, and loop through this array instead of all fields.

issue with Xrm.Page.data.entity.save("saveandclose")

When i open an opportunity form and from there i have opened an opportunity product, but when i comes back to project and click on save and close it returns back me to opportunity product page (which i have opened last) instead of opportunity list page.
So, i have make custom function on save and close button and write code as following :
function SaveAndClose()
{
Xrm.Page.data.entity.save("saveandclose")
}
but issue remain same.
Please anyonve can you help me out on this?
I have fixed issue by following code:
function SaveAndClose()
{
Xrm.Page.data.entity.save();
if (parent.opener != undefined)
{
window.parent.close();
}
else
Xrm.Page.ui.close();
}
Hope this help !!!!

Phpbb new successful member registration pop up window

I would like to create a pop up welcome message for the new member that's successfully registered.
But I m having problem of finding where should I put the code, I have check the ucp_register.html ,, but I don't think that is the display content after the member successfully registered, can anyone help me please? Thanks
It would likely to be a more robust solution to display the popup on the first time the user is logged in as an activated user -- after registration they may not be activated, or they may close the browser window immediately after registration.
The way to do this would be to add a column (say, user_JBL_seen_message INT to the phpbb_users table in the database, then modify functions.php to check that column:
In functions.php, find:
// The following assigns all _common_ variables that may be used at any point in a template.
Before, add:
if($user->data['is_registered'] && $user->data['is_active'] && !$user->data['is_bot'])
{
if(isset($user->data['user_JBL_seen_message']) && !$user->data['user_JBL_seen_message']))
{
$showPopup = true;
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_JBL_seen_message = 1
WHERE user_id = ' . (int)$user->data['user_id'];
if (!$result = $db->sql_query($sql))
{
return false;
}
}
}
Then, find:
$template->assign_vars(array(
After, add:
'JBL_POPUP' => $showPopup,
Then, you can add the popup HTML code to your overall_header.html template file, where appropriate...
<!-- IF JBL_POPUP -->
.... your HTML popup code here.....
<!-- END IF -->
If you don't want existing users to see the popup, then fill the new column with 1s.
I also agree with Damien's suggestion to use a jQuery UI dialog rather than a popup -- most users' browsers will block popups. However, use jQuery in noconflict mode to avoid conflicts with other mods.

drupal multiple node forms on one page

I have a view that displays several nodes. I want to place node form below each displayed node. Both node_add and drupal_get_form directly in template.php works fine, but I get forms with same form ID of NODETYPE_node_form and validation and submitting does not work as expected.
If you had to put several node forms on one page, what would be your general approach?
Progress so far...
in template.php while preprocessing node
$author_profile and $content is set before.
$unique = $vars['node']->nid;
$node = new StdClass();
$node->uid = $vars['user']->uid;
$node->name = $vars['user']->name;
$node->type = 'review';
$node->language = '';
$node->title = t('Review of ') . $vars['node']->realname . t(' by ') . $vars['user']->realname . t(' on ') . $content->title;
$node->field_review_to_A[0]['nid'] = $nodeA->nid;
$node->field_review_to_B[0]['nid'] = $vars['node']->nid;
$node->field_review_to_profile[0]['nid'] = $author_profile->nid;
if(!function_exists("node_object_prepare")) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
}
//$vars['A_review_form'] = drupal_get_form('review_node_form', $node);
$vars['A_review_form'] = mymodule_view($node, $unique);
in mymodule module
function mymodule_view($node, $unique) {
if(!function_exists("node_object_prepare")) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
}
$output = drupal_get_form('review_node_form_' . $unique, $node);
return $output;
}
function mymodule_forms($form_id, $args) {
$forms = array();
if (strpos($form_id, "review_node_form_") === 0) {
$forms[$form_id] = array('callback' => 'node_form');
}
return $forms;
}
function mymodule_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form_id != $form['type']['#value'] .'_node_form' && $form['type']['#value'] == 'review') {
$type = content_types($form['#node']->type);
if (!empty($type['fields'])) {
module_load_include('inc', 'content', 'includes/content.node_form');
$form = array_merge($form, content_form($form, $form_state));
}
$form['#pre_render'][] = 'content_alter_extra_weights';
$form['#content_extra_fields'] = $type['extra'];
//$form['#id'] = $form_id;
//$form['#validate'][0] = $form_id . '_validate';
$form['title']['#type'] = 'value';
$form['field_review_to_A']['#type'] = 'value';
$form['field_review_to_B']['#type'] = 'value';
$form['field_review_to_profile']['#type'] = 'value';
}
}
Questions
My take on summarizing unclear questions...
Is this good general approach for displaying multiple node forms on same page?
Is it OK to copy/paste code from content modules content_form_alter function in function mymodule_form_alter? Will it not brake things if content module is updated?
Should i set $form['#id']? Without it all forms has same HTML form ID of node_form, with it ID is unique, like review_node_form_254. Thing is that there is no difference of how form is submitted. Setting $form['#validate'][0] does not seem to influence things too. Maybe I should set $form[button]['#submit'][0] to something else? Now its node_form_submit.
Why validation does not work even with unique form id and form validate function? If i submit last form without required field all previous forms gets particular fields red. should I make my own validation function? what level - form or field? Any tips on where to start?
You need to implement hook_forms() to map different ids to the same builder function.
The NODETYPE_node_form ids you mention are already an example of this mechanism, as they are all mapped to the same builder function (node_form()) within the node modules node_forms() implementation.
You can find links to more examples in the 'Parameters' explanation off the drupal_get_form() function.
This was exceptionally useful to me.
Documentation on all the drupal APIs is so lacking - I was tearing my hair out. The crucial bit for me, that I don't think is covered anywhere else on the net:
CCK adds its fields to your form through hook_form_alter() . But it does this based on the form_id. So if the form ID is different (cause you want multiple ones on the same page), you need to replicate a bit of the CCK code to add the fields to your form regardless.
That is what this does brilliantly.
I really did not dig to the bottom of it, but it seems to me that you pretty much did all the relevant digging by yourself.
From what I understand by inspecting the code only, you are right in thinking that content_form_alter() is the show-stopper.
Maybe this is a naïve suggestion, but what about writing your own implementation of hook_form_alter() starting from the content_form_alter() code but changing the conditions that make the alteration to occur? I am thinking to something along these lines:
function modulename_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) &&
stripos($form_id, $form['type']['#value'] .'_node_form')) {
...
}
}
I did not actually test the code above, but I hope it is self-explenatory: you actually trigger the changes for a give customised type of content if MYCCKTYPE_node_form is a substring of the actual form_id (es: MYCCKTYPE_node_form_234).
Hope this helps at least a bit... Good luck! :)
EDIT: TWO MORE THINGS
It just occurred to me that since your custom implementation of hook_form_alter() will live aside the CCK one, you would like to add a check to avoid the form to be modified twice something like:
&& $form_id != $form['type']['#value'] .'_node_form'
The other way you might try to implement this by not using CCK but implementing you custom type programmatically (this might even be an advantage if you plan to use your module on various different sites).

CKEditor custom select menu

I am trying to add my own custom select menu to the new CKEditor. The API is a little confusing so I am unsure how to get this working. I am using the ui dialog function, but really not sure how to get it working.
So far I have:
CKEDITOR.ui.dialog.select(dialogObj, elementDefinition, htmlList);
Anyone hav ideas on how to actually get a custom select to work?
I am trying understand this API: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.dialog.select.html
Try this Code,
It's something like creating the element dynamically just like in javascript, the SELECT control will be created whenever you are pressing Enter key...
var editor1 = CKEDITOR.replace('editor');
CKEDITOR.instances["editor"].on("instanceReady" , function(){
var e = this.document;
this.document.on("keyup", function(event){
domEvent = event.data;
key = domEvent.getKey();
switch(key){
case 13:
e = CKEDITOR.instances.editor.document;
b = e.getBody();
s = e.createElement('select');
o = e.createElement('option');
o.appendHtml("hi");
s.append(o);
o = e.createElement('option');
o.appendHtml("hello");
s.append(o);
b.append(s);
s.focus();
break;
default:
}
});
});
Why don't you check the _source folder?
Go into the plugins directory and pick a plugin which shows dropdown selects e.g. stylescombo. The code may shed some light into it. Create a copy of the folder and start modifying the code top down and you'll have your select in no time.
Cheers,
m^e