Configurable product and its associated product creation using soap api documentation is not in magento api guide.any idea? - magento

I am trying to create a configurable product and its associated product using magento soap api.Product created successfully but configurable product linking with associated product is not working properly guys any idea? This is my code
<?php
$client = new SoapClient('https://sample.com/api/v2_soap?wsdl=1');
// If some stuff requires api authentification,
// then get a session token
$session = $client->login('username', 'Password');
// get attribute set
$attributeSets = $client->catalogProductAttributeSetList($session);
$attributeSet = current($attributeSets);
print_r($attributeSet);
$result = $client->catalogProductCreate($session, 'simple',72, 'product_sku0002', array(
'categories' => array(2),
'websites' => array(1),
'name' => 'Product name',
'description' => 'Product description',
'short_description' => 'Product short description',
'weight' => '10',
'status' => '1',
'url_key' => 'product-url-key',
'url_path' => 'product-url-path',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title',
'meta_keyword' => 'Product meta keyword',
'meta_description' => 'Product meta description',
'additional_attributes' => array(
'single_data' => array(
array(
'key' => 'color',
'value' => 'Red', // Id or label of color, attribute that will be used to configure product
)
),
),
));
var_dump ($result);
$result = $client->catalogProductCreate($session, 'configurable',72, 'Configurable_product_sku0001', array(
'categories' => array(2),
'websites' => array(1),
'name' => 'Confihurable Product name',
'description' => 'Product description',
'short_description' => 'Product short description',
'weight' => '10',
'status' => '1',
'url_key' => 'product-url-key',
'url_path' => 'product-url-path',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title',
'meta_keyword' => 'Product meta keyword',
'meta_description' => 'Product meta description',
'associated_skus' => array('product_sku0002'),
'price_changes' => array(
array(
'color' => array(
'Red' => '0'
)
),
),
));
var_dump ($result);
?>

Its working fine using this method follow the link
http://www.bubblecode.net/en/2012/04/20/magento-api-associate-simple-products-to-configurable-or-grouped-product/

Related

How to Make a Status Field Bydefault Enable in Magento Form?

Following is my Form Field Code.
$fieldset->addField('status','select',
array(
'label' => Mage::helper('synclogin')->__('Eshot Status'),
'name' => 'status',
'values' => array(
array(
'value' => 0,
'label' => Mage::helper('synclogin')->__('Disabled'),
),
array(
'value' => 1,
'label' => Mage::helper('synclogin')->__('Enabled'),
),
),
)
);
How to Make a Status Field Bydefault Enable in Magento Form?
$fieldset->addField('status','select',
array(
'label' => Mage::helper('synclogin')->__('Eshot Status'),
'name' => 'status',
'value' => '1',
'values' => array(
array(
'value' => 0,
'label' => Mage::helper('synclogin')->__('Disabled'),
),
array(
'value' => 1,
'label' => Mage::helper('synclogin')->__('Enabled'),
),
),
)
);

How to get Manufacturer dropdown in custom module edit form?

I want to add images for each brand, for that i have created a module. in module's edit form i want a manufacturer dropdown list so i can assign image to the particular manufacturer/brand.
its my code for the edit form location:
app/code/local/Root/Brand/Block/Adminhtml/Brand/Edit/Tab/form.php
$fieldset->addField('title', 'select', array(
'name' => 'title',
'label' => 'Brand',
'values' => Mage::getUrl('catalogsearch/advanced/result', array(
'brand' => $option['value']
))
));
$fieldset->addField('filename', 'image', array(
'label' => Mage::helper('brand')->__('Brand Image') ,
'required' => false,
'name' => 'filename',
'note' => '(*.jpg, *.png, *.gif)'
));
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'manufacturer');
//here, "brandname" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
$fieldset->addField('title', 'select', array(
'label' => Mage::helper('brand')->__('Brand Name'),
'name' => 'title',
'values' => $allOptions
));

How to change comments data with onchange function in addfield in magento

