【问题标题】:Magento - Add parameter to soap methodMagento - 向soap方法添加参数
【发布时间】:2013-07-19 03:27:29
【问题描述】:

我正在使用 SOAP 实现一个 Magento 客户端,并且我正在对 Magento 进行一些更改以提高我的应用程序的整体性能。为此,我试图减少对 Magento 服务的调用次数。

例如,我想为购物车创建新报价并通过一次调用为其设置客户。为此,我更改了app\code\core\Mage\Checkout\etc\wsdl.xml

<message name="shoppingCartCreateRequest">
    <part name="sessionId" type="xsd:string"/>
    <part name="storeId" type="xsd:string"/>
    <part name="customer" type="typens:shoppingCartCustomerEntity"/> <!--added this line -->
</message>

在文件 /optiMage/app/code/core/Mage/Checkout/Model/Cart/Api.php 中,我将方法 create 更改为:

public function create($store = null, $customer = null)
{
    $storeId = $this->_getStoreId($store);

    try {
        /*@var $quote Mage_Sales_Model_Quote*/
        $quote = Mage::getModel('sales/quote');
        $quote->setStoreId($storeId)
        ->setIsActive(false)
        ->setIsMultiShipping(false)
        ->save();
    } catch (Mage_Core_Exception $e) {
        $this->_fault('create_quote_fault', $e->getMessage());
    }
    $quoteId = (int) $quote->getId();

    try{
        $service = new Mage_Checkout_Model_Cart_Customer_Api_V2();
        $res = $service->set($quoteId, $customer);
    } catch (Mage_Core_Exception $e) {
        $this->_fault('customer_not_set', $e->getMessage());
    }

    return $quoteId;
}

问题似乎是我添加的参数 ($customer) 无法以某种方式访问​​。当我尝试转储它时,服务器停止运行并且不向我的应用返回任何内容。

你能帮帮我吗?如果还不够清楚,请告诉我。谢谢!

PS:$quoteId 仍在生成中。当我尝试与较新的变量进行交互时,就会出现问题。

============编辑============ 我发现了问题:我的客户端应用程序正在发送不同类型的对象,这就是 Magento 无法转换我的参数的原因。现在它起作用了!

还是谢谢:)

【问题讨论】:

    标签: magento soap magento-1.7 soap-client


    【解决方案1】:

    问题在于声明,因为整个实体不能通过soap请求传递:

    <part name="customer" type="typens:shoppingCartCustomerEntity"/> 
    

    将其更改为类型:

    <part name="customer" type="xsd:int"/> 
    

    或 xsd:string

    然后只将 customer_id 传递给您的方法。然后在您的自定义 api 方法中加载整个实体数据:

    $customer = Mage::getModel('customer/customer')->load($customer_id);
    

    【讨论】:

    • 我同意我可以传递客户 ID 而不是整个对象,但“shoppingCartCustomerSetRequest”确实收到一个对象(而不是 id)。我也会加入客户模式,我不相信只添加每个文件就可以解决问题。
    • 已解决。 +1 为您的努力:D
    猜你喜欢
    • 1970-01-01
    • 2013-01-29
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 2012-10-14
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多