I am adding a new Product using the API, I am then running the function below to add an Image to the newly created product.
The problem is, when I view the newly created product, it has 1 valid image that was uploaded and then 1 broken image. It seems like it always makes 2 image records in the Admin panel even though only 1 image is uploaded.
I have tested this on multiple Magento installs and the problem persist everywhere. I am at a lost as to what to do next.
View this image to see the result after adding 1 image through the API, you can see it makes 2 entries (1 good one and 1 bad one)...
You can see in the image that the broken image is selected as the default. I cannot figure out why this broken image is even being created instead of my uploaded image being used.
Below is the Image API code I am using.
function uploadImage( $sku, $imagePath, $productId ) {
global $proxy;
global $sessionId;
$sku = strtoupper($sku );
$newImage = array(
'file' => array(
'name' => 'file_name',
'content' => base64_encode(file_get_contents($imagePath)),
'mime' => 'image/png'
),
'label' => "Item:" . $sku,
'position' => 0,
'types' => array('image', 'small_image', 'thumbnail', 'ebayimage' ),
'exclude' => 0
);
try {
$imageFilename = $proxy->call(
$sessionId,
'catalog_product_attribute_media.create',
array(
$productId,
$newImage
)
);
echo '<br>Image Filename Added '.$imageFilename;
//var_dump($proxy->call($sessionId, 'product_media.list', $sku));
}
catch(Exception $e) {
print( "Error assigning image to $sku: " . $e->getMessage() . "\n" );
}
}
And here is my Product creating code which then calls the Image function above...
try {
// Create new product
$productId = $proxy->call(
$sessionId,
'product.create',
array(
'simple',
$attributeSet,
$productSku,
$productData
)
);
echo 'Product ID Create: '.$productId;
// Upload and attach Image
$imagePath = 'twitter-header.png';
uploadImage( $productSku, $imagePath, $productId );
} catch (SoapFault $e) {
echo "Product creation error $e";
}
Any ideas why it would be creating this dummy broken image record everytime it creates a valid record?
UPDATE
I was starting to think that possibly another extension on the magento site I am working on might be the cause but I have now tried my code on a brand new fresh Magento Install and the issue still exist. For every Image that I create through the API, it then creates an additional broken image with the original image name with _1
added to the end of the filename.
I cannot figure out why this is happening, surely such a huuuuuge bug wouldn't have lived in Magento this long?
Here is the result of the API call...You can see 2 image records for each Image added. The 2nd is the broken image and it is assigned the thumbnail, small_image, and image values