Example #1
0
class CategoryModel(Model):
    id = fields.UUIDField(primary_key=True, default=uuid.uuid4)
    parent = fields.ForeignKey("self", null=True, related_name="parentId")
    name = fields.CharField(max_length=255)
    cmsPage = fields.ForeignKey("cms_page.cms_page_model.CmsPageModel",
                                related_name="cmsPageId",
                                null=True)

    class Meta:
        api_endpoint = "category"
        api_type = "category"
Example #2
0
class ProductMediaModel(Model):
    id = fields.UUIDField(primary_key=True,
                          aliases=("coverId", ),
                          default=uuid.uuid4)
    product = fields.ForeignKey("product.product_model.ProductModel",
                                related_name="productId",
                                null=True)
    position = fields.NumberField(null=True)
    media = fields.ForeignKey("media.media_model.MediaModel",
                              related_name="mediaId")

    class Meta:
        api_endpoint = "product-media"
        api_type = "product_media"
Example #3
0
class MediaFolderModel(Model):
    id = fields.UUIDField(primary_key=True,
                          default=uuid.uuid4,
                          aliases=("mediaFolderId"))
    useParentConfiguration = fields.BooleanField(default=True)
    configuration = fields.ForeignKey(
        "media.media_folder_configuration_model.MediaFolderConfigurationModel",
        related_name="configurationId")
    parent = fields.ForeignKey("self", related_name="parentId", null=True)
    name = fields.CharField()

    class Meta:
        api_endpoint = "media-folder"
        api_type = "media_folder"
Example #4
0
class ProductCrossSellingAssignedProductModel(Model):
    id = fields.UUIDField(primary_key=True, default=uuid.uuid4)
    product = fields.ForeignKey("product.product_model.ProductModel", related_name="productId")
    #position = fields.NumberField(null=True)

    class Meta:
        api_endpoint = "product-cross-selling-assigned-products"
        api_type = "product_cross_selling_assigned_products"
Example #5
0
class MediaModel(Model):
    id = fields.UUIDField(primary_key=True, default=uuid.uuid4)
    mediaFolder = fields.ForeignKey(
        "media.media_folder_model.MediaFolderModel")
    fileName = fields.CharField(read_only=True)
    fileExtension = fields.CharField(read_only=True)
    hasFile = fields.BooleanField(default=False)
    position = fields.NumberField(null=True)
    customFields = fields.DictField(null=True)

    class Meta:
        api_endpoint = "media"
        api_type = "media"

    def upload(self, file):
        if not (hasattr(self, "id") and isinstance(self.id, uuid.UUID)):
            raise AttributeError("Missing id attribute")

        if not (hasattr(self, "_meta")
                and hasattr(self._meta, "swapi_client")):
            raise AttributeError("Missing swapi client")

        if not isinstance(file, File):
            raise ValueError(
                "file must be an instance of shopwareapi.api.media.File")
        swapi_client = self._meta.swapi_client

        swapi_client.post(
            url={
                "model": ("_action", "media", self.id.hex, "upload"),
                "extension": file.get_file_extension(),
                "fileName": file.get_filename(),
            },
            data=file.get_binary(),
            headers={"Content-Type": str(file.get_content_type())})
        return file

    def upload_from_path(self, path, **kwargs):
        file_kwargs = {
            "content_type": mimetypes.guess_type(path),
            "path": path
        }
        file_kwargs.update(kwargs)
        with open(path, "rb") as fobj:
            f = File(fobj, **file_kwargs)
        return self.upload(f)

    def upload_from_url(self, url, **kwargs):
        o = urlparse(url)
        image_src = requests.get(o.geturl(), stream=True)
        image_data = io.BytesIO(image_src.content)
        content_type = image_src.headers.get(
            "Content-Type") or mimetypes.guess_type(o.path)

        file_kwargs = {"content_type": content_type, "path": o.path}
        file_kwargs.update(**kwargs)
        f = File(image_data, **file_kwargs)
        return self.upload(f)
Example #6
0
class ProductModel(Model):
    id = fields.UUIDField(primary_key=True, aliases=("productId", ), default=uuid.uuid4)
    name = fields.CharField()
    description = fields.CharField()
    manufacturer = fields.ForeignKey("product.product_manufacturer_model.ProductManufacturerModel", related_name="manufacturerId")
    unit = fields.ForeignKey("unit.Unit")
    tax = fields.ForeignKey("tax.tax_model.TaxModel", related_name="taxId")
    cover = fields.ForeignKey("product.product_media_model.ProductMediaModel", related_name="coverId")

    price = fields.ManyToOneField(ProductPrice)

    visibilities = fields.ListField(schema=fields.DictField(schema={
        "salesChannel": fields.ForeignKey("sales_channel.sales_channel_model.SalesChannelModel", related_name="salesChannelId"),
        "visibility": fields.NumberField(),
    }))

    media = fields.ManyToOneField("product.product_media_model.ProductMediaModel")

    #media = fields.ListField(schema=fields.DictField(schema={
    #    "id": fields.ForeignKey("product.product_media_model.ProductMediaModel", related_name="id"),
    #    "mediaId": fields.ForeignKey("media.media_model.MediaModel", related_name="mediaId"),
    #    "position": fields.NumberField()
    #}))

    categories = fields.ListField(schema=fields.DictField(schema={
        "id": fields.ForeignKey("category.category_model.CategoryModel", related_name="id")
    }))
    tags = fields.ListField(schema=fields.DictField(schema={
        "id": fields.ForeignKey("tag.tag_model.TagModel", related_name="id")
    }))
    productNumber = fields.CharField()
    stock = fields.IntegerField(null=True)
    restockTime = fields.IntegerField(null=True)
    active = fields.BooleanField(default=True)
    ean = fields.CharField()
    purchaseUnit = fields.CharField(null=True)
    packUnit = fields.CharField(null=True)
    purchaseSteps = fields.IntegerField(null=True)
    minPurchase = fields.IntegerField(null=True)
    maxPurchase = fields.IntegerField(null=True)
    weight = fields.NumberField(null=True)
    width = fields.NumberField(null=True)
    height = fields.NumberField(null=True)
    length = fields.NumberField(null=True)
    categoryTree = fields.ListField(schema=fields.CharField(null=False), read_only=True)


    #categoryTree = fields.ManyToOneField("category.category_model.CategoryModel")
    #crossSellings = fields.ListField(schema=fields.ForeignKey("product.product_cross_selling_model.ProductCrossSellingModel"))
    # name
    # description
    # packUnit
    ##- customFields
    # featureSet
    # createdAt
    # updatedAt

    class Meta:
        api_endpoint = "product"
        api_type = "product"
Example #7
0
class ProductCrossSellingModel(Model):
    id = fields.UUIDField(primary_key=True, default=uuid.uuid4)
    name = fields.CharField()
    position = fields.NumberField(null=True)
    type = fields.CharField()  # productList
    active = fields.BooleanField(default=True)
    product = fields.ForeignKey("product.product_model.ProductModel",
                                related_name="productId")
    assignedProducts = fields.ManyToOneField(
        "product.product_cross_selling_assigned_product_model.ProductCrossSellingAssignedProductModel"
    )

    class Meta:
        api_endpoint = "product-cross-selling"
        api_type = "product_cross_selling"
Example #8
0
class ProductPrice(Model):
    gross = fields.NumberField()
    net = fields.NumberField()
    currency = fields.ForeignKey("currency.currency_model.CurrencyModel", related_name="currencyId")
    linked = fields.BooleanField(default=False)