Merge lp:~therp-nl/magentoerpconnect/oerp6.1-stable-fix_image_update into lp:magentoerpconnect/oerp6.1-stable

Proposed by Stefan Rijnhart (Opener)
Status: Needs review
Proposed branch: lp:~therp-nl/magentoerpconnect/oerp6.1-stable-fix_image_update
Merge into: lp:magentoerpconnect/oerp6.1-stable
Diff against target: 68 lines (+33/-7)
1 file modified
magentoerpconnect/product_images.py (+33/-7)
To merge this branch: bzr merge lp:~therp-nl/magentoerpconnect/oerp6.1-stable-fix_image_update
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Review via email: mp+190804@code.launchpad.net

Commit message

[FIX] Actually update the image on product image update
[FIX] Magento requires image info to be updated for each storeview

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

LGTM

review: Approve (code review)

Unmerged revisions

695. By Stefan Rijnhart (Opener)

[FIX] Refer to local variable name

694. By Stefan Rijnhart (Opener)

[FIX] Actually update the image on product image update
[FIX] Magento requires image info to be updated for each storeview

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'magentoerpconnect/product_images.py'
2--- magentoerpconnect/product_images.py 2012-12-03 15:08:39 +0000
3+++ magentoerpconnect/product_images.py 2013-10-12 17:01:06 +0000
4@@ -97,6 +97,10 @@
5
6 ir_model_data_obj = self.pool.get('ir.model.data')
7
8+ storeviews = [
9+ storeview.code for storeview in
10+ external_session.sync_from_object.storeview_ids]
11+
12 def detect_types(image):
13 types = []
14 if image.small_image:
15@@ -107,16 +111,37 @@
16 types.append('thumbnail')
17 return types
18
19- #TODO update the image file
20- def update_image(product_extid, image_name, image):
21+ def update_image(product_extid, image_name, image, send_image=False):
22+
23+ values = {'label': image.name,
24+ 'exclude': image.exclude,
25+ 'types': detect_types(image),
26+ }
27+
28+ # Update image info per storeview
29+ for storeview in storeviews:
30+ result = external_session.connection.call(
31+ 'catalog_product_attribute_media.update',
32+ [product_extid, image_name, values, storeview])
33+
34+ if send_image:
35+ values['file'] = {
36+ 'name': image.name,
37+ 'content': image.file,
38+ 'mime': (
39+ image.link and image.url and mimetypes.guess_type(image.url)[0] or
40+ image.extention and
41+ mimetypes.guess_type(image.name + image.extention)[0] or
42+ 'image/jpeg'),
43+ }
44+
45+ # Update global settings, including the image
46 result = external_session.connection.call('catalog_product_attribute_media.update',
47 [product_extid,
48 image_name,
49- {'label':image.name,
50- 'exclude':image.exclude,
51- 'types':detect_types(image),
52- }
53+ values,
54 ])
55+
56 return result
57 list_image = []
58 list_image = self.read(cr, uid, ids, ['write_date', 'create_date'], context=context)
59@@ -152,7 +177,8 @@
60 if ext_file_name: #If update
61 try:
62 external_session.logger.info("Updating %s's image: %s" %(each.product_id.default_code, each.name))
63- result = update_image(product_extid, ext_file_name, each)
64+ result = update_image(
65+ product_extid, ext_file_name, each, send_image=True)
66 external_session.logger.info("%s's image updated with sucess: %s" %(each.product_id.default_code, each.name))
67 need_to_be_created = False
68 except Exception, e: