mediact/robinhq-hooks

此包的最新版本(2.3.3)没有可用的许可信息。

安装: 606

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 9

类型:magento-module

2.3.3 2018-12-05 13:04 UTC

This package is auto-updated.

Last update: 2024-09-06 09:17:42 UTC


README

这份README需要更新

Magento Robin集成

此包设计为一个起点,并展示了如何在您的Magento商店中使用ROBIN API。它目前会在创建或更新客户和/或订单时,通过前后端将数据发送到ROBIN。该模块已在Magento 1.7、1.8和1.9版本中进行了测试。

依赖项

请注意,此包依赖于https://github.com/jkowens/magento-jobqueue。在安装和使用此包之前,请先安装它,否则此包将无法使用。您还需要启用magento cron以使队列工作。

设置

确保您有ROBIN API密钥和API密钥。如果您没有API密钥,[您可以在此处请求][request-api-key-secret]。如果您不知道在哪里找到API密钥,也可以询问ROBIN人员。

安装

  • 克隆或下载git仓库
  • 如果您下载了仓库,请解压它
  • 复制文件,最好使用rsync(rsync -rtlv --progress /location/of/package_files/ /location/of/magento/)
  • 从管理员界面注销,刷新缓存,然后重新登录

安装了什么?

模块安装在app/code/community/Robinhq/Hooks文件夹中,包设置文件位于app/etc/modules/Robin_Hooks.xml中。管理员设计文件是:design/adminhtml/default/default/layout/Hooks.xmldesign/adminhtml/default/default/template/hooks/hooksbackend.phtml。该模块没有自己的sql文件或数据库,api密钥和密钥通过Magento的配置保存。

下一步

如果没有出现任何错误,那就太好了!现在注销并再次登录,以确保Magento注意到了这些更改。现在您可以重新开启安装过程中关闭的编译。同时,在缓存管理中禁用配置。我再次想确认您已经拥有了[api密钥和密钥][request-api-key-secret],否则模块将无法工作!

现在转到系统 -> 配置 -> ROBINHQ -> 设置 -> API设置,填写您的API密钥和API密钥。API基础URL已经为您提供,还有字段Seconds to waitBulk Limit,这些设置是在您想进行批量导入时使用的。在填写了两个密钥之后,点击保存配置,您就完成了!所有未来的订单和客户在创建和/或更改时都将自动发送到ROBIN。

初始数据

您可能已经注意到在您的后端菜单栏中出现了新的Robin标签。这是为了将现有客户及其订单发送到ROBIN。要开始这个过程,只需转到Robin -> 批量发送,然后点击运行按钮。

警告和日志记录

默认情况下,包将记录发生的事情,并在出现问题时在管理员页面显示通知。要查看日志文件,通过ssh登录到您的Web服务器,并导航到您的Magento根文件夹。

要查看日志文件的内容,请执行以下操作var/log/Robinhq_hooks.log 使用tail来监视它。

确保您已从Magento的开发者设置中启用日志记录。

开发

事件

此模块监听以下事件

  • customer_save_after
  • sales_order_place_after
  • sales_order_save_after

customer_save_after

当创建客户、修改客户信息或客户下单时,此事件会被调用。在这个事件中,根据 etc/config.xml 中定义,将执行 Robinhq_Hooks_Model_Observer::customerHook

<config>
    <global>
        <events>
            <customer_save_after> <!-- identifier of the event we want to catch -->
                <observers>
                    <customer_save_after_handler> <!-- identifier of the event handler -->
                        <type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
                        <class>hooks/observer</class> <!-- observers class alias -->
                        <method>customerHook</method>  <!-- observer's method to be called -->
                        <args></args> <!-- additional arguments passed to observer -->
                    </customer_save_after_handler>
                </observers>
            </customer_save_after>
        </events>
    </global>
</config>

sales_order_place_after

下单后,此事件会被调用。在这个事件中,根据 etc/config.xml 中定义,将执行 Robinhq_Hooks_Model_Observer::orderPlacedHook

