Ejemplo n.º 1
0
 def setVariationStock(self, stock, variation):
     """ Set the number of items available of a variation or combination
         of multiple variations
     """
     if IVariation.providedBy(variation):
         key = variation.UID()
     else:
         key = self._sorted_variation_key([IVariation.providedBy(v) and v.UID() or v for v in variation])
     self.storage[key] = stock
Ejemplo n.º 2
0
 def variationStock(self, variation):
     """ Number of items available of a variation or combination
         of multiple variations
     """
     if IVariation.providedBy(variation):
         stock = 0
         key = variation.UID()
         for k, v in self.storage.items():
             if key in self._get_uids_from_key(k):
                 stock += v
         return stock
     else:
         key = self._sorted_variation_key([IVariation.providedBy(v) and v.UID() or v for v in variation])
         return self.storage.get(key, 0)
Ejemplo n.º 3
0
 def stockable(self, KEY=False):
     """ Returns a list of the stockable variation combinations of a product
     """
     variations = {}
     ids = self.context.objectIds()
     if not KEY:
         variations_by_uid = {}
     for id in ids:
         obj = self.context._getOb(id)
         if not IVariation.providedBy(obj):
             continue
         type = obj.getType()
         if not variations.has_key(type):
             variations[type] = []
         uid = obj.UID()
         if not KEY:
             variations_by_uid[uid] = obj
         variations[type].append(uid)
     if len(variations.keys()) > 1: # multiple variation types (creating cartesian product)
         comp = product(*variations.values())
         if KEY:
             return [self._sorted_variation_key(keys) for keys in comp]
         return [[variations_by_uid[uid] for uid in keys] for keys in comp]
     elif len(variations.keys()) == 1: # one variation type
         if KEY:
             return variations.values()[0]
         return [[variations_by_uid[uid],] for uid in variations.values()[0]]
     else: # no variations at all
         return None
Ejemplo n.º 4
0
    def price(self):
        import logging
        v_uid = None
        product = aq_inner(self.context)
        if IVariation.providedBy(product):
            product = aq_parent(product)
            v_uid = self.context.UID()
        
        v_uids = self.request.get('v', '')
        v_uids = v_uids.split(',')
        v_uids = [uid for uid in v_uids if uid != '']
        if not len(v_uids) and v_uid is not None:
            v_uids = [v_uid,]
        
        catalog = getToolByName(self.context, 'uid_catalog')
        variations = catalog(object_provides=IVariation.__identifier__, UID=v_uids)
        variations = [variation.getObject() for variation in variations]
        
        price = IPricing(product).getPrice(variations)

        return CurrencyAware(price)
Ejemplo n.º 5
0
    def price(self):
        import logging
        v_uid = None
        product = aq_inner(self.context)
        if IVariation.providedBy(product):
            product = aq_parent(product)
            v_uid = self.context.UID()

        v_uids = self.request.get('v', '')
        v_uids = v_uids.split(',')
        v_uids = [uid for uid in v_uids if uid != '']
        if not len(v_uids) and v_uid is not None:
            v_uids = [
                v_uid,
            ]

        catalog = getToolByName(self.context, 'uid_catalog')
        variations = catalog(object_provides=IVariation.__identifier__,
                             UID=v_uids)
        variations = [variation.getObject() for variation in variations]

        price = IPricing(product).getPrice(variations)

        return CurrencyAware(price)
Ejemplo n.º 6
0
 def title(self):
     if IVariation.providedBy(self.context):
         return '%s (%s: %s)' % (self.product.Title().decode('utf-8'), self.context.getType().decode('utf-8'), self.context.Title().decode('utf-8'))
     return self.context.Title()
Ejemplo n.º 7
0
 def base_price(self):
     if IVariation.providedBy(self.context):
         return CurrencyAware(IPricing(self.product).getBasePrice([aq_inner(self.context),]))
     return CurrencyAware(IPricing(self.product).getBasePrice())
Ejemplo n.º 8
0
 def product(self):
     context = aq_inner(self.context)
     if IVariation.providedBy(context):
         return aq_parent(context)
     return self.context