def paypal_success(request): """ Copied over from cartridge.shop.models.Order.complete. Avoiding to copy the code would result in an unnecessary hassle of creating an Order object which is not required with Paypal. """ session_fields = ("shipping_type", "shipping_total", "discount_total", "discount_code", "tax_type", "tax_total") items = [] if request.session.get('cart'): for item in request.cart.items.all(): items.append({ 'image': item.image, 'title': item.description, 'get_absolute_url': item.get_absolute_url() }) discount_code = request.session.get('discount_code') clear_session(request, "order", *session_fields) for item in request.cart: try: variation = ProductVariation.objects.get(sku=item.sku) except ProductVariation.DoesNotExist: pass else: variation.update_stock(item.quantity * -1) variation.product.actions.purchased() if discount_code: DiscountCode.objects.active().filter(code=discount_code).update( uses_remaining=models.F('uses_remaining') - 1) request.cart.delete() del request.session['cart'] else: raise PermissionDenied return render(request, "shop/paypal_complete.html", {'items': items})
def set_discount(self): """ Assigns the session variables for the discount. """ discounts = getattr(self, "_discount", None) # member_discount = getattr(self, "member_discount", None) if discounts is not None: total = Decimal("0") names = ("free_shipping", "discount_codes", "discount_total") clear_session(self._request, *names) for discount in discounts: # Clear out any previously defined discount code # session vars. total += self._request.cart.calculate_discount(discount) if discount.free_shipping: set_shipping(self._request, _("Free shipping"), 0) self._request.session["free_shipping"] = discount.free_shipping else: # A previously entered discount code providing free # shipping may have been entered prior to this # discount code beign entered, so clear out any # previously set shipping vars. clear_session(self._request, "shipping_type", "shipping_total") self._request.session["discount_codes"] = discount.code self._request.session["discount_total"] = str(total)
def billship_handler(request, order_form): cart = request.cart shipping, q = cart.cart_get_shipping() if shipping: if q == 1: set_shipping(request, "Shipping", 60.00) else: set_shipping(request, "Shipping", (60.00 + ((q - 1) * 10))) else: clear_session(request, "shipping_type", "shipping_total")
def complete(self, request): """ Remove order fields that are stored in the session, reduce the stock level for the items in the order, decrement the uses remaining count for discount code (if applicable) and then delete the cart. """ self.save() # Save the transaction ID. discount_code = request.session.get('discount_code') clear_session(request, "order", *self.session_fields) for item in request.cart: try: variation = ProductVariation.objects.get(sku=item.sku) except ProductVariation.DoesNotExist: pass else: if variation.product.content_model == 'reservableproduct': reservableproduct = ReservableProduct.objects.get( product_ptr=variation.product.id) # we also create a reservable order reservation for date in utils.daterange(item.from_date, item.to_date): reservation = ReservableProductReservation.objects.get( date=date, product=reservableproduct) if reservation: reservation_order = ReservableProductOrderReservation( order=self, reservation=reservation) reservation_order.save() else: variation.update_stock(item.quantity * -1) variation.product.actions.purchased() # create reservations in external hook for reservable products (if any) if self.has_reservables: for item in self.items.all(): try: variation = ProductVariation.objects.get(sku=item.sku) except ProductVariation.DoesNotExist: pass else: if variation.product.content_model == 'reservableproduct': # create reservation via hook (if any) # external_order_id = reservableproduct.reserve_via_hook(item.from_date, item.to_date, self.id) external_order_id = -1 if external_order_id == -1 or not external_order_id: # External hook reported an error # TODO: send extra notice to shop admins to process this manually pass item.external_order_id = external_order_id item.save() if discount_code: DiscountCode.objects.active().filter(code=discount_code).update( uses_remaining=models.F('uses_remaining') - 1) request.cart.delete()
def set_discount(self): """ Assigns the session variables for the discount. """ discount = getattr(self, "_discount", None) if discount is not None: # Clear out any previously defined discount code # session vars. names = ("free_shipping", "discount_code", "discount_total") clear_session(self._request, *names) total = self._request.cart.calculate_discount(discount) if discount.free_shipping: set_shipping(self._request, _("Free shipping"), 0) else: # A previously entered discount code providing free # shipping may have been entered prior to this # discount code beign entered, so clear out any # previously set shipping vars. clear_session(self._request, "shipping_type", "shipping_total") self._request.session["free_shipping"] = discount.free_shipping self._request.session["discount_code"] = discount.code self._request.session["discount_total"] = str(total)
def complete(self, request): """ Remove order fields that are stored in the session, reduce the stock level for the items in the order, decrement the uses remaining count for discount code (if applicable) and then delete the cart. """ self.save() # Save the transaction ID. discount_code = request.session.get('discount_code') clear_session(request, "order", *self.session_fields) for item in request.cart: try: variation = ProductVariation.objects.get(sku=item.sku) except ProductVariation.DoesNotExist: pass else: variation.update_stock(item.quantity * -1) variation.product.actions.purchased() if discount_code: DiscountCode.objects.active().filter(code=discount_code).update( uses_remaining=models.F('uses_remaining') - 1) request.cart.delete()
def set_discount(self): """ Assigns the session variables for the discount. """ discount = getattr(self, "_discount", None) if discount is not None: # Clear out any previously defined discount code # session vars. names = ("free_shipping", "discount_code", "discount_total") clear_session(self._request, *names) total = self._request.cart.calculate_discount(discount) if discount.free_shipping: set_shipping(self._request, _("Free shipping"), 0) else: # A previously entered discount code providing free # shipping may have been entered prior to this # discount code beign entered, so clear out any # previously set shipping vars. clear_session(self._request, "shipping_type", "shipping_total") self._request.session["free_shipping"] = discount.free_shipping self._request.session["discount_code"] = discount.code #change by wni, change number to minus for display on page #self._request.session["discount_total"] = str(total) self._request.session["discount_total"] = str(total)