定制 eoko/magento2-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

eoko/magento2-client

Composer 安装命令:

composer require eoko/magento2-client

包简介

Eoko Magento 2 client for the API

README 文档

README

Build Status

A simple PHP client to use the Magento2.

Requirements

  • PHP >= 7.1
  • Composer

Installation

We use HTTPPlug as the HTTP client abstraction layer. In this example, we will use Guzzle v6 as the HTTP client implementation.

eoko/magento2-client uses Composer. The first step to use eoko/magento2-client is to download composer:

$ curl -s http://getcomposer.org/installer | php

Then, run the following command to require the library:

$ php composer.phar require eoko/magento2-client php-http/guzzle6-adapter

If you want to use another HTTP client implementation, you can check here the full list of HTTP client implementations.

Getting started

Initialise the client

You first need to initialise the client with your credentials with admin token.

If you don't have any admin token, you can create it and retrieve with the following code :

<?php

require('./../vendor/autoload.php');

use Eoko\Magento2\Client\MagentoClientBuilder;
use Eoko\Magento2\Client\Security\AdminAuthentication;

// We initiate the client builder
$clientBuilder = new MagentoClientBuilder('http://m2.localhost:8000/rest/default');

// Create an unauthenticated client
$unAuthenticatedClient = $clientBuilder->buildAuthenticatedClient();

// Get an admin token
echo $unAuthenticatedClient->getAdminTokenApi()->getAdminToken('magento2', 'magento2');

After that, you can create an authenticated client :

<?php
require('./../vendor/autoload.php');

use Eoko\Magento2\Client\MagentoClientBuilder;
use Eoko\Magento2\Client\Security\AdminAuthentication;

$token = 'youtoken...';

// Authentication from admin token
$authentication = AdminAuthentication::fromAdminToken($token);

// Create an authenticated client
$authenticatedClient = $clientBuilder->buildAuthenticatedClient($authentication);

Get a product

$product = $client->getProductApi()->get('top');
echo $product['sku']; // display "top"

Get a list of products

By getting pages

$firstPage = $client->getProductApi()->listPerPage();

echo $page->getCount();

foreach ($page->getItems() as $product) {
    // do your stuff here
    echo $product['identifier'];
}

$nextPage = $page->getNextPage();

$firstPage = $nextPage->getPreviousPage();

By getting a cursor

$products = $client->getProductApi()->all(50);
foreach ($products as $product) {
    // do your stuff here
    echo $product['sku'];
}

Create a product

unsupported

Update a product

$client->getProductApi()->update('top', ['family' => 'tshirt']);

Stock Item

Update a stock item

$api = $client->getProductApi()->getStockItemApi('MH03-M-Blue');

// There is nothing interesting in the output (product id :/)
$api->update($item['item_id'], ['qty' => 42]);

Support

If you find a bug or want to submit an improvement, don't hesitate to raise an issue on Github.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: OSL-3.0
  • 更新时间: 2017-12-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固