Question

I have a third party extension module in Magento (aheadWorks gift wrap) that works fine from the front end and will save gift details to the Magento DB as required. The issue I have is trying to create an API that I can call via SOAP from a Java backend server.

I have followed online tutorials to try and create the a custom API for this module but I receive an unknown error from the receiver side that I can't diagnose. Please excuse me if I have made an obvious mistake but I am a complete novice to Magento.

Example call using SoapUI Example call using SoapUI

I am using WS-I Compliance mode and have disabled WSDL cache while trying to diagnose the issue.

My setup is as follows: -

/var/www/html/magento/app/code/local/AW/Giftwrap/etc/wsi.xml

    <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:typens="urn:{{var wsdl.name}}"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
             name="{{var wsdl.name}}"
             targetNamespace="urn:{{var wsdl.name}}">
    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:{{var wsdl.name}}">
            <xsd:complexType name="giftwrapOrderEntity">
                <xsd:sequence>
                    <xsd:element name="order_id" type="xsd:string" minOccurs="0" />
                </xsd:sequence>
            </xsd:complexType>
        <xsd:complexType name="giftwrapOrderEntityArray">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray" type="typens:giftwrapOrderEntity" />
                </xsd:sequence>
            </xsd:complexType>
        <xsd:element name="giftwrapOrderListRequestParam">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        <xsd:element name="giftwrapOrderListResponseParam">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="1" maxOccurs="1" name="result" type="typens:giftwrapOrderEntityArray" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
         </xsd:schema>
    </wsdl:types>
    <wsdl:message name="giftwrapOrderListRequest">
        <wsdl:part name="parameters" element="typens:giftwrapOrderListRequestParam" />
    </wsdl:message>
    <wsdl:message name="giftwrapOrderListResponse">
        <wsdl:part name="parameters" element="typens:giftwrapOrderListResponseParam" />
    </wsdl:message>
    <wsdl:portType name="{{var wsdl.handler}}PortType">
    <wsdl:operation name="giftwrapOrderList">
      <wsdl:documentation>List of order wraps</wsdl:documentation>
      <wsdl:input message="typens:giftwrapOrderListRequest" />
      <wsdl:output message="typens:giftwrapOrderListResponse" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="giftwrapOrderList">
            <soap:operation soapAction="" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
  </wsdl:binding>
</wsdl:definitions>

/var/www/html/magento/app/code/local/AW/Giftwrap/etc/api.xml

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <giftwrap_order translate="title" module="AW_Giftwrap">
                <model>aw_giftwrap/order_api</model>
                <title>Order Gift Wrap Resource</title>
        <acl>giftwrap/order</acl>
                <methods>
                    <list translate="title" module="AW_Giftwrap">
                        <title>Retrieve list of gift wraps by filters</title>
                        <method>items</method>
                    </list>
                </methods>
                <faults module="AW_Giftwrap">
                    <not_exists>
                        <code>100</code>
                        <message>Requested wrap not exists.</message>
                    </not_exists>
                    <filters_invalid>
                        <code>101</code>
                        <message>Invalid filters given. Details in error message.</message>
                    </filters_invalid>
                    <data_invalid>
                        <code>102</code>
                        <message>Invalid data given. Details in error message.</message>
                    </data_invalid>
                </faults>
</giftwrap_order>
        </resources>
        <resources_alias>
            <order>giftwrap_order</order>
        </resources_alias>
        <v2>
            <resources_function_prefix>
                <order>giftwrapOrder</order>
            </resources_function_prefix>
        </v2>
        <acl>
            <resources>
<giftwrap translate="title" module="AW_Giftwrap">
                    <order translate="title" module="aw_giftwrap">
                         <title>Order Wraps</title>
                         <list translate="title" module="aw_giftwrap">
                            <title>View All</title>
                         </list>
                         </order>
                    </giftwrap>
            </resources>
        </acl>
    </api>
</config>

/var/www/html/magento/app/code/local/AW/Giftwrap/Model/Order/api.php

    <?php
class AW_Giftwrap_Model_Order_Api extends Mage_Api_Model_Resource_Abstract
{
    public function items()
    {
        return Mage::getModel('aw_giftwrap/order_wrap')->getCollection()->addAttributeToSelect('*');
    }   
}

