Sharing some useful tips, solutions and notes for Geeks.

Wednesday, December 6, 2017

First parameter must either be an object or the name of an existing class Magento api soap

Yesterday when i was working in Magento API V2, i met with an issue.

I was able to create product using WSDL xml in Magento. However, i was struggling to insert the additional custom attributes i have created in Magento. Whatever i do, the custom attribute values were not inserting in the fields for product.

Creating xml looks like this:

<s:Envelope xmlns:s="">
        <Action s:mustUnderstand="1" xmlns="" /> </s:Header>
    <s:Body xmlns:xsi="" xmlns:xsd="">
        <catalogProductCreateRequestParam xmlns="urn:Magento">
            <sessionId xmlns="">**************</sessionId>
            <type xmlns="">simple</type>
            <set xmlns="">***</set>
            <sku xmlns="">**********</sku>
            <productData xmlns="">

Here whatever i do, colour was not setting for that product.

So i started debugging the code and found this error:

"First parameter must either be an object or the name of an existing class /app/code/core/Mage/Catalog/Model/Product/Api/V2.php"

Then i started investigating the above V2.php file. I understood that in this method: _prepareDataForSave, the additional attributes are getting inserted/updated.

Under if (property_exists($productData, 'additional_attributes')) { , it checks for single_data and multi_data. I have amended another if condition just below the other two if conditions.

if (gettype($productData->additional_attributes) == 'array') {
                foreach ($productData->additional_attributes as $k => $v) {
                    $_attrCode = $k;
                    $productData->$_attrCode = $v;

This checks whether the type receiving is in array. So the whole code will looks like this:

 And Voila, everything started importing. For dropdown attributes, i used index instead of values. For text and other attribute types, used values itself.

Just try it out and not worked, get me back via contact form.

No comments: