PHP code example of kustomer / kustomer-integration

1. Go to this page and download the library: Download kustomer/kustomer-integration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kustomer / kustomer-integration example snippets




namespace MyCompany\MyModule\Observer;

use Kustomer\KustomerIntegration\Observer\KustomerEventObserver;
use Magento\Framework\Event\Observer as EventObserver;

class MySubscriptionObserver extends KustomerEventObserver
{
    /**
     * @param EventObserver $observer
     */
    public function execute(EventObserver $observer)
    {
        $subscription = $observer->getEvent()->getSubscription();
        $customer = $subscription->getCustomerId();

        $type = 'subscription';
        $data = array(
            'plan' => $subscription->getPlan(),
            'term' => $subscription->getTerm(),
            'period_start' => $subscription->getPeriodStart(),
            'period_end' => $subscription->getPeriodEnd()  
        );
        $this->publish($type, $data, $customer);
    }
}


class MySubscriptionObserver extends KustomerEventObserver
{
    /**
     * @param EventObserver $observer
     */
    public function execute(EventObserver $observer)
    {
        $customer = $observer->getEvent()->getCustomer();

        $type = 'customer';
        $data = [];
        $this->publish($type, $data, $customer);
    }
}