Skip to content

Commit

Permalink
Overwriting content-type in case of new product
Browse files Browse the repository at this point in the history
  • Loading branch information
bakeable committed Jul 22, 2024
1 parent 27ab88a commit 76c2ab7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions akeneo_connector/akeneo_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get(self, url: str):

return data

def update(self, url: str, payload: list | dict):
def update(self, url: str, payload: list | dict, is_new: bool = False):
"""
Updates an item in Akeneo.
Expand All @@ -136,9 +136,13 @@ def update(self, url: str, payload: list | dict):
# Join the JSON-strings into a single string
data_str = "\n".join(batch_strings)

# Create headers
headers = self.headers.copy()
headers['Content-Type'] = 'application/vnd.akeneo.collection+json' if not is_new else 'application/json'

# Set the payload to the joined JSON-strings
print(f"PATCH {url}")
response = req.patch(url, headers=self.headers, data=data_str)
response = req.patch(url, headers=headers, data=data_str)

# Check if the request was successful
if response.status_code < 200 or response.status_code >= 300:
Expand Down
6 changes: 3 additions & 3 deletions akeneo_connector/akeneo_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def get(self, identifier: str | None = None, with_attribute_options: bool = Fals

return None

def update(self):
def update(self, is_new = False):
"""
Updates the product.
Expand All @@ -368,7 +368,7 @@ def update(self):
url = self.connector.product_url.format(identifier=self.identifier)

# Update the product
return self.connector.update(url, self.payload())
return self.connector.update(url, self.payload(), is_new=is_new)

def create(self):
"""
Expand All @@ -378,7 +378,7 @@ def create(self):
bool: JSON response if successful, None otherwise.
"""
# Update is same
return self.update()
return self.update(is_new=True)

def get_media(self, media_attribute: str, locale: str | None = None, scope: str | None = None):
"""
Expand Down

0 comments on commit 76c2ab7

Please sign in to comment.