如何从Magento连接到外部API

时间:2013-03-12 12:18:58

标签: soap magento-1.7

我正在寻找一些帮助来创建基于API的模块,将客户信息从Magento推送到第三方忠诚度计划。

到目前为止,我已经创建了一个基本模块,但是找不到有关在Magento中创建基于API的模块的任何好信息,并且可以真正做一些建议,请...

我需要以某种方式挂钩到Magneto的Checkout成功页面,并添加一个表格,将客户信息(姓名,地址等)发布到第三方忠诚度计划。我还需要能够登录以完成账单信息等......

有没有人知道有关这种实现的任何方便的教程或文档?

到目前为止,我已经设置了具有相应角色的API用户。我还为测试purpses创建了一个非常基本的模块,但是浏览到文件我得到了404错误

apitest.php

<?php 
$proxy = new SoapClient('http://mysite.com/api/?wsdl'); //edit the address and put the url to your magento here

$sessionId = $proxy->login('######', '#######'); // put in the info for your user here

echo "Login ID : $sessionId";
$result = $proxy->call($sessionId, 'Mymodule.testConnection', array('param1' => ' This string was sent from soap client'));
echo $result; 

Objectmodel / api.php

<?php
class MyModule_MyModule_Model_ObjectModel_Api extends Mage_Api_Model_Resource_Abstract
{
    public function testConnection($arg)
    {
        return "Hello World! My argument is : " . $arg;
    }
}

我按照here中的示例获取了一个基本的“Hello world”模块,如果有人可以帮助我获得正确的设置我将不胜感激

1 个答案:

答案 0 :(得分:1)

您可以像这样创建客户,而不是连接magento API。

define('INCLUDE_PATH', '/var/www/QA/mojostage/app/');
define('INCLUDE_FILE', 'Mage.php');
Mage::app();
$customer = Mage::getModel('customer/customer');
        $customer->setWebsiteId($wesite_id);
        $customer->loadByEmail($customer_email);
        /*
         * Check if the email exist on the system.
         * If YES,  it will not create a user account.
         */

        if (!$customer->getId()) {

            //setting data such as email, firstname, lastname, and password

            $customer->setEmail($customer_email);
            $customer->setTaxvat($value['cus_vatnumber'])
                    ->setCreatedAt($date1)
                    ->setDob($value['date_of_birth'])
                    ->setGroupId($cus_group_id)
                    ->setConfirmation($is_active)
                    ->setCreatedIn('Admin')
                    ->setStoreId($store_id)
                    ->setWebsiteId($wesite_id)
                    ->setEntityId($value['cus_id']);
            $customer->setFirstname($customer_fname);
            $customer->setLastname($customer_lname);
            $customer->setPassword($value['password']);

            $subscriber = Mage::getModel('newsletter/subscriber');
            $subscriber->setStoreId($store_id)
                    ->setCustomerId($value['cus_id'])
                    ->setSubscriberEmail($customer_email)
                    ->setSubscriberStatus($value['cus_spam'])
                    ->setSubscriberConfirmCode($subscriber->randomSequence());
        }

        //the save the data and send the new account email.
        $customer->save();
        $subscriber->save();
相关问题