Skip to main content

Voyado Engage

Installation of Magento 2 extension

This module provides an integration between Voyado Engage and Magento 2.

Requirements
  • Magento 2.3.x or higher, open source or commerce

  • PHP 7.4 or higher

  • RabbitMQ

  • Voyado account

Installation

Add this repository to your composer:

composer config repositories.voyado composer 
https://gitlab.com/api/v4/group/11993948/-/packages/composer/

To be able to require the module:

composer require voyado/magento2
Flows

See PlantUML flows in src/doc.

Extending

When, for instance, more data needs to be send to Engage in the order receipt, the module can be extended. An approach on how to do this is described here:

Note

Replace ‘VendorName’ with your own vendor name.

app/code/VendorName/ExtendedVoyado/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'VendorName_ExtendedVoyado',
    __DIR__
);

app/code/VendorName/ExtendedVoyado/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">

    <module name="VendorName_ExtendedVoyado" setup_version="1.0.0">
        <sequence>
            <module name="Voyado_Magento2" />
        </sequence>
    </module>
</config>

app/code/VendorName/ExtendedVoyado/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Voyado\Magento2\Helper\VoyadoHelper">
        <plugin name="VendorName_ExtendedVoyado_Plugin_AddOwnAttributeToOrderItem"
                type="VendorName\ExtendedVoyado\Plugin\AddOwnAttributeToOrderItem" />
    </type>
</config>

app/code/VendorName/ExtendedVoyado/Plugin/AddOwnAttributeToOrderItem.php

<?php

namespace VendorName\ExtendedVoyado\Plugin;

use Voyado\Magento2\Helper\VoyadoHelper;

class AddOwnAttributeToOrderItem
{
    /**
     * @param VoyadoHelper $object
     * @param array $result
     * @param mixed $orderItem
     * @return array
     */
    public function afterGetExtraDataForItem(VoyadoHelper $object, $result, $orderItem)
    {
        if ($orderItem->getProduct() !== null) {
            if ($orderItem->getProduct()->getTypeId() === 'simple') {
                if ($orderItem->getProduct()->getAttributeText('my_own_attribute') !== false) {
                    $result['my_own_attribute'] = $orderItem->getProduct()->getAttributeText('my_own_attribute');
                }
            } elseif ($orderItem->getProduct()->getTypeId() === 'configurable') {
                $options = $orderItem->getProductOptions();
                if (isset($options['attributes_info'])) {
                    foreach ($options['attributes_info'] as $option) {
                        if ($option['label'] === 'My Own Attribute Label') {
                            $result['my_own_attribute'] = $option['value'];
                            break;
                        }
                    }
                }
            }
        }
        return $result;
    }

    /**
     * @param VoyadoHelper $object
     * @param array $result
     * @param mixed $orderItem
     * @return array
     */
    public function afterGetExtraDataForReceiptItem(VoyadoHelper $object, $result, $orderItem)
    {
        if ($orderItem->getProduct() !== null) {
            if ($orderItem->getProduct()->getTypeId() === 'simple') {
                if ($orderItem->getProduct()->getAttributeText('my_own_attribute') !== false) {
                    $result = [
                        [
                            'name' => 'my_own_attribute',
                            'value' => $orderItem->getProduct()->getAttributeText('my_own_attribute')
                        ]
                    ];
                }
            } elseif ($orderItem->getProduct()->getTypeId() === 'configurable') {
                $options = $orderItem->getProductOptions();
                if (isset($options['attributes_info'])) {
                    foreach ($options['attributes_info'] as $option) {
                        if ($option['label'] === 'My Own Attribute Label') {
                            $result = [
                                [
                                    'name' => 'my_own_attribute',
                                    'value' => $option['value']
                                ]
                            ];
                            break;
                        }
                    }
                }
            }
        }
        return $result;
    }
}
Consents

For the contact, it’s possible to add the consents by creating two plugins:

  • afterGetConsents for class Voyado\Magento2\Helper\ContactAttributesHelper

  • afterGetConsents for class Voyado\Magento2\Helper\OrderBodyHelper

For addOrder and creditMemo, the function will receive true for argument ‘fromOrder’.

The method getConsents can be found in class Voyado\Magento2\Helper\VoyadoHelper and only returns an empty array. Per index, an array should be added with these keys (values are examples):

[
    "id" => "consentGeneralTerms",
    "value" => true,
    "date" => "2021-03-15T16:32:42+01:00",
    "source" => "string",
    "comment" => "string"
]
Development

The module has quality assurance scripts in place. To activate them, run:

composer install

Note

Use composer 2 and PHP 7.4.

You’ll be asked for Magento credentials, best to use those for Magento Enterprise. Do not store them as they are needed just once.

You’ll need a GitLab-token, create an auth.json with them:

{
    "gitlab-token": {
        "gitlab.com": "generate-this-in-your-gitlab-account"
    }
}

Now, when changes are committed, GrumPHP will perform some checks.