/var/www/html/magento/app/code/local/AW/Giftwrap/Model/Order/Api/v2.php

    <?php
class AW_Giftwrap_Model_Order_Api_V2 extends AW_Order_Wrap_Model_Api
{
}

Finally, we have the config.xml supplied by the creator of the module...

/var/www/html/magento/app/code/local/AW/Giftwrap/etc/config.xml

    <?xml version="1.0"?>
<config>
    <modules>
        <AW_Giftwrap>
            <version>1.1.1</version><platform>ce</platform>
        </AW_Giftwrap>
    </modules>
    <global>
        <blocks>
            <aw_giftwrap>
                <class>AW_Giftwrap_Block</class>
            </aw_giftwrap>
        </blocks>
        <helpers>
            <aw_giftwrap>
                <class>AW_Giftwrap_Helper</class>
            </aw_giftwrap>
        </helpers>
        <models>
            <aw_giftwrap>
                <class>AW_Giftwrap_Model</class>
                <resourceModel>aw_giftwrap_resource</resourceModel>
            </aw_giftwrap>
            <aw_giftwrap_resource>
                <class>AW_Giftwrap_Model_Resource</class>
                <entities>
                    <type>
                        <table>aw_giftwrap_type</table>
                    </type>
                    <order_wrap>
                        <table>aw_giftwrap_order_wrap</table>
                    </order_wrap>
                    <invoice_wrap>
                        <table>aw_giftwrap_invoice_wrap</table>
                    </invoice_wrap>
                    <creditmemo_wrap>
                        <table>aw_giftwrap_creditmemo_wrap</table>
                    </creditmemo_wrap>
                </entities>
            </aw_giftwrap_resource>
        </models>
        <resources>
            <aw_giftwrap_setup>
                <setup>
                    <module>AW_Giftwrap</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </aw_giftwrap_setup>
            <aw_giftwrap_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </aw_giftwrap_write>
            <aw_giftwrap_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </aw_giftwrap_read>
        </resources>
        <events>
            <sales_model_service_quote_submit_before>
                <observers>
                    <aw_giftwrap_sales_model_service_quote_submit_before>
                        <class>aw_giftwrap/observer</class>
                        <method>salesModelServiceQuoteSubmitBefore</method>
                    </aw_giftwrap_sales_model_service_quote_submit_before>
                </observers>
            </sales_model_service_quote_submit_before>
            <sales_model_service_quote_submit_after>
                <observers>
                    <aw_giftwrap_sales_model_service_quote_submit_after>
                        <class>aw_giftwrap/observer</class>
                        <method>salesModelServiceQuoteSubmitAfter</method>
                    </aw_giftwrap_sales_model_service_quote_submit_after>
                </observers>
            </sales_model_service_quote_submit_after>
            <checkout_controller_onepage_save_shipping_method>
                <observers>
                    <aw_giftwrap_checkout_controller_onepage_save_shipping_method>
                        <class>aw_giftwrap/observer</class>
                        <method>checkoutControllerOnepageSaveShippingMethod</method>
                    </aw_giftwrap_checkout_controller_onepage_save_shipping_method>
                </observers>
            </checkout_controller_onepage_save_shipping_method>
            <checkout_type_onepage_save_order_after>
                <observers>
                    <aw_giftwrap_checkout_type_onepage_save_order_after>
                        <class>aw_giftwrap/observer</class>
                        <method>checkoutTypeOnepageSaveOrderAfter</method>
                    </aw_giftwrap_checkout_type_onepage_save_order_after>
                </observers>
            </checkout_type_onepage_save_order_after>
            <sales_order_load_after>
                <observers>
                    <aw_giftwrap_sales_order_load_after>
                        <class>aw_giftwrap/observer</class>
                        <method>salesOrderLoadAfter</method>
                    </aw_giftwrap_sales_order_load_after>
                </observers>
            </sales_order_load_after>
            <sales_order_invoice_load_after>
                <observers>
                    <aw_giftwrap_sales_order_invoice_load_after>
                        <class>aw_giftwrap/observer</class>
                        <method>salesOrderInvoiceLoadAfter</method>
                    </aw_giftwrap_sales_order_invoice_load_after>
                </observers>
            </sales_order_invoice_load_after>
            <sales_order_creditmemo_load_after>
                <observers>
                    <aw_giftwrap_sales_order_creditmemo_load_after>
                        <class>aw_giftwrap/observer</class>
                        <method>salesOrderCreditmemoLoadAfter</method>
                    </aw_giftwrap_sales_order_creditmemo_load_after>
                </observers>
            </sales_order_creditmemo_load_after>
            <sales_order_invoice_save_after>
                <observers>
                    <aw_giftwrap_sales_order_invoice_save_after>
                        <class>aw_giftwrap/observer</class>
                        <method>salesOrderInvoiceSaveAfter</method>
                    </aw_giftwrap_sales_order_invoice_save_after>
                </observers>
            </sales_order_invoice_save_after>
            <sales_order_creditmemo_save_after>
                <observers>
                    <aw_giftwrap_sales_order_creditmemo_save_after>
                        <class>aw_giftwrap/observer</class>
                        <method>salesOrderCreditmemoSaveAfter</method>
                    </aw_giftwrap_sales_order_creditmemo_save_after>
                </observers>
            </sales_order_creditmemo_save_after>
            <paypal_prepare_line_items>
                <observers>
                    <aw_giftwrap_paypal_prepare_line_items>
                        <class>aw_giftwrap/observer</class>
                        <method>paypalPrepareLineItems</method>
                    </aw_giftwrap_paypal_prepare_line_items>
                </observers>
            </paypal_prepare_line_items>
        </events>
        <sales>
            <quote>
                <totals>
                    <aw_giftwrap>
                        <class>aw_giftwrap/sales_total_quote_giftwrap</class>
                        <after>subtotal,tax</after>
                        <before>grand_total</before>
                        <renderer>aw_giftwrap/checkout_total</renderer>
                    </aw_giftwrap>
                </totals>
            </quote>
            <order_invoice>
                <totals>
                    <aw_giftwrap>
                        <class>aw_giftwrap/sales_total_invoice_giftwrap</class>
                        <after>subtotal</after>
                    </aw_giftwrap>
                </totals>
            </order_invoice>
            <order_creditmemo>
                <totals>
                    <aw_giftwrap>
                        <class>aw_giftwrap/sales_total_creditmemo_giftwrap</class>
                        <after>subtotal</after>
                    </aw_giftwrap>
                </totals>
            </order_creditmemo>
        </sales>
        <pdf>
            <totals>
                <aw_giftwrap translate="title">
                    <title>Gift Wrap</title>
                    <model>aw_giftwrap/sales_total_pdf_giftwrap</model>
                    <font_size>7</font_size>
                    <display_zero>0</display_zero>
                    <sort_order>650</sort_order>
                </aw_giftwrap>
            </totals>
        </pdf>
    </global>
    <admin>
        <routers>
            <aw_giftwrap_admin>
                <use>admin</use>
                <args>
                    <module>AW_Giftwrap</module>
                    <frontName>aw_giftwrap_admin</frontName>
                </args>
            </aw_giftwrap_admin>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <aw_orderattributes module="AW_Orderattributes">
                    <file>aw_orderattributes.xml</file>
                </aw_orderattributes>
                <aw_giftwrap>
                    <file>aw_giftwrap.xml</file>
                </aw_giftwrap>
            </updates>
        </layout>
        <translate>
            <modules>
                <AW_Giftwrap>
                    <files>
                        <default>AW_Giftwrap.csv</default>
                    </files>
                </AW_Giftwrap>
            </modules>
        </translate>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <aw_giftwrap>
                                            <title>aheadWorks - Gift Wrap</title>
                                        </aw_giftwrap>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
        <events>
            <admin_system_config_changed_section_aw_giftwrap>
                <observers>
                    <aw_giftwrap_admin_system_config_changed_section>
                        <class>aw_giftwrap/observer</class>
                        <method>adminSystemConfigSectionChanged</method>
                    </aw_giftwrap_admin_system_config_changed_section>
                </observers>
            </admin_system_config_changed_section_aw_giftwrap>
            <clean_catalog_images_cache_after>
                <observers>
                    <aw_giftwrap_clean_catalog_images_cache_after>
                        <type>singleton</type>
                        <class>aw_giftwrap/observer</class>
                        <method>cleanCatalogImagesCacheAfter</method>
                    </aw_giftwrap_clean_catalog_images_cache_after>
                </observers>
            </clean_catalog_images_cache_after>
        </events>
    </adminhtml>
    <frontend>
        <layout>
            <updates>
                <aw_onestepcheckout module="AW_Onestepcheckout">
                    <file>aw_onestepcheckout.xml</file>
                </aw_onestepcheckout>
                <aw_orderattributes module="AW_Orderattributes">
                    <file>aw_orderattributes.xml</file>
                </aw_orderattributes>
                <aw_giftwrap module="AW_Giftwrap">
                    <file>aw_giftwrap.xml</file>
                </aw_giftwrap>
            </updates>
        </layout>
        <translate>
            <modules>
                <AW_Giftwrap>
                    <files>
                        <default>AW_Giftwrap.csv</default>
                    </files>
                </AW_Giftwrap>
            </modules>
        </translate>
    </frontend>
    <default>
        <aw_giftwrap>
            <general>
                <is_enabled>0</is_enabled>
                <is_wrap_products_separately>0</is_wrap_products_separately>
                <is_gift_message_enabled>0</is_gift_message_enabled>
            </general>
            <exclude_products>
                <rule></rule>
            </exclude_products>
        </aw_giftwrap>
    </default>

    <aw_lib>
        <models>
            <pdf>
                <invoice>
                    <aw_giftwrap>
                        <model>aw_giftwrap/sales_order_pdf_invoice</model>
                        <sort_order>100</sort_order>
                    </aw_giftwrap>
                </invoice>
                <creditmemo>
                    <aw_giftwrap>
                        <model>aw_giftwrap/sales_order_pdf_creditmemo</model>
                        <sort_order>100</sort_order>
                    </aw_giftwrap>
                </creditmemo>
                <shipment>
                    <aw_giftwrap>
                        <model>aw_giftwrap/sales_order_pdf_shipment</model>
                        <sort_order>100</sort_order>
                    </aw_giftwrap>
                </shipment>
            </pdf>
        </models>
    </aw_lib>
