File: custom_collection.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 (16 lines) | stat: -rw-r--r-- 547 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from ..base import ShopifyResource
from shopify import mixins
import shopify


class CustomCollection(ShopifyResource, mixins.Metafields, mixins.Events):
    def products(self):
        return shopify.Product.find(collection_id=self.id)

    def add_product(self, product):
        return shopify.Collect.create({"collection_id": self.id, "product_id": product.id})

    def remove_product(self, product):
        collect = shopify.Collect.find_first(collection_id=self.id, product_id=product.id)
        if collect:
            collect.destroy()