Magento Forum

   
[API] Pass manufacturer by name (instead of ID)
 
microalps
Jr. Member
 
Total Posts:  2
Joined:  2008-11-03
 

I’m looking to use the catalog_product.create api to pass a manufacturer (or any dropdown attribute) by name instead of by ID. I would like to detect if this dropdown option exists and if not create it. I assume my code needs to go Mage\Catalog\Model\Product\API after this piece of code:

if ($this->_isAllowedAttribute($attribute)
                && isset(
$productData[$attribute->getAttributeCode()])) {

If anyone can assist on this, it would be greatly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
microalps
Jr. Member
 
Total Posts:  2
Joined:  2008-11-03
 

Here’s the code I have so far, it will translate the manufacturer into an option ID, but still can’t create a new option.

if ($attribute->usesSource() && !is_int($productData[$attribute->getAttributeCode()])) {
                  $value 
$attribute->getSource()->getOptionId($productData[$attribute->getAttributeCode()]);
                  if (!empty(
$value))
                    
$productData[$attribute->getAttributeCode()$value;
                  
else{
                    
//create new option
                  
}
                }

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top