Magento Product Image Uploader

Utility tool in Java for uploading product images to Magento site

License

License

MIT
Categories

Categories

Java Languages
GroupId

GroupId

com.github.chen0040
ArtifactId

ArtifactId

java-magento-image-uploader
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Magento Product Image Uploader
Utility tool in Java for uploading product images to Magento site
Project URL

Project URL

https://github.com/chen0040/java-magento-image-uploader
Source Code Management

Source Code Management

https://github.com/chen0040/java-magento-image-uploader

Download java-magento-image-uploader

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.chen0040/java-magento-image-uploader/ -->
<dependency>
    <groupId>com.github.chen0040</groupId>
    <artifactId>java-magento-image-uploader</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.chen0040/java-magento-image-uploader/
implementation 'com.github.chen0040:java-magento-image-uploader:1.0.2'
// https://jarcasting.com/artifacts/com.github.chen0040/java-magento-image-uploader/
implementation ("com.github.chen0040:java-magento-image-uploader:1.0.2")
'com.github.chen0040:java-magento-image-uploader:jar:1.0.2'
<dependency org="com.github.chen0040" name="java-magento-image-uploader" rev="1.0.2">
  <artifact name="java-magento-image-uploader" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.chen0040', module='java-magento-image-uploader', version='1.0.2')
)
libraryDependencies += "com.github.chen0040" % "java-magento-image-uploader" % "1.0.2"
[com.github.chen0040/java-magento-image-uploader "1.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.20
org.slf4j : slf4j-log4j12 jar 1.7.20
com.github.chen0040 : java-magento-client jar 1.0.3

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.6

test (10)

Group / Artifact Type Version
org.testng : testng jar 6.9.10
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3
org.assertj : assertj-core jar 3.5.2
org.powermock : powermock-core jar 1.6.5
org.powermock : powermock-api-mockito jar 1.6.5
org.powermock : powermock-module-junit4 jar 1.6.5
org.powermock : powermock-module-testng jar 1.6.5
org.mockito : mockito-core jar 2.0.2-beta
org.mockito : mockito-all jar 2.0.2-beta

Project Modules

There are no modules declared in this project.

java-magento-image-uploader

Java utility tool which allows user to upload images for each product into a magento site using token-based access

Install

<dependency>
  <groupId>com.github.chen0040</groupId>
  <artifactId>java-magento-image-uploader</artifactId>
  <version>1.0.2</version>
</dependency>

Usage

The sample code below shows how to upload a set of images for each product at the Magento site.

String url = "http://magento.ll";
String username = "admin";
String password = "[email protected]";
ImageUploader uploader = new ImageUploader(url);
String token = uploader.loginAsAdmin(username, password);

if(token != null && !token.equals("")) {
 int pageIndex = 0;
 int pageSize = 10;
 ProductPage page = uploader.page(pageIndex, pageSize);
 boolean overwrite = true;
 uploader.uploadJpeg(page, product -> {
    long productId = product.getId();
    long imageId = (productId % 6 + 1);
    String imageName = "/tmp/images/" + imageId + ".jpg";
    return Arrays.asList(imageName);
 }, overwrite);
}

The code first login to Magento site using the admin account (to login as a client, call uploader.loginAsClient(...) instead).

Next, it then obtain the first 10 products from the Magento site, for each product its product id is used to retrieve the image file stored locally in the /tmp/images folder. The /tmp/images folder has the following images

  • /tmp/images/1.jpg
  • /tmp/images/2.jpg
  • /tmp/images/3.jpg
  • /tmp/images/4.jpg
  • /tmp/images/5.jpg
  • /tmp/images/6.jpg

The mapping between each product and each page is done by (product) -> (product.productId % 6 + 1).jpg. Note that it is feasible to upload multiple images for each product (as evidenced by the line 'Arrays.asList...' in the above code).

The 'overwrite' flag if set to true will delete all images originally associated with the product before upload the new images for the product. If set to false, it will not upload any images if there already been images associated with the product.

To upload png images, use uploadPng(...) instead of uploadJpeg(...)

Versions

Version
1.0.2
1.0.1