Recently when i working Magento data migration team, some sort of reason we use magento SOAP API for migrate products details. one of the major issue that we face was migrate Bundle product via soap API. At the moment magento core API doesn't support create bundle product via API.
There for i decided to create Custom extension for Create Bundle product via soap API. After spend few hours on web found the possible way to implement it. hope this will help any one who want create Bundle product in Magento via SOAP API.
Extension Files
/www/magento/app/etc/Company_Bundleapi.xml
/www/magento/app/code/local/Company/Bundleapi/Model/Objectmodel/Api.php
/www/magento/app/code/local/Company/Bundleapi/etc/api.xml
/www/magento/app/code/local/Company/Bundleapi/etc/config.xml
Source Code
/www/magento/app/etc/Company_Bundleapi.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Bundleapi>
<active>true</active>
<codePool>local</codePool>
</Company_Bundleapi>
</modules>
</config>
/www/magento/app/code/local/Company/Bundleapi/etc/api.xml
<?xml version="1.0"?>
<config>
<api>
<resources>
<bundle_link translate="title" module="company_bundleapi">
<title>Title Of Bundle link</title>
<model>bundleapi/objectmodel_api</model>
<methods>
<createlink translate="title" module="company_bundleapi">
<title>Title Of Create link method</title>
</createlink>
</methods>
</bundle_link>
</resources>
</api>
</config>
/www/magento/app/code/local/Company/Bundleapi/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Company_Bundleapi>
<version>0.1.0</version>
</Company_Bundleapi>
</modules>
<global>
<models>
<bundleapi>
<class>Company_Bundleapi_Model</class>
</bundleapi>
</models>
</global>
</config>
/www/magento/app/code/local/Company/Bundleapi/Model/Objectmodel/Api.php
<?php
class Company_Bundleapi_Model_ObjectModel_Api extends Mage_Api_Model_Resource_Abstract
{
public function createlink($pitems,$pselectionRawData, $pproductId, $storeid)
{
$selections = array();
$selections = $pselectionRawData;
$productId = $pproductId;
$product = Mage::getModel('catalog/product')->setStoreId($storeid);
if ($productId) {
$product->load($productId);
}
Mage::register('product', $product);
Mage::register('current_product', $product);
$product->setCanSaveConfigurableAttributes(false);
$product->setCanSaveCustomOptions(true);
$product->setBundleOptionsData($pitems);
$product->setBundleSelectionsData($selections);
$product->setCanSaveCustomOptions(true);
$product->setCanSaveBundleSelections(true);
$product->save();
return $product->getName();
}
}
?>
Usage
$items[] = array(
'title' => 'Bundle Option',
'option_id' => '',
'delete' => '',
'type' => 'radio',
'required' => 1,
'position' => 0);
$selectionRawData[$i][0] = array(
'selection_id' => '',
'option_id' => '',
'product_id' => $magento_pr_id,
'delete' => '',
'selection_price_value' => 0,
'selection_price_type' => 0,
'selection_qty' => 1,
'is_default' => 1,
'selection_can_change_qty' => 0,
'position' => 0);
$resultretun = $proxy->call($sessionId, 'bundle_link.createlink', array($items, $selectionRawData, $productId, $storeid));
There for i decided to create Custom extension for Create Bundle product via soap API. After spend few hours on web found the possible way to implement it. hope this will help any one who want create Bundle product in Magento via SOAP API.
Extension Files
/www/magento/app/etc/Company_Bundleapi.xml
/www/magento/app/code/local/Company/Bundleapi/Model/Objectmodel/Api.php
/www/magento/app/code/local/Company/Bundleapi/etc/api.xml
/www/magento/app/code/local/Company/Bundleapi/etc/config.xml
Source Code
/www/magento/app/etc/Company_Bundleapi.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Bundleapi>
<active>true</active>
<codePool>local</codePool>
</Company_Bundleapi>
</modules>
</config>
/www/magento/app/code/local/Company/Bundleapi/etc/api.xml
<?xml version="1.0"?>
<config>
<api>
<resources>
<bundle_link translate="title" module="company_bundleapi">
<title>Title Of Bundle link</title>
<model>bundleapi/objectmodel_api</model>
<methods>
<createlink translate="title" module="company_bundleapi">
<title>Title Of Create link method</title>
</createlink>
</methods>
</bundle_link>
</resources>
</api>
</config>
/www/magento/app/code/local/Company/Bundleapi/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Company_Bundleapi>
<version>0.1.0</version>
</Company_Bundleapi>
</modules>
<global>
<models>
<bundleapi>
<class>Company_Bundleapi_Model</class>
</bundleapi>
</models>
</global>
</config>
/www/magento/app/code/local/Company/Bundleapi/Model/Objectmodel/Api.php
<?php
class Company_Bundleapi_Model_ObjectModel_Api extends Mage_Api_Model_Resource_Abstract
{
public function createlink($pitems,$pselectionRawData, $pproductId, $storeid)
{
$selections = array();
$selections = $pselectionRawData;
$productId = $pproductId;
$product = Mage::getModel('catalog/product')->setStoreId($storeid);
if ($productId) {
$product->load($productId);
}
Mage::register('product', $product);
Mage::register('current_product', $product);
$product->setCanSaveConfigurableAttributes(false);
$product->setCanSaveCustomOptions(true);
$product->setBundleOptionsData($pitems);
$product->setBundleSelectionsData($selections);
$product->setCanSaveCustomOptions(true);
$product->setCanSaveBundleSelections(true);
$product->save();
return $product->getName();
}
}
?>
Usage
$items[] = array(
'title' => 'Bundle Option',
'option_id' => '',
'delete' => '',
'type' => 'radio',
'required' => 1,
'position' => 0);
$selectionRawData[$i][0] = array(
'selection_id' => '',
'option_id' => '',
'product_id' => $magento_pr_id,
'delete' => '',
'selection_price_value' => 0,
'selection_price_type' => 0,
'selection_qty' => 1,
'is_default' => 1,
'selection_can_change_qty' => 0,
'position' => 0);
$resultretun = $proxy->call($sessionId, 'bundle_link.createlink', array($items, $selectionRawData, $productId, $storeid));
magento expert developers should keep an eagle's watch over the updates if they want to remain at the very top of the developer chain.
ReplyDeleteHow to integrate social login and sharing on my Magento e-commerce site?
ReplyDeleteMagento Modules
I used this service when i started my business website, it helped me to come up from 34th position to 5th position in google keyword search. Site is: http://cybernetworks.com.au ...Hope this helps.
ReplyDeleteoutsourcingall.com "Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it.
ReplyDeleteThis paragraph gives clear idea for the new viewers of blogging, Thanks you. You’re doing a great job Man, Keep it up.
Seo training
outsourcing training in dhaka
Best Website Development and Design Company in Bangladesh
free outsourcing training
graphic design training
digital marketing training
affiliate marketing training