<config>
    <global>
        <events>
           <sales_order_place_after> <!-- identifier of the event we want to catch -->
               <observers>
                    <sales_order_place_after_handler> <!-- identifier of the event handler -->
                        <type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
                        <class>hooks/observer</class> <!-- observers class alias -->
                        <method>orderPlacedHook</method>  <!-- observer's method to be called -->
                        <args></args> <!-- additional arguments passed to observer -->
                     </sales_order_place_after_handler>
               </observers>
            </sales_order_place_after>
        </events>
    </global>
</config>

sales_order_save_after

订单状态改变或任何其他类型的订单相关更改被保存后,此事件会被调用。在这个事件中,根据 etc/config.xml 中定义,将执行 Robinhq_Hooks_Model_Observer::orderStatusChanceHook

<config>
    <global>
        <events>
           <sales_order_save_after> <!-- identifier of the event we want to catch -->
                <observers>
                    <sales_order_save_after_handler> <!-- identifier of the event handler -->
                        <type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
                        <class>hooks/observer</class> <!-- observers class alias -->
                        <method>orderStatusChanceHook</method>  <!-- observer's method to be called -->
                        <args></args> <!-- additional arguments passed to observer -->
                    </sales_order_save_after_handler>
                </observers>
                </sales_order_save_after>
        </events>
    </global>
</config>

代码

Robinhq_Hooks_Model_Observer 类是我们挂钩到所有事件的入口类。从那里,通过使用 Robinhq_Hooks_Model_Api::orders()Robinhq_Hooks_Model_Api::customers()` 来调用 API。

Robinhq_Hooks_Model_Api::orders()

此方法遍历所有给定的订单,将其映射为 [Robin API][robin-api] 所需的 RobinOrder,并发送到 orders API 端点。要生成 RobinOrder,使用 Robinhq_Hooks_Model_RobinOrder::factory() 方法。此方法收集订单详情,如产品、发货和发票,并根据 [Robin API][robin-api] 所需的 details_view 对象进行格式化。

{
  "orders": 
  [
    {
      "email_address":  "email@address.com",
      "order_number":  "RHQO1234",
      "url":  "http://shop.com/order/RHQO1234",
      "order_by_date" : "2014/01/29",
      "list_view": 
      {
         "order_number":  "RHQO1234",
         "date":  "29-01-2014 12:34",
         "status":  "In progress"
      },
      "details_view": 
      [    
        {
          "display_as": "details",      
          "data": 
          {
             "date":  "29-01-2014 12:34",
             "status":  "In progress",
             "payment_status":  "Partially paid",
             "shipment_status":  "Partially shipped"
          }
        }, 
        {
          "display_as": "columns",
          "caption": "products",
          "data" :
          [
            {
              "product":  "iPhone 5S",
              "quantity":  "1",
              "price":  "$695.50"
            },
            {
              "product":  "iPad 3",
              "quantity":  "2",
              "price":  "$898.00"
            },
            {
              "product":  "Shipment",
              "quantity":  "",
              "price":  "$10.00"
            },
            {
              "product":  "Total",
              "quantity":  "",
              "price":  "$1603.50"
            }
          ]
        },
        {
          "display_as": "rows",
          "caption": "shipments",
          "data":           
          [
            {
              "shipment":  
                 "<a href=' http://shop.com/shipment/RHQS01'>RHQS01</a>",
              "status":  "Shipped"
            },
            {
              "shipment":  
                 "<a href=' http://shop.com/shipment/RHQS02'>RHQS02</a>",
              "status":  "Not shipped"
            }
          ]
        },
        {
          "display_as": "rows",
          "caption": "invoices",
          "data":           
          [
            {
              "shipment":  
                 "<a href=' http://shop.com/invoice/RHQI01'>RHQI01</a>",
              "status":  "Paid",
              "amount":  "$1200.00"
            },
            {
              "shipment":  
                 "<a href=' http://shop.com/invoice/RHQI02'>RHQI02</a>",
              "status":  "Not paid",
              "amount":  "$403.50"
            }
          ]
        }
      ]
    }
  ]
}

Robinhq_Hooks_Model_Api::customers()

此方法遍历所有给定的客户,并将它们映射为 [Robin API][robin-api] 所需的 RobinCustomer,并发送到 customers API 端点。要生成 RobinCustomer,使用 Robinhq_Hooks_Model_RobinCustomer::factory() 方法。此方法创建 [Robin API][robin-api] 所需的客户对象。

{
      "email_address":  "email@address.com",
      "customer_since":  "2014-01-28",
      "order_count":  12,
      "total_spent":  "$154.95",
      "panel_view":  
      {
         "Orders":  "12",
         "Total_spent":  "$154.95"
      },
      "name": "John Doe",
      "currency":"EUR",
      "phone_number":"0612345678"
}

ROBIN API 文档还提到了可选数据。此软件包默认发送这些字段。

panel_view 包含了一个新的键值对对象,可以是任何内容。例如,我添加了总订单数和总支出。如何在 [Robin API][robin-api] 文档中使用 panel_view 数组进行了说明。

向 Robin 发送更多订单数据

您可以通过在 Robinhq_Hooks_Model_RobinOrder::getDetailsView() 中每个方法的返回值中的 list_viewdata 数组中添加键值对来扩展您想要在 Robin 中可见的数据。如果您想添加一个新的 details_view,例如订单的评论,您可以在 Robinhq_Hooks_Model_RobinOrder::getDetailsView() 方法中添加逻辑,如下所示

private function getDetailsView(){
        $details = $this->getDetails();
        $productsOverview = $this->getProductsOverview();
        $shipments = $this->getShipments();
        $invoices = $this->getInvoices();
        $comments = $this->getComments(); //new line of code!
        return array($details, $productsOverview, $shipments, $invoices, $comments); //the order of this array determines the order of the different panel views you have inside the Robin conversation
    }

现在在 Robinhq_Hooks_Model_RobinOrder 中创建一个名为 getComments 的新方法,让它返回一个包含评论数据的数组,布局如下

{
    "display_as":"rows",
    "caption": "Order Comments",
    "data": []
}

data 键中,您可以添加一个包含对象的数组,每个对象都包含键值对,如下所示

{
    "Date:":"Jun 24, 2014 2:35:41 AM",
    "Content:": "This is a comment from the admin",
    "Order Status:":"On Hold",
    "Customer Notified:":"Yes"
}

注意:键的名称也将显示,因此请确保格式良好。

环境

此示例代码都是在使用 Vagrant box 的情况下开发的。如果您想根据此代码开发自己的实现,我强烈建议使用 Vagrant box 作为开发环境,因为设置快速且简单。如果您是 Vagrant 新手,请观看 [此][magento-vagrant] 简短演示,以了解最新情况。

我推荐使用 [此版本][magento-vagrant-github]。只需遵循那里提供的说明,您应该能够在短时间内拥有虚拟 Magento 安装。

Git 和 Magento 模块开发

安装的最简单方法是使用 modman。

Magento 1.9.3.3 的最新版本禁用了 symlinks 的使用,因此此安装方法不再工作或至少不应该再使用。

cd your_magento_project_dir
modman init
modman clone https://github.com/graciousstudios/magento-robin-integration.git

进入系统 -> 配置 -> 高级 -> 开发者 -> 模板设置,将 允许 Symlinks 设置为 。这里的想法是创建一个只包含模块文件和文件夹的单独文件夹,并将其链接到 Magento 安装。这样,您的 Magento 安装就不需要是 Git 仓库,您也不需要进行一些奇怪的 .gitignore 魔法。

现在您可以在 .modman/magento-robin-integration 文件夹中开发。

链接

Modman 让您轻松安装模块 modman

Magerun 允许您启用符号链接、生成 phpstorm 辅助文件、运行模块设置等。必备工具! magerun

request-api-key-secret

robin-api

许可证

代码遵循 [GPL v3 许可证][gpl-v3-licence] gpl-v3-licence