jreinke / magento-improve-api Goto Github PK
View Code? Open in Web Editor NEWMagento extension to improve some missing features of API.
Magento extension to improve some missing features of API.
Hi,
I'm using this extension with magento 1.9 and everything works fine. If I add array of categories with their ids, the product is created correctly, but if I add an array of names, the product is created without any category associated to it. The code I'm using is:
$simple_data = array(
'categories' => array('Default Category', 'first subcategory'),
...
);
In the Magento 1.9 wsdl.xml the type "typens:associativeArray" is definend like this:
<complexType name="associativeEntity"> <all> <element name="key" type="xsd:string"/> <element name="value" type="xsd:string"/> </all> </complexType> <complexType name="associativeArray"> <complexContent> <restriction base="soapenc:Array"> <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:associativeEntity[]"/> </restriction> </complexContent> </complexType>
So a "associativeArray" has to contain the keys "key" & "value" and this is incompatible with the data-structure the code requires:
'price_changes' => array( array( 'color' => array( 'Red' => '2', 'Blue' => '-10%', ), 'size' => array( 'Large' => '+1', 'Medium' => '-3', ), ), ),
I'am not an expert in WSDL but I think this calls for a new type definition?
An alternative Fix I did quick and dirty is to change the type of "price_changes" to "xsd:string" and do json_encode / serialize before calling the function with the soapclient and then in the api there needs to be the equivalent json_decode / unserialize.
Does anyone still maintain this extension ? Do you accept pull request ? Or is there another way to do this (create and associate configurable products), that i'am not aware of ?
Great extension first off!
I see that you are able to associate simple products to configurable products when you create them, but I was unable find in the blog post if it is possible to see already existing associated products when pulling the configurable via the API. Is this possible?
It would be greate if you could add this to your module.
Here is the code for it: (hope this works)
http://stackoverflow.com/questions/20760624/magento-soap-how-to-update-quantity-increments
Hello Jreinke,
Thank you so much for a good free extension, I've tried improve-api with Magento ver. 1.9.0.1 CE
by call api soap v2, everything seem great... except!
when I define price_changes:
'price_changes' => array(
array(
'color' => array(
'Red' => '2',
'White' => '-10%',
),
'size' => array(
'7' => '+1',
'7-' => '-3',
),
),
),
error occurred :
SOAP-ERROR: Encoding: object has no 'key' property
"; $sessionId = $proxy->login('example', 'example123@'); echo ""; }catch(Exception $e) { die(var_dump($e)); } /** * Simple product #1 (sku : SKU-001) */ $productData = array( 'name' => 'Produto Simples #1', 'description' => 'Descrição do Produto Simples #1', 'short_description' => 'Descrição Curta do Produto Simples #1', 'website_ids' => array('base'), // Id or code of website 'status' => 1, // 1 = Enabled, 2 = Disabled 'visibility' => 1, // 1 = Not visible, 2 = Catalog, 3 = Search, 4 = Catalog/Search 'tax_class_id' => 2, // Default VAT 'weight' => 0, 'stock_data' => array( 'use_config_manage_stock' => 0, 'manage_stock' => 0, // We do not manage stock, for example ), 'price' => 9.90, // Same price than configurable product, no price change 'additional_attributes' => array( 'single_data' => array( array( 'key' => 'cores', 'value' => 'AMARELO', // Id or label of color, attribute that will be used to configure product ), ), ), ); $proxy->catalogProductCreate($sessionId, 'simple', 'Default', 'SKU-001', $productData); /** * Simple product #2 (sku : SKU-002) */ $productData = array( 'name' => 'Produto Simples #2', 'description' => 'Descrição do Produto Simples #2', 'short_description' => 'Descrição Curta do Produto Simples #2', 'website_ids' => array('base'), // Id or code of website 'status' => 1, // 1 = Enabled, 2 = Disabled 'visibility' => 1, // 1 = Not visible, 2 = Catalog, 3 = Search, 4 = Catalog/Search 'tax_class_id' => 2, // Default VAT 'weight' => 0, 'stock_data' => array( 'use_config_manage_stock' => 0, 'manage_stock' => 0, // We do not manage stock, for example ), 'price' => 8.90, // Red product is $1 less than configurable product 'additional_attributes' => array( 'single_data' => array( array( 'key' => 'cores', 'value' => 'AZUL', // Id or label of color, attribute that will be used to configure product ), ), ), ); // Creation of product #2 $proxy->catalogProductCreate($sessionId, 'simple', 'Default', 'SKU-002', $productData); /** * Configurable product */ $productData = array( 'name' => 'Produto Configurável', 'description' => 'Descrição do produto configurável', 'short_description' => 'Descrição curta do produto configurável', 'website_ids' => array('base'), // Id or code of website 'status' => 1, // 1 = Enabled, 2 = Disabled 'visibility' => 4, // 1 = Not visible, 2 = Catalog, 3 = Search, 4 = Catalog/Search 'tax_class_id' => 2, // Default VAT 'weight' => 0, 'stock_data' => array( 'use_config_manage_stock' => 0, 'manage_stock' => 0, // We do not manage stock, for example ), 'price' => 9.90, 'associated_skus' => array('SKU-001', 'SKU-002'), // Simple products to associate ); try { $proxy->catalogProductCreate($sessionId,'configurable','Default','Configurable Product',$productData); }catch(Exception $e) { echo "
"; die(var_dump($e)); echo ""; } I'm receiving the following error: ["previous":"Exception":private]=> NULL ["faultstring"]=> string(92) "Call to undefined method Mage_Catalog_Model_Product_Attribute_Backend_Price::getAllOptions()" ["faultcode"]=> string(15) "SOAP-ENV:Server" }
Awesome script!!
Unfortunately it doesn't work for me with Magento 1.7.0.2.
I'm using API_V2 and always get the error "SOAP-ERROR: Encoding: object has no 'key' property" when trying your example.
The 'price_changes' array kills it somehow.
If i use the WSI price_changes array with the API call, it ends with a "array to string conversion" notice and "SOAP-ERROR: Encoding: string 'Cannot use object of type stdClass\xe0...' is not a valid utf-8 string".
Need some help :/
Thanks,
Andi
does this work with 1.9+ CE ? or what about EE ?
<?php
$options = array(
'trace' => true,
'connection_timeout' => 86400,
'wsdl_cache' => WSDL_CACHE_NONE,
);
$proxy = new SoapClient('https://www.veromotos.com.br/index.php/api/v2_soap/?wsdl=1',$options);
try {
echo "<pre>";
$sessionId = $proxy->login('example', 'example123@');
echo "</pre>";
}catch(Exception $e) {
die(var_dump($e));
}
/**
* Simple product #1 (sku : SKU-001)
*/
$productData = array(
'name' => 'Produto Simples #1',
'description' => 'Descrição do Produto Simples #1',
'short_description' => 'Descrição Curta do Produto Simples #1',
'website_ids' => array('base'), // Id or code of website
'status' => 1, // 1 = Enabled, 2 = Disabled
'visibility' => 1, // 1 = Not visible, 2 = Catalog, 3 = Search, 4 = Catalog/Search
'tax_class_id' => 2, // Default VAT
'weight' => 0,
'stock_data' => array(
'use_config_manage_stock' => 0,
'manage_stock' => 0, // We do not manage stock, for example
),
'price' => 9.90, // Same price than configurable product, no price change
'additional_attributes' => array(
'single_data' => array(
array(
'key' => 'cores',
'value' => 'AMARELO', // Id or label of color, attribute that will be used to configure product
),
),
),
);
$proxy->catalogProductCreate($sessionId, 'simple', 'Default', 'SKU-001', $productData);
/**
* Simple product #2 (sku : SKU-002)
*/
$productData = array(
'name' => 'Produto Simples #2',
'description' => 'Descrição do Produto Simples #2',
'short_description' => 'Descrição Curta do Produto Simples #2',
'website_ids' => array('base'), // Id or code of website
'status' => 1, // 1 = Enabled, 2 = Disabled
'visibility' => 1, // 1 = Not visible, 2 = Catalog, 3 = Search, 4 = Catalog/Search
'tax_class_id' => 2, // Default VAT
'weight' => 0,
'stock_data' => array(
'use_config_manage_stock' => 0,
'manage_stock' => 0, // We do not manage stock, for example
),
'price' => 8.90, // Red product is $1 less than configurable product
'additional_attributes' => array(
'single_data' => array(
array(
'key' => 'cores',
'value' => 'AZUL', // Id or label of color, attribute that will be used to configure product
),
),
),
);
// Creation of product #2
$proxy->catalogProductCreate($sessionId, 'simple', 'Default', 'SKU-002', $productData);
/**
* Configurable product
*/
$productData = array(
'name' => 'Produto Configurável',
'description' => 'Descrição do produto configurável',
'short_description' => 'Descrição curta do produto configurável',
'website_ids' => array('base'), // Id or code of website
'status' => 1, // 1 = Enabled, 2 = Disabled
'visibility' => 4, // 1 = Not visible, 2 = Catalog, 3 = Search, 4 = Catalog/Search
'tax_class_id' => 2, // Default VAT
'weight' => 0,
'stock_data' => array(
'use_config_manage_stock' => 0,
'manage_stock' => 0, // We do not manage stock, for example
),
'price' => 9.90,
'associated_skus' => array('SKU-001', 'SKU-002'), // Simple products to associate
);
try {
$proxy->catalogProductCreate($sessionId,'configurable','Default','Configurable Product',$productData);
}catch(Exception $e) {
echo "<pre>";
die(var_dump($e));
echo "</pre>";
}
I'm receiving the following error:
["previous":"Exception":private]=>
NULL
["faultstring"]=>
string(92) "Call to undefined method Mage_Catalog_Model_Product_Attribute_Backend_Price::getAllOptions()"
["faultcode"]=>
string(15) "SOAP-ENV:Server"
}
Mixed Content: The page at 'https://example.com/index.php/admin/system_config/edit/section/payment/key/123456/' was loaded over HTTPS, but requested an insecure image 'http://i.imgur.com/nkD1M9R.png'. This content should also be served over HTTPS.
The image is tightly coupled to imgur which seems odd, but it's hardcoded to request a http image which is causes a mixed content warning when the admin panel is on https.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.