</config>

Does anyone have any idea about what the problem is here?

You bright guys are my last resort before I give up and write an implementation to access the Magento DB directly via SQL! :-)

Était-ce utile?

La solution

Ok well managed to track down the issue finally after some rummaging around...

I wasn't aware that Magento kept logs of my failed SOAP requests but the system.log turned out to be my best friend in diagnosing this issue.

The issue that was causing the unhelpful unknown receiver error was because my request could not find the file AW/Giftwrap/Model/Order/Api/V2.php. Yes I had saved the file as AW/Giftwrap/Model/Order/Api/v2.php.

Frustratingly it appears that Magento requires you to be consistently case sensitive with your file and class naming.

I also made some changes to V2.php and Api.php which I will list below but the previous change was the biggie...

/var/www/html/magento/app/code/local/AW/Giftwrap/Model/Order/Api/v2.php

    <?php
class AW_Giftwrap_Model_Order_Api_V2 extends AW_Giftwrap_Model_Order_Api
{
}

/var/www/html/magento/app/code/local/AW/Giftwrap/Model/Order/api.php

<?php
class AW_Giftwrap_Model_Order_Api extends Mage_Api_Model_Resource_Abstract
{
    public function items($filters = null)
    {
    $collection = Mage::getModel('aw_giftwrap/order_wrap')->getCollection();

        if (is_array($filters)) {
            try {
                foreach ($filters as $field => $value) {
                    $collection->addFieldToFilter($field, $value);
                }
            } catch (Mage_Core_Exception $e) {
                $this->_fault('filters_invalid', $e->getMessage());
                // If we are adding filter on non-existent attribute
            }
        }

        $result = array();
        foreach ($collection as $orderwrap) {
            $result[] = $orderwrap->toArray();
        }

        return $result;
    }   
}

Which gives the result I was expecting!

Success! Hope someone will find this of use.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top