Last active
February 3, 2017 22:30
-
-
Save willboudle/13057db6c5714a8db027 to your computer and use it in GitHub Desktop.
Add Product's Images using Magento API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // API Configuration | |
| $this->APIUrl= "http://yourdomain.com/index.php/api/soap/?wsdl"; | |
| $this->APIUser="APIUser"; | |
| $this->APIKey= "APIKey"; | |
| function addAPIImages($product_id){ | |
| $sql ="SELECT * FROM YourDatabaseTable WHERE ProductID = $product_id"; | |
| $resultat=mysql_query($sql) or die('SQL error:'.mysql_error()); | |
| while ($row = mysql_fetch_array($resultat)) { | |
| $imageURL = $row['ImageURL']; | |
| $proxy = new SoapClient($this->APIUrl); | |
| $sessionId = $proxy->login($this->APIUser, $this->APIKey); | |
| $newImage = array( | |
| 'file' => array( | |
| 'content' => base64_encode(file_get_contents($imageURL)), | |
| 'mime' => 'image/jpeg' | |
| ), | |
| 'label' => $row['ProductName'], | |
| 'position' => 1, | |
| 'types' => array('image','small_image','thumbnail'), | |
| 'exclude' => 0 | |
| ); | |
| try { | |
| $imageFilename = $proxy->call($sessionId, 'product_media.create', array($product_id, $newImage)); | |
| } catch ( SoapFault $e ) { | |
| echo $e->getMessage (); | |
| continue; | |
| } | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment