def get_by_key(self, request, key):
     obj = self.model.get_by_key(key)
     if obj:
         expanded_obj = self._expand(request, obj)
         content = schemas.ProductProjectionSchema().dumps(expanded_obj)
         return create_commercetools_response(request, text=content)
     return create_commercetools_response(request, status_code=404)
    def _convert_product_projection(
            self,
            product: typing.Dict,
            staged: bool = False) -> typing.Optional[types.ProductProjection]:
        """Convert a Product object to a ProductProjection object"""
        if product["masterData"] is None:
            return None

        if staged:
            data = product["masterData"]["staged"]
        else:
            data = product["masterData"]["current"]

        if data is None:
            return None

        return schemas.ProductProjectionSchema().load({
            "id":
            product["id"],
            "key":
            product["key"],
            "version":
            product["version"],
            "createdAt":
            product["createdAt"],
            "lastModifiedAt":
            product["lastModifiedAt"],
            "productType":
            product["productType"],
            "name":
            data["name"],
            "description":
            data["description"],
            "slug":
            data["slug"],
            "categories":
            data["categories"],
            "categoryOrderHints":
            data["categoryOrderHints"],
            "metaTitle":
            data["metaTitle"],
            "metaDescription":
            data["metaDescription"],
            "metaKeywords":
            data["metaKeywords"],
            "searchKeywords":
            data["searchKeywords"],
            "hasStagedChanges":
            product["masterData"]["hasStagedChanges"],
            "published":
            product["masterData"]["published"],
            "masterVariant":
            data["masterVariant"],
            "variants":
            data["variants"],
            "taxCategory":
            product["taxCategory"],
            "state":
            product["state"],
            "reviewRatingStatistics":
            product["reviewRatingStatistics"],
        })
 def get_by_key(self, request, key):
     obj = self.model.get_by_key(key)
     if obj:
         content = schemas.ProductProjectionSchema().dumps(obj)
         return create_response(request, text=content)
     return create_response(request, status_code=404)