Skip to content

Commit

Permalink
[IMP] oxigen_connector_woocommerce_wpml_acf: add video gallery field
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC013 committed Oct 23, 2024
1 parent 5edbd3e commit 4314512
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
class WooCommerceWPMLProductTemplateAdapter(Component):
_inherit = "woocommerce.product.template.adapter"

def prepare_meta_data(self, data):
video_gallery_fields = [k for k in data.keys() if k.startswith("video_gallery")]
if video_gallery_fields:
self.env.context = {"video_gallery_fields": video_gallery_fields}
return super(WooCommerceWPMLProductTemplateAdapter, self).prepare_meta_data(
data
)

def _prepare_meta_data_fields(self):
meta_data_fields = super()._prepare_meta_data_fields()
meta_data_fields.extend(["additional_information"])
video_gallery_fields = self.env.context.get("video_gallery_fields", {})
if video_gallery_fields:
meta_data_fields.extend(video_gallery_fields)
return meta_data_fields
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ def additional_information(self, record):
if technical_features:
additional_information.append(technical_features)
return {"additional_information": "\n".join(additional_information) or None}

def _get_video_gallery_data(self, record):
data = {}
for i, video in enumerate(record.product_template_image_ids):
data[f"video_gallery_{i}_video"] = video.video_url or ""
data[f"video_gallery_{i}_video_description"] = video.title or ""
return data

@mapping
def video_gallery(self, record):
len_videos = len(record.product_template_image_ids)
if len_videos == 0:
return {"video_gallery": "0"}

video_gallery_data = self._get_video_gallery_data(record)
video_gallery_data["video_gallery"] = str(len_videos)
return video_gallery_data

0 comments on commit 4314512

Please sign in to comment.