kustomer/kustomer-integration 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kustomer/kustomer-integration

Composer 安装命令:

composer require kustomer/kustomer-integration

包简介

Integrate Magento eCommerce site with Kustomer service

README 文档

README

This extension allows publication of Adobe Commerce events to Kustomer. It provides a KustomerEventObserver class that you can extend to publish events to your Kustomer account.

Installation

  1. $ composer require kustomer/kustomer-integration from your Adobe Commerce project root
  2. $ bin/magento module:enable Kustomer_KustomerIntegration --clear-static-content
  3. $ bin/magento setup:upgrade
  4. $ bin/magento setup:di:compile

Notes

Packagist

If you are using the default adobe commerce metapackage, you will need to add the packagist repo to your store's composer.json:

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://repo.magento.com/"
        },
        {
            "type": "composer",
            "url": "https://packagist.org"
        }
    ]
}

Find more detailed instructions here

Cron

The extension makes use of a cron job to collect events and send them to Kustomer and thus requires cron to be installed on the Adobe Commerce server.

You can check if the cron was installed correctly with crontab -l. If the cron does not show up, run bin/magento cron:install in your Adobe Commerce dir. This command is available with Adobe Commerce 2.2.

Setup

Use of this extension requires an active Kustomer subscription. More information about Kustomer can be found on our website.

Before you can start sending data to Kustomer, you must install the Adobe Commerce app in your Kustomer account. You can do this by logging into the Kustomer app then go to Settings>>App Directory and click Install for Adobe Commerce.

Once Adobe Commerce is enabled on your Kustomer account, you need to create an API key so your Adobe Commerce store can send data to Kustomer. In the Kustomer app, go to Settings>>API Keys. Create a key here with the role org.user and keep a copy of the key handy. You will need it.

Next, go to your Adobe Commerce store's admin site and navigate to Store>>Configuration>>Customers>>Kustomer (if the Kustomer option is not available, see the installation instructions above). Select the store/website you want to integrate with Kustomer (or stay in the default scope if you want to use the integration globally). Enter the API key you generated in Kustomer into the API Key box and make sure the Enabled option is set to Yes. Next, select any of the default events you want to broadcast to Kustomer (such as when a new Customer is created) and click Save. You should be all set!

Pausing the Extension

If you want to stop sending data to Kustomer, you can turn off the extension at any time by returning to the settings page and setting the Enabled value to No. Note that any data collected while the extension is off will not be sent to Kustomer.

Custom Events and Objects

While the Kustomer Extension comes with a few pre-made events (new customers, orders, etc.), it is possible to send add your own custom events to Kustomer. To do this, create your own module and make sure kustomer/kustomer-integration is one of the requirements in composer.json. For more information about creating Adobe Commerce Modules, see the Adobe Commerce Developer Documentation.

Then create an Observer under Observers/MySubscriptionObserver.php and extend the KustomerEventObserver class. If you wanted to send a custom Subscription object to Kustomer when it is created, you might do something like this:

<?php

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);
    }
}

Note that the KustomerEventObserver.publish() method requires a $type string, an array of $data (this is will be your object in Kustomer) and a $customer variable that is either a customer ID or an instance of CustomerInterface.

We also recommend you explicitly select which fields you send to Kustomer. This will avoid inadvertently sharing information you may not want to share with Kustomer, such as passwords.

Once your observer is ready, you need to register it in your module's etc/events.xml file. This example might look like this:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="subscription_create_success">
        <observer name="my_subscription_observer" instance="MyCompany\MyModule\Observer\MySubscriptionObserver" />
    </event>
</config>

Subscription objects will automatically be ingested by Kustomer and associated with your customer as Kustom Objects belonging to a dynamically-generated Klass.

Customer Only Events

If you just want to send the Customer object, you can assign $type a value of 'customer' and pass an empty array as $data:

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

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

kustomer/kustomer-integration 适用场景与选型建议

kustomer/kustomer-integration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.66k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 kustomer/kustomer-integration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kustomer/kustomer-integration 我们能提供哪些服务?
定制开发 / 二次开发

基于 kustomer/kustomer-integration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 34
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: OSL-3.0
  • 更新时间: 2018-03-27