I have my custom product attributes in magento.i want to set the product description dynamically.is their any way in magento so that we can find the attribute is custom created by us not by default magento.
i had searched.but not got any success.
Please Help.
Thanks in Advance.
Let's say you have an attribute with code some_code.
Here is how you can check if it's a system attribute or if it's a custom one.
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'some_code');
if ($attribute->getIsUserDefined()) {
//then you created the attribute
}
else {
//then it's a system attribute
}
Use the magento soap/rest api for creating a custom attribute for Product and update with values as well,
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
echo "<pre>";
// Create new attribute
$attributeToCreate = array(
"attribute_code" => "new_attribute",
"scope" => "store",
"frontend_input" => "select",
"is_unique" => 0,
"is_required" => 0,
"is_configurable" => 0,
"is_searchable" => 0,
"is_visible_in_advanced_search" => 0,
"used_in_product_listing" => 0,
"additional_fields" => array(
"is_filterable" => 1,
"is_filterable_in_search" => 1,
"position" => 1,
"used_for_sort_by" => 1
),
"frontend_label" => array(
array( "store_id" => 0,"label" => "A new attribute" )
)
);
$attributeId = $proxy->call($sessionId,"product_attribute.create",
array(
$attributeToCreate
)
);
// Update attribute
$attributeToUpdate = array(
"scope" => "global",
"is_unique" => 1,
"is_required" => 1,
"is_configurable" => 1,
"is_searchable" => 1,
"is_visible_in_advanced_search" => 0,
"used_in_product_listing" => 0,
"additional_fields" => array(
"is_filterable" => 01,
"is_filterable_in_search" => 0,
"position" => 2,
"used_for_sort_by" => 0
),
"frontend_label" => array(
array(
"store_id" => 0,
"label" => "A Test Attribute"
)
)
);
$proxy->call(
$sessionId,
"product_attribute.update",
array(
"new_attribute",
$attributeToUpdate
)
);
I hope this will solve your problem..
You can use Magento default API to get default product list
For more details you can refer to following url:
http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.listOfAdditionalAttributes.html
Code used will be:
$proxy = new SoapClient('localhost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$listAttributes = $proxy->call($sessionId, 'product.listOfAdditionalAttributes', array( 'simple', 13 ));
Related
I have created a custom attribute for the billing address on my magneto backed (Sales-> order -> billing address). However, the attribute input field is showing on the backend without the label. like this
My backend array for this label is like this.
$attributes = array(
'buildingnumber' => array(
'label' => 'Building Number',
'backend_type' => 'varchar',
'frontend_input' => 'text',
'is_user_defined' => 1,
'is_system' => 0,
'is_visible' => 1,
'is_required' => 1,
'multiline_count' => 0,
'validate_rules' => array(
'max_text_length' => 255,
'min_text_length' => 1
),
),
);
Please let me know how to add a label for my field.
Open eav_attribute table and search for buildingnumber attribute_code and check field frontend_label
I am working on virtual products type in magento.i want to set following properties to product progrmmatically.
[recurring_profile] => Array
(
[start_date_is_editable] =>
[schedule_description] =>
[suspension_threshold] =>
[bill_failed_later] =>
[period_unit] =>
[period_frequency] =>
[period_max_cycles] =>
)
I had searched but no success and i had tried some solutions then also no success.please help me to achive this task.
Thanks
$_product = Mage::getModel('catalog/product')->load($proid);
$productname = $_product->getName();
$_product->setIsRecurring('1');
$_product->setRecurringProfile(array(
'start_date_is_editable' => 0,
'schedule_description' => $productname,
'suspension_threshold' => 1,
'bill_failed_later' => 1,
'period_unit' => day,
'period_frequency' => 12,
'period_max_cycles' => 1
));
I am using SOAP v1 of the Magento API, I am trying to add an option to an attribute.
My Code:
$attributeCode = "feltColor";
$optionToAdd = array(
"Label" => array(
array(
"store_id" => 1,
"value" => "Green"
)
),
"order" => 0,
"is_default" => 0
);
But I keep getting the following error:
Fatal error: Uncaught SoapFault exception: [108] Default option value is not defined
Can't get it to work...any suggestions?
You need to specify a label for store_id = 0 (instead of or in addition to defining one for store_id = 1).
This is from the docs for product_attribute.create, but also holds true for product_attribute.addOption:
Notes: The "label" value for the "store_id" value set to 0 must be
specified. An attribute cannot be created without specifying the label
for store_id=0.
If you define a label for store_id = 0, that is the default, so you don't need to define it for other store views unless you want to override the default:
$attributeCode = "feltColor";
$optionToAdd = array(
"Label" => array(
array(
"store_id" => 0,
"value" => "Green"
)
),
"order" => 0,
"is_default" => 0
);
The following code does create a configurable product, however, when I open the product in the backend, the following message appears:
Select Configurable Attributes
"Only attributes with scope "Global", input type "Dropdown" and Use To Create Configurable Product "Yes" are available."
A single checkbox is displayed ("Colour Group"), which must be selected before continuing.
When I click "Continue", all of the product data is there as expected EXCEPT for the associated products.
//Mage Product
$mpr = Mage::getModel('catalog/product');
$mpr
->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
->setTaxClassId(5)
->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
->setWebsiteIds(array(1))
->setAttributeSetId(4) // You can determine this another way if you need to.
->setSku("C12345")
->setName("C12345")
->setQty(25)
->setShortDescription('short description')
->setDescription('description')
->setPrice(1)
->setStockData(array(
'use_config_manage_stock' => 1,
'is_in_stock' => 1,
'is_salable' => 1,
));
$productData = array(
'7039604' =>
array('0' => array('attribute_id' => '85', 'label' => 'ROYAL','value_index' => '28563', 'is_percent' => 0, 'pricing_value' => '')
,'1' => array('attribute_id' => '192', 'label' => '14', 'value_index' => '28728', 'is_percent' => 0, 'pricing_value' => '')
)
);
$attributeData = array(
'0' => array(
'id' => NULL
,'label' => 'Color'
,'position' => NULL
,'values' => array(
'0' => array('value_index' => 28563, 'label' => 'ROYAL', 'is_percent' => 0, 'pricing_value' => '0', 'attribute_id' => '85')
)
,'attribute_id' => 85
,'attribute_code' => 'color'
,'frontend_label' => 'Color'
,'html_id' => 'config_super_product__attribute_0')
,'1' => array(
'id' => NULL
,'label' => 'Rivers Size'
,'position' => NULL
,'values' => array(
'0' => array('value_index' => 28728, 'label' => '14', 'is_percent' => 0, 'pricing_value' => '0', 'attribute_id' => '192')
)
,'attribute_id' => 192
,'attribute_code' => 'rivers_size'
,'frontend_label' => 'Rivers Size'
,'html_id' => 'config_super_product__attribute_1')
);
$mpr->setConfigurableProductsData($productData);
$mpr->setConfigurableAttributesData($attributeData);
$mpr->setCanSaveConfigurableAttributes(true);
$mpr->save();
Add this code before $mpr->save();
$SKU = "any-simple product sku enter here";
$productid = Mage::getModel('catalog/product')
->getIdBySku(trim($SKU));
$mpr->assignProduct($productid);
And set simple product sku in $SKU variable. and i have check that when i select global variable then after i see associated product in configure product.
Its work fine !!!
If you are getting redirected to select attribute page, this means that attribute data you set in this sample is not saved correctly.
Try viewing catalog_product_super_attribute after script run (new rows should be added).
I've been following along with this example: Magento programmaticaly create bundle Product
and the code is working when I create a new product, however, I can't get it to work when I load a product either bundled or simple. [EDIT] I can load a bundled product that I created programmatically through the code below and add products to the bundle. A bundled product I created through the GUI I cannot add products too.
Any idea how I can load a product up then bundle it with another a product?
Here is my current code:
$items = array();
$items[] = array(
'title' => 'Bundle Option',
'option_id' => '',
'delete' => '',
'type' => 'radio',
'required' => 1,
'position' => 0,
);
$selectionRawData = array();
$selectionRawData[0] = array();
$selectionRawData[0][] = array(
'selection_id' => '',
'option_id' => '',
'product_id' => 3,
'delete' => '',
'selection_price_value' => 0,
'selection_price_type' => 0,
'selection_qty' => 1,
'selection_can_change_qty' => 0,
'position' => 0,
'is_default' => 1,
);
$selections = $selectionRawData;
$websiteIDs = array(1);
$cats = array(4);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
// load product
// NOT WORKING
$product = Mage::getModel('catalog/product');
$product->load(127);
// new product
/******
* THIS WORKS
$p = array(
'sku_type' => 1,
'sku' => '123321',
'name' => "BarProduct",
'description' => 'Foo',
'short_description' => 'Bar',
'type_id' => 'bundle',
'attribute_set_id' => 4,
'weight_type' => 0,
'visibility' => 4,
'price_type' => 1,
'price_view' => 0,
'price' => 1.99,
'has_options' => 1,
'required_options' => 1,
'status' => 1,
'created_at' => strtotime('now'),
'category_ids' => $cats,
'store_id' => 0,
'website_ids' => $websiteIDs,
'weight' => 0,
'weight_type' => 1,
'delivery_time' => '',
'generate_meta' => 1,
'tax_class_id' => 1, //19%
);
$product->setData($p);
*****/
Mage::register('product', $product);
Mage::register('current_product', $product);
$product->setCanSaveConfigurableAttributes(false);
$product->setCanSaveCustomOptions(true);
$product->setBundleOptionsData($items);
$product->setBundleSelectionsData($selections);
$product->setCanSaveCustomOptions(true);
$product->setCanSaveBundleSelections(true);
$product->setAffectBundleProductSelections(true);
$product->save();
$result['product_name'] = $product->getId();
return $result;
This is important for bundled products:
$product->setData("price_type", 0);
You must set this attribute to 0 (Dynamic price) before saving.
Reindexing is then necessary of course.
I had some funky stuff going on with my product index. I deleted all my products and fixed my index and this now works, albeit not well.
So here is what I gleaned from the process:
If you want to take two simple products and bundle them, you'll need to create a new bundled bundled product via the $p = array code above, then add both simple products.
Otherwise, you'll need a bundled product that is premade via the magento gui. then you'll have bring up that product using the $product->load(product_id) command, then add your simple products to that.
Just delete all unneeded options like this:
$optionsselectionsmap = array();
$options = Mage::getModel("bundle/option")->getCollection()->setProductIdFilter($product->getId());
foreach($options as $option){
$selection = Mage::getModel("bundle/selection")->getCollection()->setOptionIdsFilter($option->getId())->getFirstItem();
$tmp = array();
$tmp['option_id'] = $option->getId();
$tmp['selection_id'] = $selection->getData('selection_id');
$optionsselectionsmap[$selection->getData('sku')] = $tmp;
}
$deleteoptionids = array();
foreach($optionsselectionsmap as $k=>$v) $deleteoptionids[] = $v['option_id'];
foreach($product->getTypeInstance(true)->getOptionsCollection($product) as $deleteitem){
$deleteitem = $deleteitem->getData();
$deleteitem['delete'] = 1;
$bundleOptions[] = $deleteitem;
}