name: prestashop_moodle_user_enrolment_course
description: 'Enrol your Prestashop Customer to Moodle courses (Prestashop product = Moodle course)'
rules:
    -
        name: Users
        nameSlug: users
        sourceSolution: prestashop
        targetSolution: moodle
        sourceModule: customers
        targetModule: users
        fields:
            - { target: email, source: email, formula: null }
            - { target: firstname, source: firstname, formula: null }
            - { target: lastname, source: lastname, formula: null }
            - { target: username, source: firstname;lastname, formula: 'lower({firstname}.{lastname})' }
            - { target: createpassword, source: my_value, formula: '"1"' }
        params:
            - { name: delete, value: '60' }
            - { name: datereference, value: '1970-01-01 00:00:00' }
            - { name: mode, value: '0' }
            - { name: limit, value: '100' }
            - { name: duplicate_fields, value: email }
            - { name: description, value: 'Send Prestashop customers to Moodle users' }
    -
        name: Course
        nameSlug: course
        sourceSolution: prestashop
        targetSolution: moodle
        sourceModule: products
        targetModule: courses
        fields:
            - { target: fullname, source: name, formula: null }
            - { target: shortname, source: name, formula: null }
            - { target: summary, source: description, formula: null }
            - { target: categoryid, source: my_value, formula: '"1"' }
        params:
            - { name: delete, value: '60' }
            - { name: datereference, value: '1970-01-01 00:00:00' }
            - { name: mode, value: '0' }
            - { name: limit, value: '100' }
            - { name: duplicate_fields, value: 'shortname' }
            - { name: description, value: 'Send Prestashop products to Moodle courses' }
    -
        name: Order
        nameSlug: order
        sourceSolution: prestashop
        targetSolution: moodle
        sourceModule: orders
        targetModule: users
        relationships:
            - { fieldNameSource: id_customer, fieldNameTarget: Myddleware_element_id, fieldId: users, parent: false }
        params:
            - { name: delete, value: '60' }
            - { name: datereference, value: '1970-01-01 00:00:00' }
            - { name: mode, value: U }
            - { name: limit, value: '100' }
            - { name: description, value: 'This rule creates a link between Prestashop customer orders and Moodle users. It is required to manage enrollment.' }
    -
        name: Enrolment
        nameSlug: enrolment
        sourceSolution: prestashop
        targetSolution: moodle
        sourceModule: order_details
        targetModule: manual_enrol_users
        fields:
            - { target: roleid, source: my_value, formula: '"5"' }
        relationships:
            - { fieldNameSource: product_id, fieldNameTarget: courseid, fieldId: course, parent: false }
            - { fieldNameSource: id_order, fieldNameTarget: userid, fieldId: order, parent: false }
        params:
            - { name: delete, value: '60' }
            - { name: datereference, value: 0 }
            - { name: mode, value: C }
            - { name: limit, value: '100' }
            - { name: description, value: 'Create Moodle enrollment depending on the product ordered by Prestashop customers.' }
