Myddleware and Magento

Myddleware and Magento

by Eric Messick -
Number of replies: 18

Hi, anyone experienced with Myddleware, Magento 2.2.2 , Moodle 3.4.1?

Wanting to make moodle users from Magento Customers. Not working. In Myddleware getting error: "invalidparameter : Invalid parameter value detectedFailed to send document. Status : Error_sending"

The connectors seem to work within Myddleware and I set up a rule to copy Magento customers names into Moodle (to create users). I installed the Myddleware plugin into Moodle and also created a custom web service as per Myddleware documentation. 

I'm unclear if I need to do anything more in Moodle. Tried adding webservice capabilities to my Moodle user and making the user authorised for the custom web service and plugin. May not have done this right.



Average of ratings: -
In reply to Eric Messick

Re: Myddleware and Magento

by Stéphane Faure -

Hi Eric,

Thanks for using Myddleware.

Unfortunately the error returned by Moodle hasn't much detail. So could you try to create the user manually with the same data that you have in your transfer. Moodle should give you an error too with more detail, for example, the password is too short, or username has space, a user is alreday existing with the same email address...
When you have the error, you could change your data transfer and your rule.

The good news is, if Moodle returns this error, it means that your connection is working. It is better to get an erro than nothng ;).

Could you tell us if your problem is solved ? Thanks.

