smalot/magento-bundle

用于 Magento Soap 客户端 API 的 Symfony2 封装

v0.4 2016-11-25 20:45 UTC

This package is not auto-updated.

Last update: 2024-09-10 02:19:50 UTC


README

本项目是 Symfony 2 和 Magento-Client API 之间的桥梁,允许轻松调用 Magento Soap v1 API。

Scrutinizer Code Quality Total Downloads Current Version License

允许

  • 每个调用都有封装器
  • 依赖注入
  • 事件监听器
  • 调试工具栏集成
  • 以及 ... 代码补全

要求

  • Symfony >= 2.1
  • PHP >= 5.3
  • smalot/magento-client

安装

将以下行添加到您的 composer.json 文件中

{
    "require": {
        "smalot/magento-bundle": "*"
    }
}

然后运行 php composer.phar update smalot/magento-bundle

然后,在您的 kernel 中注册此包

# app/AppKernel.php

# ...

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            # ...
            new Smalot\MagentoBundle\MagentoBundle(),
        );

        return $bundles;
    }
}

配置

您需要在 connections 池中设置至少一个连接,并通过 default_connection 属性指定它。必填属性包括: urlapi_userapi_key

# app/config/config.yml

# Sample configuration
magento:
    # Refers to the default connection in the connection pool
    default_connection:   default # Example: default

    # List all available connections
    connections:

        # Prototype
        default:
            url:                  http://domain.tld/magento/
            api_user:             username
            api_key:              0123456789AZ

            # Enable logging system
            logging:              %kernel.debug%

            # Refers to the logger service
            logger:               ~

            # Refers to the dispatcher service
            dispatcher:           ~

详细信息

提供的服务

  • magento

在安全上下文中抛出的事件

  • \Smalot\MagentoBundle\MagentoEvents::PRE_LOGIN
  • \Smalot\MagentoBundle\MagentoEvents::POST_LOGIN
  • \Smalot\MagentoBundle\MagentoEvents::PRE_LOGOUT
  • \Smalot\MagentoBundle\MagentoEvents::POST_LOGOUT

在传输上下文中抛出的事件

  • \Smalot\MagentoBundle\MagentoEvents::PRE_SINGLE_CALL
  • \Smalot\MagentoBundle\MagentoEvents::POST_SINGLE_CALL
  • \Smalot\MagentoBundle\MagentoEvents::PRE_MULTI_CALL
  • \Smalot\MagentoBundle\MagentoEvents::POST_MULTI_CALL

示例代码

使用 default 连接

class MagentoController extends Controller
{
    /**
     * @Route("/", name="magento_index")
     */
    public function indexAction(Request $request)
    {
        // Retrieve default connection.
        $magento = $this->get('magento')->getManager();

        if ($magento->ping()) {
            // Call any module's class.
            $categoryManager = new \Smalot\Magento\Catalog\Category($magento);
            $tree            = $categoryManager->getTree()->execute();
        } else {
            $tree = array();
        }

        $magento->logout();

        return new Response('<html><body><pre>' . var_export($tree, true) . '</pre></body></html>');
    }
}

如果需要,可以手动指定连接

$magento = $this->get('magento')->getManager('second_connection_name');