I created custom module and now from admin side on edit form i added extra field select type.
I want to change comments with onchange function for this specific field.See below my code.
$eventElem = $fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
));
$eventElem->setAfterElementHtml("<script type=\"text/javascript\">function checkSelectedItem(selectElement){}</script>");
This is my code i alert the value and i got my value but it cannot show it in comments area .Did someone one know how to fix it ?
Thanks
This will update the comment (onchange) with the current selected option
$fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
)
))->setAfterElementHtml("<small id='banner_type_comment'>Comments</small>
<script type=\"text/javascript\">
function checkSelectedItem(selectElement){
$('banner_type_comment').update($('banner_type')[$('banner_type').selectedIndex].text);
}
</script>");

set selected field when define with 'type' => 'select' in magento

I have a custom module where I create a form.
One field is a dropdown with values from a flat file.
$fields = array(
'type_of_service' => array('display' => 'Tip serviciu',
'required' => true,
'type' => 'select',
'options' => $serviceTypeOptions,
How can I set one value to be selected ?
EDIT:
if I use something like this in _prepareForm()
$fieldset->addField('select', 'select', array(
'label' => Mage::helper('tracking')->__('Select'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
'value' => '3',
'values' => array('-1'=>'Please Select..','1' => 'Option1','2' => 'Option2', '3' => 'Option3'),
)),
preselected will be 3.
But I generate my fields previously, and assign those to form with
$formFields = $this->getFormFields();
The problem is that I can't use the addField method, I need to have them created within my function.
Thanks.
try this,
'required' => true,
'value' => '2',
'values' => array(
array('1' => 'Option 1','2' => 'Option 2'),
...
which will select Option 2.
Try this
'required' => true,
'value' => 2,
'values' => array(
array('label' => 'Option 2', value => 2),
array('label' => 'Option 1', value => 1)
)
A full example can be like below
$fieldset->addField(
'target_type',
'select',
array(
'label' => $this->__("Target Type"),
'class' => 'required-entry',
'required' => 'true',
'name' => 'target_type',
'note' => $this->__("Target Type"),
'value' => 2,
'values' => array(
array(
'value' => 2,
'label' => 'Option 2'
)
)
)
);
NOTE : If you want to know about any of the Varien_Data_Form_Elements, you can directly do an inspection of Varien library /lib/Varien/Data/Form/Element/Select.php in your case.

Magento Custom module - how to add custom select box with parent categories

I wrote a module to have my own menu bar, rather than just using categories as a menu bar.
So, here I want to show already added menus while adding new menu in the Tab/Form.php in my custom menu module. How can I show all of the existing menu names as a dropdown/options list on the form. Here is the code that I used to have menu form.
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('menu_form', array('legend'=>Mage::helper('menu')->__('Menu information')));
$note = "Name of this Menu";
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('menu')->__('Menu Name'),
'class' => 'required-entry',
'required' => true,
'note' => $note,
'name' => 'title',
));
$note = "Menu level";
$fieldset->addField('level', 'select', array(
'label' => Mage::helper('menu')->__('Menu level'),
'name' => 'level',
'note' => $note,
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Level 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Level 2'),
),
),
));
$model = Mage::registry('menu');
$fieldset->addField('parent', 'text', array(
'name' => 'conditions',
'label' => Mage::helper('menu')->__('Parent Menu'),
'title' => Mage::helper('menu')->__('Parent Menu'),
'required' => false,
'note' => $note,
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
$fieldset->addField('target', 'select', array(
'label' => Mage::helper('menu')->__('Open in new window'),
'name' => 'target',
'values' => array(
array(
'value' => "_blank",
'label' => Mage::helper('menu')->__('Yes'),
),
array(
'value' => "_self",
'label' => Mage::helper('menu')->__('No'),
),
),
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('menu')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Disabled'),
),
),
));
$note = "Menu Links to Which page. BaseURL(<b>".str_ireplace("index.php/","",Mage::getBaseUrl())."</b>) Will be Added Dynamically, Please add Your new page Refrence alone";
$fieldset->addField('menulink', 'text', array(
'label' => Mage::helper('menu')->__('URL'),
'required' => true,
'class' => 'required-entry',
'note' => $note,
'name' => 'menulink',
));
$fieldset->addField('position', 'select', array(
'label' => Mage::helper('menu')->__('Position'),
'name' => 'position',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Top 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Top 2'),
),
),
));
if ( Mage::getSingleton('adminhtml/session')->getMenuData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getMenuData());
Mage::getSingleton('adminhtml/session')->setMenuData(null);
} elseif ( Mage::registry('menu_data') ) {
$form->setValues(Mage::registry('menu_data')->getData());
}
return parent::_prepareForm();
In this I want to show all the added menus under the parent menu option. What should I write in my Model class so that I can have a drop down list to show them all, and after adding it should be added to database.
Please help me, am struggling here.
You can do this by adding these lines.
It will show already added menus as a dropdown list so that you can choose any of them as a parent menu for current item.
$_menus = Mage::getSingleton('menus/menus')->getCollection();
foreach($_menus as $item)
{
if($item->getParent == NULL){
$_menuItems[] = array(
'value' => $item->getId(),
'label' => $item->getTitle(),
);
}
}
$note = "Choose the parent menus for this item";
$fieldset->addField('parent', 'select', array(
'name' => 'parent',
'label' => Mage::helper('menus')->__('Parent Menu'),
'title' => Mage::helper('menus')->__('Parent Menu'),
'required' => false,
'note' => $note,
'class' => 'HideIt',
'values' => $_menuItems,
));

Resources