If you still have the error, could you show us the detail of a data transfert (but don't share client real data). Then we will test these data in our Moodle. Thanks

Best regards,
Stéphane


Average of ratings: Useful (1)
In reply to Stéphane Faure

Re: Myddleware and Magento

by Eric Messick -

Hi. That error was actually from Myddleware. I deleted my rule and made a very simple one. 

When I make the rule, it shows that both connectors connect (light bulb lights up).

I only have only one test customer in my Magento.

In the rule, modules are Magento customers to Moodle users. I then mapped email, firstname, lastname from Magento to Moodle. The simulation works. I set synchronisation type to "create data only" and confirmed the rule.

I then run it and check the transfer and it says "no transfer found." When I check the tasks it has an entry. Status is "end" and Open, Closed, Cancelled, and Error are all "0." Start and end date are the same.

Are there specific error logs that I should look at?

Thanks for your help.





In reply to Eric Messick

Re: Myddleware and Magento

by Stéphane Faure -

Hi Eric,

For information, Myddleware tried to create the user into Moodle, and the error displayed was just the message returned by Moodle.

So you tried to create a simple rule but Myddleware can't read any data. I guess it is just because of you reference date in your rule. This date is probably later than the creation date of your client in Magento. You can have more information about this reference date here : http://community.myddleware.com/index.php/tutorial/#parameters

If you change this date to a date before the creation of a customer in Magento, Myddleware will read it.

Then, if your data transfer is stopped to "error_sending" status again. Maybe you will have to change your rule again. But this time, don't delete it, here what you can do : 1) cancel your data  transfert, 2) change your rule, 3) change the rule reference date and 4) run the rule again.

About your rule, you will maybe need to set a password, it depends on your settings in Moodle. You can find in attachment a picture of a rule we have set up between Prestashop and Moodle.

Hope it will help.

Stéphane


In reply to Stéphane Faure

Re: Myddleware and Magento

by Eric Messick -

OK changing the date parameter has made a difference, but still not transferring data.

In the transfers list I'm getting two rows with "Error_sendingX" and type "C." It looks like each row is for a customer...which makes sense because I have 2 customers in Magento. I noticed the date/time in Myddleware is 13 hours behind my server time (NZ). I did set timezone in both php.ini files in etc/php/7.0:

 

Here is what one of the transfers looks like:



Tasks list has 2 rows, one for the manual running of the rule and one for the auto sync.  So it looks like when I change the date to 2010 and run it manually it is trying to send data...and that when the auto sync runs it it is not trying because the data parameter changes back to today:



Apache error log...one of my customers in Magento has no middle name so looks like that is reason for PHP notice:

[Wed Feb 14 12:00:39.054910 2018] [:error] [pid 5814] [client MYHOMEIPADDRESS:6412] PHP Warning:  Invalid argument supplied for foreach() in /var/www/myddleware/src/Myddleware/RegleBundle/Solutions/magento.php on line 268, referer: https://www.MYWEBSITE.COM/myddleware/rule/view/5a82462ba606d

[Wed Feb 14 12:00:39.460000 2018] [:error] [pid 5814] [client MYHOMEIPADDRESS:6412] PHP Warning:  Invalid argument supplied for foreach() in /var/www/myddleware/src/Myddleware/RegleBundle/Solutions/magento.php on line 268, referer: https://www. MYWEBSITE.COM/myddleware/rule/view/5a82462ba606d

[Wed Feb 14 12:02:02.267397 2018] [:error] [pid 5964] [client MYHOMEIPADDRESS:6411] PHP Notice:  Undefined index: middlename in /var/www/myddleware/src/Myddleware/RegleBundle/Classes/document.php on line 1239, referer: https://www. MYWEBSITE.COM/myddleware/rule/create/step3/5a82462ba606d

 PHP Notice:  Undefined index: middlename in /var/www/myddleware/src/Myddleware/RegleBundle/Classes/document.php on line 1021

Thanks for your help.

In reply to Eric Messick

Re: Myddleware and Magento

by Eric Messick -

I ran the rule later and had a look at the Apache access log right after:

MYSERVERIPADDRESS- - [14/Feb/2018:13:13:07 +1300] "POST /webservice/rest/server.php?wstoken=36effd29c7b6a56e743b9b7e77ca827a&wsfunction=core_webservice_get_site_info HTTP/1.1" 200 4266 "-" "MoodleBot/1.0"

MYSERVERIPADDRESS- - [14/Feb/2018:13:13:07 +1300] "POST /webservice/rest/server.php?wstoken=36effd29c7b6a56e743b9b7e77ca827a&wsfunction=core_webservice_get_site_info HTTP/1.1" 200 4266 "-" "MoodleBot/1.0"

MYSERVERIPADDRESS- - [14/Feb/2018:13:13:07 +1300] "POST /webservice/rest/server.php?wstoken=36effd29c7b6a56e743b9b7e77ca827a&wsfunction=core_user_create_users HTTP/1.1" 200 3747 "-" "MoodleBot/1.0"

MYSERVERIPADDRESS- - [14/Feb/2018:13:13:07 +1300] "POST /webservice/rest/server.php?wstoken=36effd29c7b6a56e743b9b7e77ca827a&wsfunction=core_user_create_users HTTP/1.1" 200 3747 "-" "MoodleBot/1.0"

MYSERVERIPADDRESS - - [14/Feb/2018:13:13:06 +1300] "GET /myddleware/rule/exec/5a82462ba606d HTTP/1.1" 302 4002 "https://www.MYWEBSITE.COM/myddleware/rule/view/5a82462ba606d" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36"

MYSERVERIPADDRESS - - [14/Feb/2018:13:13:07 +1300] "GET /myddleware/rule/view/5a82462ba606d HTTP/1.1" 200 5149 "https://www.MYWEBSITE.COM/myddleware/rule/view/5a82462ba606d" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36"

MYSERVERIPADDRESS - - [14/Feb/2018:13:13:08 +1300] "GET /myddleware/js/routing?callback=fos.Router.setData HTTP/1.1" 200 649 "https://www.MYWEBSITE.COM/myddleware/rule/view/5a82462ba606d" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36"


In reply to Eric Messick

Re: Myddleware and Magento

by Eric Messick -

Hi, I have had some success!  I needed to make sure that Myddleware was sending all of the required fields to Moodle in order to create a user: username, firstname, lastname, password. I didn't have all of these in the rule so it did not work.

I was able to create a user. I changed the rule to update data and this worked too.

I came across a new problem...I deleted the user in Moodle, re-ran the rule (with date set to 2010), and it did not re-create the user. When I look in "transfers" in Myddleware, the status for the customer is "send" and type is "U"...I think that means "update." So Myddleware thinks it is updating, but moodle user list doesn't change.

If I create a new customer with the same info, in Magento, it works.

I tried going into the moodle database and deleting the users but that didn't have any effect (as described here https://stackoverflow.com/questions/33547376/moodle-clean-up-database).

In reply to Eric Messick

Re: Myddleware and Magento

by Stéphane Faure -

Hi Eric,

Good news about the user creation ;).

When you put a reference date in the past, or update a customer in Magento, Myddleware will read again the customer in Magento. Then Myddleware will check if this customer has already been sent to Moodle via the current rule.

 - If no, Myddleware will create the user in Moodle.

 - If yes, Myddleware will try to update the user in Moodle except if the rule's mode is "create_only". In this case, Myddleware will cancel the data transfer. But if the rule allows the data modification, Myddleware will find the Moodle user ID by searching with the Magento customer ID in a previous data transfer in the current rule. Then Myddleware will update the user in Moodle with the user ID found in Myddleware.

In your case, you have deleted the user in Moodle but Myddleware still have the user ID and try to update it even if it is deleted. Moodle doesn't seem to return an error when we try to update a deleted user. This is weird.

So if you delete a user in Moodle, you have 2 methods to handle it :

 - First method : delete the customer in Magento too, you will be sur that it won't be read again by Myddleware

 - Second method : you have to cancel every data transfert in you rule with the Moodle user ID. It isn't possible to cancel a data transfer already sent in Myddleware UI yet. We think about allow it for super ADMIN user. But for now, you have to update directly the database.

Here is a query for that : UPDATE `Document` SET status = 'Cancel', global_status = 'Cancel' WHERE `rule_id` = '<your_rule_id>' AND `target_id`  = '<Moodle_user_id>'

Then when you will update the customer in Magento or put the reference date in the past, Myddleware will try to create the user in Moodle.

Please let me know if it solves your problem. Thanks.

Stéphane


In reply to Stéphane Faure

Re: Myddleware and Magento

by Eric Messick -

Cheers for your help Stéphane. I had to remove the quotation marks from the query and it worked.

The only other small problem I have is that Myddleware's date/time seems to be set to Europe/France timezone. In Myddleware "Europe/France" seems to be default.

I set my timezone in both php.ini files (in cli and apache2 directories) as it says in your installation instructions. I checked phpinfo and my default timezone is working. 

Thanks heaps.

Eric

In reply to Eric Messick

Re: Myddleware and Magento

by Stéphane Faure -

Great Eric,

Sorry, I forgot to answer you about the date/time. We store the date/time at GMT in the Myddleware's database. But you are right, we should display it according to the php settings.

I have created an issue in our github : https://github.com/Myddleware/myddleware/issues/78

It will be fixed in the next release. Thanks for your feedback.

Don't hesitate to create other issues if you see other things which have to be improved.

In reply to Stéphane Faure

Re: Myddleware and Magento

by Eric Messick -
Hi Stéphane. I had a good look at your tutorials and your test site for Prestashop and Suite CRM but am stuck. I'm wanting customers to gain access to my Moodle courses when they buy courses through Magento. Here is where I am struggling:


  1. When trying to make rules I am getting confused with where the field names come from for source and target. Are these from the databases? Is there somewhere I can look to easily see how these field names relate to the data that I can see in Moodle/Magento?
  2. For "relationships," in my source column (for magento) drop-down menus there are two options: "ID orders" and "Customer ID." "Customer ID" is listed as a possible field for the rule, but "ID orders" is not. Where are these field names from..or is this a bug?
  3. Some field names in the target have stars next to them (E.g., email, firstname, lastname, username in Moodle), is that because these are required fields?
  4. When I click on "create formula" when making a rule, and then click on the target drop-down menu, I have only one field (auth) and its data options for Moodle as a target...seems like the drop-down should have all fields...is that a bug?
  5. I don't understand how "relationships" work. I think this is what I need to do to link orders with customers like in your test server. Seems like I need some unique identifier for items purchases...probably the SKU. So thinking that Myddleware would use a rule to detect a new order and pass the customer and SKU to the right fields in moodle so that the customer gets enrolled in the course identified by the SKU.
  6. If you have any Moodle/Magento working examples of rules then that would be helpful. The screenshot of the rule you sent me earlier was really helpful in making formulae (thanks).

Best,

Eric


In reply to Eric Messick

Re: Myddleware and Magento

by Stéphane Faure -

Hi Eric,

Sorry for the delay of our answer.

1. We usually use an API function to get the available fields and modules. However, these kind of function doesn’t exist for Moodle so we have added manually the fields and module into Moodle connector. About Magento, we have to improve the connector to use the metadata endpoints like  /V1/attributeMetadata/customer

