File: variant.py

package info (click to toggle)
python-shopifyapi 12.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: python: 1,752; sh: 10; makefile: 9
file content (28 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from ..base import ShopifyResource
from shopify import mixins


class Variant(ShopifyResource, mixins.Metafields):
    _prefix_source = "/products/$product_id/"

    @classmethod
    def _prefix(cls, options={}):
        product_id = options.get("product_id")
        if product_id:
            return "%s/products/%s" % (cls.site, product_id)
        else:
            return cls.site

    def save(self):
        if "product_id" not in self._prefix_options:
            self._prefix_options["product_id"] = self.product_id

        start_api_version = "201910"
        api_version = ShopifyResource.version
        if api_version and (api_version.strip("-") >= start_api_version) and api_version != "unstable":
            if "inventory_quantity" in self.attributes:
                del self.attributes["inventory_quantity"]
            if "old_inventory_quantity" in self.attributes:
                del self.attributes["old_inventory_quantity"]

        return super(ShopifyResource, self).save()