API SOAP e Cron: integrare Magento con servizi esterni
-
Upload
andrea-de-pirro -
Category
Software
-
view
941 -
download
0
description
Transcript of API SOAP e Cron: integrare Magento con servizi esterni
![Page 1: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/1.jpg)
![Page 2: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/2.jpg)
@akira28
Chi Sono• Co-fondatore di Yameveo
• 9 anni sviluppando in PHP
• Più di 3 anni di esperienza con Magento
• Lead developer di progetti Magento per Privalia, Reckitt Benckiser e Groupalia
• Zend Framework Certified Engineer
![Page 3: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/3.jpg)
@akira28
Yameveo
Fondata nel 2012 a Barcellona, Yameveo è una società giovane, dinamica ed internazionale, specializzata
nell’e-commerce e nello sviluppo di applicazioni web. !
!
www.yameveo.com @Yameveo
![Page 4: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/4.jpg)
@akira28
Yameveo StoreDecine di moduli per Magento e Prestashop
store.yameveo.com
![Page 5: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/5.jpg)
@akira28
Di cosa parleremo
• Intro alle API SOAP di Magento
• Estensione delle API Magento
• Estensione 3rd party
• Creare una nuova chiamata API
• Il sistema Cron di Magento
![Page 6: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/6.jpg)
@akira28
Magento SOAP
“Le API SOAP di Magento offrono la possibilità di gestire i negozi e-commerce, fornendo chiamate per lavorare con
risorse quali clienti, categorie, prodotti e ordini. Consentono inoltre di gestire i carrelli e l'inventario.”
Documentazione Magento
![Page 7: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/7.jpg)
@akira28
Applicazioni• Integrazione con operatori logistici
• Integrazione con Warehouse
• Integrazione con CRM ed ERP
• Integrazione con altri servizi via middleware
• App mobile
• …
![Page 8: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/8.jpg)
@akira28
API MagentoQuando viene effettuata una richiesta HTTP il sistema di
routing standard di Magento invia la richiesta ad una action del controller del modulo Mage_Api
!
Questa action istanzia un oggetto "Server API", lo inizializza con il tipo di API (SOAP, XML-RPC, etc.), ed in seguito
chiama il suo metodo “run”
![Page 9: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/9.jpg)
@akira28
Come iniziare• Assicurati che l’endpoint sia accessibile:
www.example.com/api/v2_soap www.example.com/api/soap
• Definisci Utenti API e le risorse associate: System -> Web Services
• Dai un’occhiata al WSDLwww.example.com/api/v2_soap?wsdl=1 www.example.com/api/soap?wsdl=1
![Page 10: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/10.jpg)
@akira28
Magento API flow
• Crea un Session ID effettuando una richiesta “login” con username e API key
• Salva il Session ID per effettuare altre chiamate
• Effettua le altre chiamate passando il Session ID
• Termina la sessione con endSession
![Page 11: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/11.jpg)
@akira28
Testing API V1// connect to soap server $client = new SoapClient('http://apimagento.dev/api/soap?wsdl=1', array('cache_wsdl' => WSDL_CACHE_NONE, 'trace' => 1)); !// log in $session = $client->login('user', ‘password’); !$info = $client->call($session, 'catalog_product.info', '4'); !var_export($client->__getLastRequest());
http://www.php.net/manual/en/class.soapclient.php
![Page 12: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/12.jpg)
@akira28
Esempio request V1
<?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:call> <sessionId xsi:type="xsd:string">24eafa404acbd904f3c0978669102496</sessionId> <resourcePath xsi:type="xsd:string">catalog_product.info</resourcePath> <args xsi:type="xsd:int">4</args> </ns1:call> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
![Page 13: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/13.jpg)
@akira28
Esempio response V1array(6) { 'product_id' => string(3) "4" 'sku' => string(3) “sku-1“ 'set' => string(2) "41" 'type' => string(12) "configurable" 'categories' => array(1) { [0] => string(1) "4" } 'websites' => array(1) { [0] => string(1) "1" } }
![Page 14: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/14.jpg)
@akira28
Testing API V2// connect to soap server $client = new SoapClient('http://apimagento.dev/api/v2_soap?wsdl=1', array('cache_wsdl' => WSDL_CACHE_NONE, 'trace' => 1)); !// log in $session = $client->login('user', ‘password'); !$complexFilter = array( 'complex_filter' => array( array( 'key' => 'type', 'value' => array('key' => 'eq', 'value' => 'configurable') ) ) ); $list = $client->catalogProductList($session, $complexFilter); !var_export($client->__getLastRequest());
![Page 15: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/15.jpg)
@akira28
Esempio request V2<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:catalogProductList> <sessionId xsi:type="xsd:string">c84d5edf23f22913066f4246d0949908</sessionId> <filters xsi:type="ns1:filters"> <complex_filter SOAP-ENC:arrayType="ns1:complexFilter[1]" xsi:type="ns1:complexFilterArray"> <item xsi:type="ns1:complexFilter"> <key xsi:type="xsd:string">type</key> <value xsi:type="ns1:associativeEntity"> <key xsi:type="xsd:string">eq</key> <value xsi:type="xsd:string">configurable</value> </value> </item> </complex_filter> </filters> <storeView xsi:nil="true" /> </ns1:catalogProductList> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
![Page 16: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/16.jpg)
@akira28
Esempio response V2array(118) { [0] => class stdClass#2 (9) { public $product_id => string(2) "16" public $sku => string(5) "n2610" public $name => string(16) "Nokia 2610 Phone" public $set => string(2) "38" public $type => string(6) "configurable" public $category_ids => array(1) { [0] => string(1) "8" } public $website_ids => array(1) { [0] => string(1) "1" } public $price => double(149.99) public $available_quantity => int(996) } […]
![Page 17: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/17.jpg)
@akira28
abstract class Mage_Api_Model_Server_Handler_Abstract { public function startSession(){[…]} ! public function endSession($sessionId){[…]} ! public function login($username, $apiKey){[…]} ! public function call($sessionId, $apiPath, $args = array()){[…]} public function multiCall($sessionId, array $calls = array(), $options = array()){[…]} public function resources($sessionId){[…]} public function globalFaults($sessionId){[…]} public function resourceFaults($sessionId, $resourceName){[…]} !} !
app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
API SOAP Handler
![Page 18: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/18.jpg)
@akira28
Differenze API V1 e V2
• V2 è adatta ad applicazioni scritte in linguaggi tipizzati come Java o .NET
• Il WSDL V2 è molto più grande
• Nella V2 esiste un metodo per ogni chiamata: V1 - $client->call($sid, ’catalog_product.info’, …);V2 - $client->catalogProductInfo($sid, …);
![Page 19: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/19.jpg)
@akira28
![Page 20: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/20.jpg)
@akira28
Problemi
• Le chiamate native non contengono abbastanza informazioni
• Le estensioni di terze parti quasi mai offrono API
• Non esistono call per alcune risorse
![Page 21: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/21.jpg)
@akira28
Soluzioni
• Estensione delle API native
• Inclusione delle estensioni di terze parti
• Nuove call API
![Page 22: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/22.jpg)
Estensione delle API native
![Page 23: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/23.jpg)
@akira28
Estensione ProductInfo
• Configurazione del modulo
• Codice PHP
• WSDL
![Page 24: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/24.jpg)
@akira28
Estensione ProductInfo - config
[…] <global> <models> […] <catalog> <rewrite> <product_api>Yameveo_Productinfo_Model_Catalog_Product_Api</product_api> <product_api_v2>Yameveo_Productinfo_Model_Catalog_Product_Api_V2</product_api_v2> </rewrite> </catalog> […] !
Yameveo/Productinfo/etc/config.xml
![Page 25: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/25.jpg)
@akira28
class Yameveo_Productinfo_Model_Catalog_Product_Api extends Mage_Catalog_Model_Product_Api { […] public function info($productId, $store = null, $attributes = array(), $identifierType = null) { $product = $this->_getProduct($productId, $store, $identifierType); […] return $this->infoResult($result, $product, $attributes, $store); } […]
Yameveo/Productinfo/Model/Catalog/Product/Api.php
ProductInfo - codice
![Page 26: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/26.jpg)
@akira28
ProductInfo - codice
class Yameveo_Productinfo_Model_Catalog_Product_Api extends Mage_Catalog_Model_Product_Api { […] protected function infoResult($result, $product, $attributes, $store) { […] } elseif ($product->isConfigurable()) { $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product); $skus = array(); foreach ($childProducts as $childProduct) { $skus[$childProduct->getId()][‘sku’] = $childProduct->getSku(); […] } $result['configurable_products_data'] = $skus; […] return $result; } }
Yameveo/Productinfo/Model/Catalog/Product/Api.php
![Page 27: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/27.jpg)
@akira28
Estensione ProductInfo - wsdl[…] <complexType name="catalogProductReturnEntity"> <all> […] <element name="configurable_products_data" type="typens:childrenEntityArray" minOccurs="0"/> […] </all> </complexType> !<complexType name="childrenEntityArray"> <complexContent> <restriction base="soapenc:Array"> <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:childrenEntity[]"/> </restriction> </complexContent> </complexType> <complexType name="childrenEntity"> <all> <element name="sku" type="xsd:string" minOccurs=“0"/> […] </all> </complexType> […] !
Yameveo/Productinfo/etc/wsdl.xml
![Page 28: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/28.jpg)
Inclusione delle estensioni di terze parti
![Page 29: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/29.jpg)
@akira28
Estensione OrderApi
• Configurazione del modulo
• Codice PHP
• WSDL
![Page 30: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/30.jpg)
@akira28
M2E Pro
![Page 31: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/31.jpg)
@akira28
Estensione OrderApi - config
![…] <models> <yameveo_orderapi> <class>Yameveo_OrderApi_Model</class> </yameveo_orderapi> <sales> <rewrite> <order_api>Yameveo_OrderApi_Model_Order_Api</order_api> <order_api_v2>Yameveo_OrderApi_Model_Order_Api_V2</order_api_v2> </rewrite> </sales> </models> […]
Yameveo/OrderApi/etc/config.xml
![Page 32: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/32.jpg)
@akira28
Estensione M2ePro - codiceclass Yameveo_OrderApi_Model_Order_Api extends Mage_Sales_Model_Order_Api { public function info($orderIncrementId) { $result = parent::info($orderIncrementId); $ebayOrder = Mage::helper('M2ePro/Component_Ebay') ->getCollection('Order') ->addFieldToFilter('magento_order_id', $result['order_id']) ->getFirstItem(); ! if ($ebayOrder->getData('ebay_order_id')) { $result['ebay'] = array(); $result['ebay']['ebay_order_id'] = $ebayOrder->getData('ebay_order_id'); $result['ebay']['selling_manager_record_number'] = $ebayOrder->getData('selling_manager_record_number'); […] foreach ($ebayOrder->getItemsCollection() as $item) { $itemArray = array( […] 'buy_it_now_price' => $item->getData('buy_it_now_price'), […] ); ! $result['ebay']['items'][] = $itemArray; } } return $result; } […]
Yameveo/OrderApi/Model/Order/Api.php
![Page 33: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/33.jpg)
@akira28
Estensione M2ePro - wsdl[…] <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento"> <complexType name="salesOrderEntity"> <all> <element name="ebay" type="typens:ebayOrder" minOccurs="0" maxOccurs="1"/> </all> </complexType> <complexType name="ebayOrder"> <all> <element name="ebay_order_id" type="xsd:string" minOccurs="0" maxOccurs="1"/> <element name="items" type="typens:ebayOrderItems" minOccurs="0" /> […] </all> </complexType> <complexType name="ebayOrderItems"> <complexContent> <restriction base="soapenc:Array"> <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:ebayOrderItem[]" /> </restriction> </complexContent> </complexType> <complexType name=“ebayOrderItem"> […] <element name="buy_it_now_price" type="xsd:string" minOccurs="0" maxOccurs=“1"/> […] </complexType> […]
Yameveo/OrderApi/etc/wsdl.xml
![Page 34: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/34.jpg)
Nuova call API
![Page 35: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/35.jpg)
@akira28
Estensione RmaApi
• Configurazione del modulo
• Codice PHP
• WSDL
![Page 36: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/36.jpg)
@akira28
RmaApi - config<config> <modules> <Yameveo_RmaApi> <version>1.0</version> </Yameveo_RmaApi> </modules> <global> <models> <rma> <class>Yameveo_RmaApi_Model</class> </rma> </models> <helpers> <rma> <class>Yameveo_RmaApi_Helper</class> </rma> </helpers> </global> </config>
Yameveo/RmaApi/etc/config.xml
![Page 37: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/37.jpg)
@akira28
RMA API api.xml<config> <api> <resources> <rma translate="title" module="rmaapi"> <model>rma/api</model> <title>Rma Resource</title> <acl>rma</acl> <methods> <info translate="title" module="rmaapi"> <title>Retrieve RMA information</title> <method>info</method> <acl>rma/info</acl> </info> </methods> <faults module="rmaapi"> <invalid_protocol> <code>106</code> <message>This operation available through SOAP v2 only.</message> </invalid_protocol> </faults> </rma> </resources> <resources_alias> <rma>rma</rma> </resources_alias> <v2> <resources_function_prefix> <rma>rma</rma> </resources_function_prefix> </v2> <acl> <resources> <rma translate="title" module="rmaapi"> <info translate="title" module="rmaapi"> <title>Retrieve RMA information</title> </info> </rma> </resources> </acl> </api> </config>
Yameveo/RmaApi/etc/api.xml
![Page 38: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/38.jpg)
@akira28
RmaApi - codiceclass Yameveo_RmaApi_Model_Api extends Mage_Api_Model_Resource_Abstract { /** * Info on RMA * * @param string $incrementId * @return info */ public function info($incrementId) { $rma = Mage::getModel('enterprise_rma/rma') ->getCollection() ->addFieldToFilter('increment_id', $incrementId) ->getFirstItem(); $rmaData = $rma->getData(); foreach ($rma->getItemsForDisplay() as $item) { $rmaData['items'][] = $item->getData(); } $comments = Mage::getResourceModel('enterprise_rma/rma_status_history_collection') ->addFilter('rma_entity_id', $rma->getId()); foreach ($comments as $comment) { $rmaData['comments'][] = $comment->getData(); } $rmaData['shipping_label'] = $rma->getShippingLabel()->getData(); ! return $rmaData; }
Yameveo/RmaApi/Model/Api.php
![Page 39: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/39.jpg)
@akira28
RmaApi - wsdl[…] <message name="rmaInfoRequest"> <part name="sessionId" type="xsd:string"/> <part name="rmaIncrementId" type="xsd:string"/> </message> <message name="rmaInfoResponse"> <part name="result" type="typens:rmaExportEntity"/> </message> [...] <portType name="{{var wsdl.handler}}PortType"> <operation name="rmaInfo"> <documentation>Info on RMA</documentation> <input message="typens:rmaInfoRequest"/> <output message="typens:rmaInfoResponse"/> </operation> </portType> <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType"> <operation name="rmaInfo"> <soap:operation soapAction="urn:{{var wsdl.handler}}Action"/> <input> <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding>
![Page 40: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/40.jpg)
@akira28
RmaApi - wsdl<complexType name="rmaExportEntity"> <all> [...] <element name="customer_custom_email" type="xsd:string" minOccurs="0" maxOccurs="1"/> <element name="items" type="typens:rmaExportEntityItemsArray" minOccurs="1" maxOccurs="1"/> [...] </all> </complexType> <complexType name="rmaExportEntityItemsArray"> <complexContent> <restriction base="soapenc:Array"> <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:rmaExportEntityItem[]"/> </restriction> </complexContent> </complexType> <complexType name="rmaExportEntityItem"> <all> [...] <element name="product_sku" type="xsd:string" minOccurs="0"/> [...] </all> </complexType>
Yameveo/RmaApi/etc/wsdl.xml
![Page 41: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/41.jpg)
@akira28
![Page 42: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/42.jpg)
@akira28
Cos’altro si può fare con le API
• Esportare ed importare ordini, prodotti, clienti
• Checkout via SOAP per applicazioni esterne
• Creare promozioni
• Gestire il CMS
• ….
• Le possibilità sono infinite!
![Page 43: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/43.jpg)
@akira28
Magento Cron
• Cos’è
• Come funziona
• Come può risultare utile
• Come si crea un task
![Page 44: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/44.jpg)
@akira28
Magento Cron!
• Il meccanismo Cron di Magento viene attivato periodicamente utilizzando un cronjob del sistema
• La chiamata viene avviata nel file di cron.php
• Il codice in cron.php invoca Mage_Cron_Model_Observer → dispatch(), che a sua volta provvederà a:
• eseguire le operazioni pianificate
• generare, se necessario, task da eseguire in futuro
• ripulire la history delle operazioni eseguite
![Page 45: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/45.jpg)
@akira28
Utilizzi del cron• Export automatico
• Report ordini giornaliero
• Aggiornamento statistiche
• Invio mail per cart abbandonati
• …
![Page 46: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/46.jpg)
@akira28
Creare un task cron - config
[…] <crontab> <jobs> <yameveo_export> <schedule> <cron_expr>0 2 * * *</cron_expr> </schedule> <run> <model>yameveo/observer::inventoryExport</model> </run> </yameveo_export> </jobs> </crontab> […]
Yameveo/Export/etc/config.xml
![Page 47: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/47.jpg)
@akira28
Creare un task cron - codiceclass Yameveo_Export_Model_Observer extends Mage_Core_Model_Observer { /** * Cron method to export the complete product inventory to the configured ftp server */ public function inventoryExport() { $products = Mage::getModel(‘catalog/product’)->getCollection(); // build data to export foreach ($products as $product) { […] } $this->sendToFtp($data); } […] }
Yameveo/Export/Model/Observer.php
![Page 48: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/48.jpg)
@akira28
Configurare cron da backend
[…] <settings translate="label" module=“yameveo_export"> […] <fields> <cron_settings translate="label comment" module="yameveo_export"> <label>How often do you want the cron to run?</label> <frontend_type>text</frontend_type> <sort_order>70</sort_order> <comment>Use Crontab Format (Eg. "0 4 * * *" for every day at 4 a.m.)</comment> <show_in_default>1</show_in_default> </cron_settings> </fields> </settings> […]
Yameveo/etc/system.xml
![Page 49: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/49.jpg)
@akira28
Configurare cron da backend
[…] <crontab> <jobs> <yameveo_export> <schedule> <config_path>export_config/settings/cron_settings</config_path> </schedule> <run> <model>yameveo_export/observer::inventoryExport</model> </run> </yameveo_export> </jobs> </crontab> […]
Yameveo/Export/etc/config.xml
![Page 50: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/50.jpg)
Volete vedere altro codice?
![Page 51: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/51.jpg)
@akira28
![Page 52: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/52.jpg)
@akira28
Risorse• www.yameveo.com
• github.com/Yameveo
• twitter.com/Yameveo
• alanstorm.com
• www.magentocommerce.com/api
![Page 53: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/53.jpg)
Domande?
![Page 54: API SOAP e Cron: integrare Magento con servizi esterni](https://reader034.fdocument.pub/reader034/viewer/2022052505/554fb3e7b4c905ad218b53f9/html5/thumbnails/54.jpg)
Grazie!www.yameveo.com !
@akira28 @Yameveo !
http://bit.ly/andreadepirro