diff --git a/rattail/config.py b/rattail/config.py index 34ce028aab0ddd1d5d31c6066b90d3170c8d0694..1888ad0da903eac690c3d6fbf1817b6d5c75c762 100644 --- a/rattail/config.py +++ b/rattail/config.py @@ -580,6 +580,10 @@ class RattailConfig(object): """ Returns the title string to be used when displaying product key field, e.g. "UPC" or "Part No." etc. + + :param key: The product key for which to return a label. This + is optional; if not specified then :meth:`product_key()` + will be called to determine the key. """ title = self.get('rattail', 'product.key_title') if title: diff --git a/rattail/products.py b/rattail/products.py index e74709ef3af938372b1746baae27e0794cf26870..5c3de3ed660b56e9d2ef871f8dab5ccc024c8ba6 100644 --- a/rattail/products.py +++ b/rattail/products.py @@ -184,17 +184,29 @@ class ProductsHandler(GenericHandler): """ Return the preferred image URL for the given UPC or product. """ + base_url = self.config.base_url() + # we prefer the "image on file" if available - if product and product.image: - url = self.config.base_url() - if url: - return '{}/products/{}/image'.format(url, product.uuid) - - # fallback to the POD image, if available - if product and not upc: - upc = product.upc - if upc: - return self.get_pod_image_url(upc) + if base_url and product and product.image: + return '{}/products/{}/image'.format(base_url, product.uuid) + + # and if this product is a pack item, then we prefer the unit + # item image as fallback, if available + if base_url and product and product.is_pack_item(): + unit = product.unit + if unit and unit.image: + return '{}/products/{}/image'.format(base_url, unit.uuid) + + # fallback to the POD image, if available and so configured + if self.config.getbool('tailbone', 'products.show_pod_image', + default=False): + if product and not upc: + upc = product.upc + if upc: + return self.get_pod_image_url(upc) + + if base_url: + return '{}/tailbone/img/product.png'.format(base_url) def get_pod_image_url(self, upc, **kwargs): """