Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Magento 2
Integration
Technologies
Alan KentMagento Chief Architect
Jeff has set up his own online store
It is doing well and sales are growing
Meet Jeff
But how does he grow his business to the next level?
Potential Integration PointsPIM
BUY BUY BUY
Buy Buttons
Native Mobile Apps
SaaS Connectors
Order Management
Internet of Things
Business Logic
(extension developers)
Integration Configuration
(system integrators)
Want separation of Business Logic from
Integration Configuration
Jeff needs to reduce the cost of integrations
Magento 2.X is Solving the Integration Challenge
Authentication made simple
Easy Custom APIs
More out-of-the-box APIs
REST
SOAP
AMQP
Service Contracts
Multiple Authentication Needs
JavaScript in web browser already has authenticated users
Enterprise systems must authenticate with humans present
Mobile apps collect credentials from users
Session Cookie
Username Password
Token OAuth 1.0a Long Life
Auth Token
Mobile App – Authentication
Authenticate using username and password
$ curl -X POST "https://127.0.0.1/rest/V1/integration/admin/token" \
-H "Content-Type:application/json" \
-d '{"username":"admin", "password":"XXXXX"}'
"w2rq3acoc6bbtxdbbhmybmxq1nm60j24"
Retrieve list of loaded modules
$ curl https://127.0.0.1/rest/V1/modules \
-H "Authorization: Bearer w2rq3acoc6bbtxdbbhmybmxq1nm60j24"
["Magento_Store","Magento_AdvancedPricingImportExport",...,"Magento_
Wishlist"]
1
2
M2: More Standard APIs out of the Box
Catalog
Inventory
Cart
Order
Customer
SearchTax
CMS
• Adding modules can change
the available REST and SOAP
services
• Look for webapi.xml files –
{Vendor}/{ModuleName}
/etc/webapi.xml
• Swagger based documentation
available online
• Swagger on your site –
localized based on which
modules are loaded.
http://devdocs.magento.com/swagger
Discovering API Coverage
http://127.0.0.1/index.php/rest/default/schema
PIM Calling Magento 2
curl –H "Content-Type: application/json“ –H "Authentication: XXX“ --data-raw @file.json
HTTP POST /V1/products
onPostSave()
JSON
{
"id": 0,
"sku": “SPD-3393",
"name": “Super fast shoes",
"storeId": 0,
"attributeSetId": 0,
"price": 20.22,
"extensionAttributes": {
...
webapi.xml
<routes ...>
<!-- Product Service -->
<route url="/V1/products" method="POST">
<service class="Magento\Catalog\Api\ProductRepositoryInterface“
method="save"/>
<resources>
<resource ref="Magento_Catalog::products" />
</resources>
</route>
...
webapi.xml
Create new product
Simpler REST and SOAP Services
• Service contracts are
– PHP interfaces
– Designed to be called from presentation layer and other modules
– Also bound to web services
• Arguments are
– Restricted to types easy to serialize as JSON
namespace Magento\Catalog\Api;
interface ProductRepositoryInterface
{
/**
* Create product
*
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param bool $saveOptions
* @return \Magento\Catalog\Api\Data\ProductInterface
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Exception\StateException
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(\Magento\Catalog\Api\Data\ProductInterface $product,
$saveOptions = false);
WSDL: http://127.0.0.1/soap?wsdl&services=customerCustomerAccountServiceV1,catalogProductV2
Retrieving Product Information
http://cyrillschumacher.com/2015/01/02/magento2---search-parameters-for-the-rest-api/
OR
AND
CONSTRAINTS
PAGINATION
SORTING
Fetch: curl http://127.0.0.1/rest/V1/products/12345
Search:curl -X PUT -i-H 'Content-type: application/json‘-d '{"search_criteria":{…}}' http://127.0.0.1/rest/V1/search
Cart
Cart manipulation (quoteCartManagementV1)• POST /V1/carts – creates new empty cart• PUT /V1/carts/{cartid} – associate cart with a customer
Get quote for cart (checkoutGuestTotalsInformationManagementV1)• POST /V1/carts/{cartId}/totals-information – returns how
much the cart will cost (to show user before checkout)
Specify payment information and place order (checkoutPaymentInformationManagementV1)
• POST /V1/carts/mine/payment-information
Custom APIs – Why?
Want an API optimized for mobile
Magento has not defined service contracts yet
IOT devices mapping IDs to customers and order
preferences
Custom APIs – How?
1.Write service contract (PHP interfaces)
2. Implement the interfaces with business logic
3.Bind REST and/or SOAP the API via webapi.xml
4.Review security settings, including acl.xml
No JSON/XML serialization
code
No authentication
code
Automatic separation of config from
logic
AMQP
• Can receive an AMQP message and bind onto service
contract
– No reply-to support yet
• There is an API allowing publishing of messages
– Hand craft messages
– Similar to M2 HTTP client library<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message
<publisher name="default" connection="amqp" exchange="magento”/>
<topic name="customer.created" schema="Magento\Customer\Api\AccountManagementInterface::createAccount" publisher="default" />
<bind queue="customer_created" exchange="magento" topic="customer.created" />
<consumer name="customerCreated" queue="customer_created" class="Magento\Customer\Api\AccountManagementInterface" method="createAccount
</config>
$this->publisher->publish(
'customer.created',
['customer' => $customer]
);
Future Exploration
• Synchronous MQ inbound calls
• Outbound REST call via service contract
• Outbound SOAP via service contract
• Webhook support
• Outbound synchronous (RPC call) and asynchronous
(publish) over MQ via service contract
Jeff’s Orders are Booming
Life is Good!
Twitter: @akent99
Blog: http://alankent.me
Forum: https://community.magento.com/ (Just Ask Alan)
THANK YOU!
Quality &
Magento 2
Magento 2 Platform Goals
M2
Modern Tech Stack
Improved Performance &
Scalability
StreamlineCustomization
Simplify ExternalIntegrations
Easier installation & upgrades
High code quality
& testing
Code Quality & Testing
Merchant Extension developer
System Integrator Magento Commerce
“For the first time, testing was fun”
Acceptance
Functional
Performance
Static
Integration & API
Unit
Test Types
Unit Test
• Isolated
• Fast
• Distributed with Module
• PhpUnit https://phpunit.de/
Integration and API
Integration and API
• “Black-box”
• Integration Framework >dev/tests/integration/framework
• Not fast
• PhpUnit
Static
• PHPMD
• PHPCS
• PHPCPD
• Magento-specific integrity tests
• >dev/tests/static/
Performance
• JMeter
• End-To-End Scenarios
Magento Testing Framework
Magento Testing Framework
Magento Testing Framework
• End user experience testing
• >dev/tests/functional/
• Selenium Webdriver (+Grid)
• Slow, very slow
Magento 2 Quality
Unit Tests Integration Web API Functional
16000+ CE4000+ EE
>35%
3200+ CE
400+ EE
640+ CE
50+ EE
300+ scenarios
1000 documented
Magento 2 Quality Stack
GitHub
Code Review
Bamboo
Bamboo
Acceptance Cycle
Travis-CI
Code Quality & Testing
Merchant Extension developer
System Integrator Magento Commerce
Thank you!
Q&A