2.The ID orders field is the id of the current module (order here). It should be available in the list field. We will have a look when we will improve the connector.

3.This stars are just an indication in Myddleware to show which field should be required in the target application. However, for some reasons we don't force you to fill them in Myddleware.

4.There are only the values for picklist field in the dropdown. But for Moodle and Magento, we have added them manually. We will improve this for Magento when we will work on the Magento connector.

5.About relationship, you can read this tutorial, we talk about relationship in the chapters 3.2.3 and 6.1) : http://community.myddleware.com/index.php/tutorial/

6.Unfortunately we have only example between Moodle and Prestashop with a Myddleware template. This template create few rules in Myddleware to send Prestashop Client to Moodle user and to enrol them to Moodle courses depending of which product they bought.

The problem is that Magento connector isn’t complete like Prestashop connector is. There is some development to make to be able to do the same thing with Magento.We plan to improve the Magento connector in a few weeks.

But if you want it quickly, and if you are or you know a developer we can guide you to improve Magento connector in Myddleware. Then you could share your code in our github. If you aren’t developer and if you want we work on it, no problem, just contact us via our contact page : http://www.myddleware.com/contact-us Then we will talk privately.

Have a nice day,

Stéphane

In reply to Stéphane Faure

Re: Myddleware and Magento

by Eric Messick -

OK, that all makes sense thank you.


In reply to Eric Messick

Re: Myddleware and Magento

by Eric Messick -

Hi Stéphane.


I thought I'd check to see if I could help with the Moodle connector. I'm not a developer. I taught myself how to use Unix, Moodle, and set up a server. So I might not be very useful to you.

The main thing I am wanting is for the connector to enrol people into a Moodle course when they buy it in Magento.

You mentioned that you had to manually enter fields for the connector...I'm happy to do this if I can get some direction from you on what to do.

Thanks.
Eric

In reply to Eric Messick

Re: Myddleware and Magento

by Stéphane Faure -

Hi Eric,

Thanks for using Myddleware.

The file to add fields in Magento is src\Myddleware\RegleBundle\Solutions\magento.php

The function to be changed is get_module_fields

However, the best way to modify Myddleware is to redefined class in the custom directory. But it will be a bit tricky if you are nit a developer. Could you tell me what field you need to add ?

Thanks.

Best regards


In reply to Stéphane Faure

Re: Myddleware and Magento

by Eric Messick -

Hi. Forgive my lack of developer skills. I hope I don't waste your time. I was able to get Myddleware to create new students in Moodle when they were added as customers in Magento (see earlier in this thread).

So I THINK that what I'm now trying to figure out is if the magento.php and moodle.php files contain the fields needed so that I can map course purchases in Magento to course enrolments in Moodle. Is that right?

In those php files are the field names directly from the MySQL database fields?

In moodle.php I see the fields for courses. It has 'idnumber' and 'id' I'm not sure the difference?--I can check the database to see if that is the way to figure it out.

It seems like the way to map Magento purchases to Moodle courses is for Magento purchases to have a field that contains the Moodle Course ID number? So that field then maps directly to the Moodle course id field via Myddleware. Does that sound right?

So I think that the 'id' field or the 'entity_id' field under "case 'orders':" in magento.php might be the fields that could contain the Moodle course ID #?

I'm happy to keep going if this is useful. Otherwise, will wait for somebody else to work on it. Thanks!!

In reply to Eric Messick

Re: Myddleware and Magento

by Stéphane Faure -

Hi Eric,

You don't waste our time. It always very interesting to have the feedback from Myddleware users.

If I understand your needs, I guess that you have products in Magento which correspond to courses in Moodle. If yes, I guess you want the Moodle user (which is a Magento customer) be enrolled in a Moodle course (which is a Magento product) each times the customer buy a product in Magento.

We have already done that with Prestashop but not with Magento. We have to improve Magento connector to be able to do the same. Indeed we have to add 2 modules in Magento connector : "Order Items" to get the products bought by the customer and "Products" to get the product catalog.

With the 2 new modules, you will be able to create 2 others rules :

  • Magento products (catalog) to Moodle courses
  • Magento products puchaise to Moodle enrolment

Is that really what you need ?

Have a nice day,

Stéphane