Monday, October 21, 2019

Drupal 7 / Ubercart 7 - Bulk Password Refresh

Drupal core 7.67 / Ubercart 7.x-3.13 

Interested in a way to perform a user-wide password refresh after boosting our password critiera, I found a module that enabled me to do exactly that!




References:

https://www.drupal.org/project/one_time_login

Sunday, October 20, 2019

Drupal 7 / Ubercart 7 - Unlimited catalog listing [Taxonomy Listing]

Drupal core 7.67 / Ubercart 7.x-3.13 

In our website, we want when a user clicks on a "catalog" they get the entire list of products within that category.  Unfortunately, the default theme we used was introducing pageination at 10 items, not what we wanted:




What was tricky wasn't removing pageination, it was finding the correct View to alter, because the URL wasn't leading to anywhere all that meaningful in the Administration area:



Fortunately, we have been here before, and it took a little clue on the page to lead us to where we needed to go:

Apparently, we need to be messing around with something to do with the Drupal 7 Taxonomy, not any place named Catalog!

So, off to the Views area we go, to look for a view related to Taxonomy.

Lo and behold, there is one:


And it has a pageination set at 10.  



Setting that value to Zero removes pageination, so let's give that a try:



Click on Apply:




Click on Save:



Now the "Catalog" no longer pageinates:








Drupal 7 / Ubercart 7 - Remove Pages in Shop

Drupal core 7.67 / Ubercart 7.x-3.13

Seeing as our primary sales channel is via Mobile, we didn't see the point of having a pageinated Shop.

Unfortunately, the theme we installed had a limit of 12 products per page, along with a pageination feature:




Luckily, this is an easy fix.

All that needs to be done is an adjustment to the View that controls Product, which is what is displayed when the user clicks on Shop.

First, go to the right place in the Administration area:



Then adjust the Pager parameters that control how the Product View works:





Click on Apply:




Then click on Save:





[Unresolved] Drupal 7 / Ubercart 7 - Migrate Usersfrom Drupal 6 into Drupal 7 w/ Passwords

Drupal core 7.67 / Ubercart 7.x-3.13

With a newly implemented and modernized Mobile-ready website, we want to bring in our legacy users from our old Drupal 6 site, ideally in such a way that they supply their username and password to the new site and simply see an updated interface with all of their information migrated over.

Username / Email
The most basic information we hope to migrate over is the username / email that is part of the initial authentication sequence
(possible)

Password
We are really, really hoping that all of our existing users will not have to go through a password re-enter or refresh cycle
(impossible to migrate - must use password refresh)

Order History We quickly realized that it would be impractical to try to migrate the user's Order History, because the Product ID are different between the two sites.  Besides, the only people really interested in the history of orders is usually us, because customers forget what product they ordered and ask us to look it up for them as part of the re-purchase cycle.
(impossible to migrate)

Addresses
We also really hope that we can migrate the Shipping and Billing Address over from our legacy site to our new site
(undetermined)


So, we plan to run the legacy site in parallel on our internal network for some time (in a container) so we can go ahead and access it for reference purposes, but we do not intend to allow our customers to go back to the site once the mobile site is production ready.

Here's the Drupal 6 users table:

> show columns from users;
+------------------+------------------+------+-----+---------+----------------+
| Field            | Type             | Null | Key | Default | Extra          |
+------------------+------------------+------+-----+---------+----------------+
| uid              | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name             | varchar(60)      | NO   | UNI |         |                |
| pass             | varchar(32)      | NO   |     |         |                |
| mail             | varchar(64)      | YES  | MUL |         |                |
| mode             | tinyint(4)       | NO   |     | 0       |                |
| sort             | tinyint(4)       | YES  |     | 0       |                |
| threshold        | tinyint(4)       | YES  |     | 0       |                |
| theme            | varchar(255)     | NO   |     |         |                |
| signature        | varchar(255)     | NO   |     |         |                |
| signature_format | smallint(6)      | NO   |     | 0       |                |
| created          | int(11)          | NO   | MUL | 0       |                |
| access           | int(11)          | NO   | MUL | 0       |                |
| login            | int(11)          | NO   |     | 0       |                |
| status           | tinyint(4)       | NO   |     | 0       |                |
| timezone         | varchar(8)       | YES  |     | NULL    |                |
| language         | varchar(12)      | NO   |     |         |                |
| picture          | varchar(255)     | NO   |     |         |                |
| init             | varchar(64)      | YES  |     |         |                |
| data             | longtext         | YES  |     | NULL    |                |
| timezone_name    | varchar(50)      | NO   |     |         |                |

+------------------+------------------+------+-----+---------+----------------+

Here's the Drupal 7 users table:

> show columns from users;
+------------------+------------------+------+-----+---------+-------+
| Field            | Type             | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+-------+
| uid              | int(10) unsigned | NO   | PRI | 0       |       |
| name             | varchar(60)      | NO   | UNI |         |       |
| pass             | varchar(128)     | NO   |     |         |       |
| mail             | varchar(254)     | YES  | MUL |         |       |
| theme            | varchar(255)     | NO   |     |         |       |
| signature        | varchar(255)     | NO   |     |         |       |
| signature_format | varchar(255)     | YES  |     | NULL    |       |
| created          | int(11)          | NO   | MUL | 0       |       |
| access           | int(11)          | NO   | MUL | 0       |       |
| login            | int(11)          | NO   |     | 0       |       |
| status           | tinyint(4)       | NO   |     | 0       |       |
| timezone         | varchar(32)      | YES  |     | NULL    |       |
| language         | varchar(12)      | NO   |     |         |       |
| picture          | int(11)          | NO   | MUL | 0       |       |
| init             | varchar(254)     | YES  |     |         |       |
| data             | longblob         | YES  |     | NULL    |       |
| uuid             | char(36)         | NO   | MUL |         |       |

+------------------+------------------+------+-----+---------+-------+

(It l
ooks to me like Drupal 6 has a bunch of extra fields that Drupal 7 either doesn't need, or needs stored elsewhere than the users table.  This is a sign of the growing pains that Drupal experienced as it scaled up and realized that it needed to segregate certain types of data (longblob, for example) away from being stored in the users table.)

| mode             | tinyint(4)       | NO   |     | 0       |                |
| sort             | tinyint(4)       | YES  |     | 0       |                |
| threshold        | tinyint(4)       | YES  |     | 0       |                |

Let's experiment with moving one identity between the two sites:

> select name from users where name like "Graham Leach";
+--------------+
| name         |
+--------------+
| GL           |
+--------------+


OK, let's move this identity into Drupal 7 using SQL and see what happens.

>select * from drupal_users where name like "GL%";


7143 | GL | c62d929e7b7e7b6165923a5dfc60cb56 | graham.r.leach@gmail.com |    0 |    0 |         0 |       |           |                0 | 1525530489 | 1571635877 | 1571635877 |      1 | NULL     | en       |         | graham.r.leach@gmail.com

Using this information, I hand crafted a test SQL statement to see if I could log into the Drupal 7 with this identity (GL or graham.r.leach@gmail.com)

Password Problems


The first obstacle I hit was the fact that the password scheme has changed between Drupal 6 (MD5) and Drupal 7 (SHA512).  This means that transporting the password over between the two systems is practically impossible.  

I do not have the "secret" necessary to calculate the new SHA512-compliant result, which is how the Drupal 7 system works:

1.  Get username & password
2.  Check for username in users table

3.  If found, compare SHA512("password") with stored password
4.  If they match, let the user in




Sequence Number


Get the largest uid number from the users table:


Get the highest uid number from the sequences table (users_uid):


Update the users_uid number in the sequences table to be higher than the highest number in the users table, so when the next user registers there's no uid clash.



How we fix the sequence number:
insert into sequences (name, id) values ('users_uid', 100000);



References




https://smbjorklund.no/how-migrate-content-drupal-6-7-using-migrated2d-part-1


https://justmagicdesign.com/blog/201404/upgrading-website-drupal-6-drupal-7-migrating-users

https://www.drupal.org/forum/support/post-installation/2007-01-06/manually-adding-users


Saturday, October 19, 2019

Drupal 7 / Ubercart 7 - Add Mobile number to Contact Form

Drupal core 7.67 / Ubercart 7.x-3.13

We would like to get the mobile number of the people who contact us, so we can reach them by WhatsApp, Line, WeChat, etc...

Unfortunately, adding a simple phone number field to the contact form is a real pain, so the fastest way to do this is to simply add some code to the contact form

WARNING:  WE ARE MODIFYING DRUPAL CORE!  EEEEEK!

Navigate to <Drupalroot>/modules/contact

Then, add these lines of code to contact.pages.inc, around line 98:

    $form['phone'] = array('#type' => 'textfield',
        '#title' => t('Phone number:'),
        '#maxlength' => 20,
        '#required' => TRUE,
    );


See example below:



Next, we need to add the email functionality to Drupal to include the mobile field contents in the notification email:

Add these lines of code to contact.module, around line 184:


      // GL 2019-10-20  Add mobile number to contact form email - BEGIN
      $message['body'][] = t('Mobile:', $variables, array('langcode' => $language->language));
      $message['body'][] = $params['mobile'];
      // GL 2019-10-20  Add mobile number to contact form email - END


Remember to add the lines of code under both of these sections:

  • page_copy
  • user_copy

See example below:




Here's what the contact form looks like after these changes have been made:



Here's what the resulting email looks like:



References:

https://www.drupal.org/forum/support/module-development-and-code-questions/2006-09-11/field-for-phone-number-on-contact

Drupal 7 / Ubercart 7 - Watch out for LANGUAGE NEUTRAL

Drupal core 7.67 / Ubercart 7.x-3.13
If things are not translating, check to make sure that the base term is set to English, not Language Neutral.

Drupal 7 / Ubercart 7 - Hide List Price

Drupal core 7.67 / Ubercart 7.x-3.13

Seeing as we are a premium business, we don't really do the discounting thing.

We have no need for List price being shown to users when they look at one of our products




So, how to prevent it from being displayed?


First, go to the Manage Display area of Product within the Content types area of the website, then change the Format to Hidden:




Click on Save



Now, List price should be gone.