Merge branch 'ticket-25' into 'master'
fixes ticket #25 bundle products are working and safer now! See merge request engineering/make-post-sell/make_post_sell!26
This commit is contained in:
commit
bbd1ec3608
2 changed files with 28 additions and 3 deletions
|
|
@ -403,8 +403,17 @@ class Product(RBase, Base):
|
|||
def add_product_to_bundle(self, product):
|
||||
if self.is_bundle == False:
|
||||
self.error_message = "This product is not a bundle."
|
||||
if self.shop_id != product.shop_id:
|
||||
elif self.shop_id != product.shop_id:
|
||||
self.error_message = "The product and bundle must share the same shop."
|
||||
elif product.is_physical or self.is_physical:
|
||||
self.error_message = (
|
||||
f"Refusing to bundle {product.title}, it is a physical item."
|
||||
)
|
||||
elif product in self.products_in_this_bundle:
|
||||
self.error_message = (
|
||||
f"Refusing to bundle {product.title}, it is already in the bundle."
|
||||
)
|
||||
|
||||
if self.error_message:
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -258,7 +258,9 @@ def product_edit(request):
|
|||
if file_size == 0:
|
||||
raise ValueError("File size is zero")
|
||||
except Exception:
|
||||
request.session.flash(("File upload failed. Pick a file and try again.", "error"))
|
||||
request.session.flash(
|
||||
("File upload failed. Pick a file and try again.", "error")
|
||||
)
|
||||
return HTTPFound(request.route_url("product_edit", product_id=product.id))
|
||||
|
||||
# Store the uploaded user's file_metadata in our database.
|
||||
|
|
@ -445,11 +447,25 @@ def product_bundle_edit(request):
|
|||
products = get_products_by_ids(
|
||||
request.dbsession, UUID_ALL_PATTERN.findall(bundle_data)
|
||||
)
|
||||
|
||||
if products is None:
|
||||
request.session.flash(
|
||||
("We didn't detect any product ids. Try again.", "error")
|
||||
)
|
||||
return HTTPFound(get_referer_or_home(request))
|
||||
|
||||
for product_to_bundle in products:
|
||||
if not product.add_product_to_bundle(product_to_bundle):
|
||||
request.session.flash((product.error_message, "error"))
|
||||
product.error_message = None
|
||||
continue
|
||||
request.session.flash(("You added a product to this bundle!", "success"))
|
||||
|
||||
request.session.flash(
|
||||
(
|
||||
f"You added product {product_to_bundle.title} to this bundle!",
|
||||
"success",
|
||||
)
|
||||
)
|
||||
|
||||
return HTTPFound(get_referer_or_home(request))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue