1

I have few questions about importing users into Craft CMS using feedme. These users would be also Craft Commerce customers.

  • Users will be imported without passwords. Would this provide some kind of security risk, for example, someone being able to log in with empty password?
  • Setting new passwords for users - would I need to write custom module to send password reset form to each imported user? Would not sending 5000 emails at once choke Craft - maybe I should use tasks for that?
  • Addresses - do i need to write some custom plugin for importing adddress data along with basic user data like email? I didnt saw any fields for setting up user address when i tested importing users using feedme. Did someone managed to tackle this issue in the past?
1
  • I have a problem with Feed Me. when i added the URL's of File in Feed URL, I can't connect the Data and I can't see the Change. what is the Problem? Commented Feb 6, 2023 at 11:19

2 Answers 2

2

Users will be imported without passwords. Would this provide some kind of security risk, for example, someone being able to log in with empty password?

I don't think the imported users will be able to login at all without a password.

Setting new passwords for users - would I need to write custom module to send password reset form to each imported user? Would not sending 5000 emails at once choke Craft - maybe I should use tasks for that?

I handled this by setting a message on the login and forgot password pages, skipping the need to send an email. Something like "Our systems were upgraded on 10-20-2020, if you've not logged in since then you'll need to reset your password first".

Addresses - do i need to write some custom plugin for importing adddress data along with basic user data like email? I didnt saw any fields for setting up user address when i tested importing users using feedme. Did someone managed to tackle this issue in the past?

Yes, you will need to use a custom module/plugin and listen to feedme events and handle address import with your code.

Something like:

 Event::on(Process::class, Process::EVENT_STEP_AFTER_ELEMENT_SAVE, function (FeedProcessEvent $event) {
   /// your code here dealing with $event->feedData;         
});
1

I had to import user data from Prestashop into Craft Commerce v4 and came up with this solution, which uses a Yii module.

// Create address elements from feed-me import
Event::on(
    Process::class, 
    Process::EVENT_STEP_AFTER_ELEMENT_SAVE, 
    function(FeedProcessEvent $event) {
        $addressElement = $this->_createAddress($event->contentData, $event->element->id);
});

I then adapted a function I found in the UpdateController in Commerce 4 that is used to update existing Commerce 3 installations:

private function _createAddress($data, $id): Address
    {

        $address = new Address();
        $address->title = 'Meine Adresse';

        // set the owner (user) of the address element
        if (isset($id)) {
            $address->ownerId = $id;
        }

        $address->addressLine1 = $data['addressline1'];
        if (isset($data['addressline2'])) {
            $address->addressLine2 = $data['addressline2'];
        }

        $address->countryCode = 19;

        switch ($data['countryid']) {
            case '19':
                $address->countryCode = 'CH';
                break;
            case '1':
                $address->countryCode = 'DE';
                break;
            case '2':
                $address->countryCode = 'FR';
                break;
            case '130':
                $address->countryCode = 'LI';
                break;
            case '10':
                $address->countryCode = 'IT';
                break;
        }

        $address->administrativeArea = null;

        $address->postalCode = $data['postalcode'];
        $address->locality = $data['city'];
        $address->dependentLocality = '';

        if ($data['firstname'] || $data['lastname']) {
            $address->fullName = implode(' ', array_filter([$data['firstname'], $data['lastname']]));
        }

        if (isset($data['company'])) {
            $address->organization = $data['company'];
        }

        $address->dateCreated = DateTimeHelper::toDateTime($data['dateupdate']);
        $address->dateUpdated = DateTimeHelper::toDateTime($data['postalcode']);
        Craft::$app->getElements()->saveElement($address, false, false, false);

        return $address;
    }

You might not need all the code in this function but you will get the idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.