Skip to content

NEW FEATURE Wildcard on gallery paths#128

Open
Centilitre wants to merge 9 commits into
dweeves:masterfrom
Centilitre:master
Open

NEW FEATURE Wildcard on gallery paths#128
Centilitre wants to merge 9 commits into
dweeves:masterfrom
Centilitre:master

Conversation

@Centilitre

Copy link
Copy Markdown

This new feature enables the use of wildcard (*) on image paths on the media_gallery field.

By enabling this feature, it simplifies image paths in media_gallery column,
from something like this (/demo1/image1.jpg;/demo1/image2.jpg;/demo1/image3.jpg)
to this (/demo1/*.jpg)

Added option to turn this feature on and off.

Tested in Linux server, need testing in windows

This new feature enables the use of wildcard (*) on image paths on the
media_gallery field.

By enabling this feature, it simplifies image paths in media_gallery
column,
from something like this
(/demo1/image1.jpg;/demo1/image2.jpg;/demo1/image3.jpg)
to this (/demo1/*.jpg)

Added option to turn this feature on and off.

Tested in Linux server, need testing in windows
Originally, when the same image is added to gallery more than once, if
image label is not specified,  the label will be updated with null, as
result it resets image labels.

This has 2 downsides:
1. It resets any manually saved labels through Magento backend.
2. This is not good with the wildcard feature. Because magmi handles
images in this order (I believe): base image, gallery, small image and
at last thumbnail, the label of base image will be reset to null when
gallery contains wildcard path.

This fix basically checks if image label is not specified, do not update
the label to null.
Solution:
if OS is windows, then replace '/' in the pattern with the properly
escaped path separator regex string for windows - '\\\\'
@Centilitre

Copy link
Copy Markdown
Author

Maybe I shall add more information about this feature and some use cases.

The main benefits of this feature are:

  1. Reduce the manual work on typing in the images paths in the media_gallery column for all products.
  2. Remove the image related columns from CSV file completely, by combining this feature with value replace plugin.

I will show you how to use the wildcard feature with these use cases:

Case 0: Testing

We have only 1 prodoct to be imported and this product has several images as shown:
/image1.jpg
/image2.jpg
/image3.jpg
...

CSV: (Without wildcard feature)

sku,image,media_gallery...
demo1,/image1.jpg,/image1.jpg;/image2.jpg;/image3.jpg

CSV: (with wildcard feature on)

sku,image,media_gallery...
demo1,/image1.jpg,/*.jpg

When we have more products and more images, Obviously if we keep all images in the image source folder, all images will be added to every product because of '/*.jpg'. We need to do some work on image renaming and/or file structures.

Consider this scenario for the following cases:
we have N products to be imported and each product has several images.

Case 1: Images are organised into folders

With the scenario above, we have manually organised the product into folders like this:
/demo1/image1.jpg
/demo1/image2.jpg
/demo1/image3.jpg

/demo2/image4.jpg
/demo2/image5.jpg
/demo2/image6.jpg
...

CSV:

sku,image,media_gallery...
demo1,/demo1/image1.jpg,/demo1/*.jpg
demo2,/demo2/image4.jpg,/demo2/*.jpg

...

Now the media_gallery column has a fix pattern, we can remove the column with help from Value Replace plugin
CSV:

sku,image,...
demo1,/demo1/image1.jpg,...
demo2,/demo2/image4.jpg,...

Value Replacer:
New value for media_gallery: /{item.sku}/*.jpg

Note that we can NOT remove the media_gallery column without the wildcard feature in this case.

Case 2: Images are renamed properly

With the scenario above, we have manually renamed the product images like this:
/demo1_1.jpg
/demo1_2.jpg
/demo1_3.jpg

/demo2_1.jpg
/demo2_2.jpg
/demo2_3.jpg
...

CSV:

sku,image,media_gallery...
demo1,/demo1_1.jpg,/demo1*.jpg
demo2,/demo2_1.jpg,/demo2*.jpg

...

Now the image column also has a fix pattern, we can further remove the column with help from Value Replace
CSV:

sku,....
demo1,...
demo1,...

Value Replacer:
New value for image: /{item.sku}_1.jpg
New value for media_gallery: /{item.sku}*.jpg

Note that we can remove the image and media_gallery column without the wildcard feature in this case. The wildcard feature simply shortens the new value for media_gallery. Without the wildcard feature, the new value for media_gallery would be like this: /{item.sku}_1.jpg;/{item.sku}_2.jpg;/{item.sku}_3.jpg

Case 3: Images are renamed and organised into folders

With the scenario above, we have manually renamed the product images and organised them into folders like this:
/demo1/1.jpg
/demo1/2.jpg
/demo1/3.jpg

/demo2/1.jpg
/demo2/2.jpg
/demo2/3.jpg
...

CSV:

sku,image,media_gallery...
demo1,/demo1/1.jpg,/demo1/*.jpg
demo2,/demo2/1.jpg,/demo2/*.jpg

Important: because the images now have duplicated name in different folders, we need to use the image renaming feature to prevent problems. For example:
re::(.)/(.).(.*)$::{item.sku}_$2.$3

Again we can remove the image and media_gallery column with help from Value Replacer plugin
CSV:

sku,....
demo1,...
demo1,...

Value Replacer:
New value for image: /{item.sku}/1.jpg
New value for media_gallery: /{item.sku}/*.jpg

If this feature is turned on, it will assign the base image of the first
associated simple to be the base image, thumbnail and small image of the
configurable, AND add all gallery images of associated simples to the
configurable.

'back' image label support is added. If both features are turned on  ,
When auto adding images to the gallery of configurable, it will clear
any existing 'back' label and set the base image of the second simple to
'back'. The labels of simple products will not be affected.

Options are added to switch both features on and off.
If this feature is turned on, it will assign the base image of the first
associated simple to be the base image, thumbnail and small image of the
configurable, AND add all gallery images of associated simples to the
configurable.

'back' image label support is also added.  If BOTH features are turned
on, when auto adding images to the gallery of configurable, it will
clear any existing 'back' label and set the base image of the second
simple to 'back'. The labels of simple products will not be affected.

Options are added to switch both features on and off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant