def notify_user_order_collected(order_id): order = Order.objects.get(id=order_id) site = get_site_for_order(order) send_sms( order.phone, "Заказ №%s собран и ожидает оплаты. Перейдите по ссылке, чтобы оплатить заказ: https://%s%s" % (order_id, site.domain, reverse('shop:order', args=[order_id]))) if order.email: if not validate_email(order.email): return reload_maybe() context = { 'site': site, 'site_profile': SiteProfile.objects.get(site=site), 'owner_info': getattr(settings, 'SHOP_OWNER_INFO', {}), 'order': order } msg_plain = render_to_string('mail/shop/order_collected.txt', context) msg_html = render_to_string('mail/shop/order_collected.html', context) return send_mail( 'Оплата заказа №%s' % order_id, msg_plain, config.sw_email_from, [order.email], html_message=msg_html, )
def notify_user_order_delivered(order_id): order = Order.objects.get(id=order_id) if order.delivery == Order.DELIVERY_PICKPOINT: title = 'PickPoint' else: title = 'ТК' send_sms( order.phone, "Заказ №%s доставлен в %s: %s" % (order_id, title, order.delivery_info)) if order.email: if not validate_email(order.email): return site = get_site_for_order(order) reload_maybe() context = { 'site': site, 'site_profile': SiteProfile.objects.get(site=site), 'owner_info': getattr(settings, 'SHOP_OWNER_INFO', {}), 'order': order } msg_plain = render_to_string('mail/shop/order_delivered.txt', context) msg_html = render_to_string('mail/shop/order_delivered.html', context) return send_mail( 'Получение заказа №%s' % order_id, msg_plain, config.sw_email_from, [order.email], html_message=msg_html, )
def notify_user_order_delivered_shop(order_id): order = Order.objects.get(id=order_id) city = order.store.city.name address = order.store.address name = order.store.name send_sms( order.phone, "Ваш заказ доставлен в магазин \"%s\" по адресу %s, %s." " Для получения заказа обратитесь в кассу и назовите номер" " заказа %s." % (name, city, address, order_id))
def notify_user_order_new_sms(order_id, password=None): order = Order.objects.get(id=order_id) site = get_site_for_order(order) password_text = "" if password: password_text = " Пароль: %s" % password return send_sms( order.phone, "Состояние заказа №%s можно узнать в личном кабинете: https://%s%s %s" % (order_id, site.domain, reverse('shop:user_orders'), password_text))
def notify_expiring_bonus(self, phone): user = ShopUser.objects.get(phone=phone) today = datetime.today() base_format = SINGLE_DATE_FORMAT if today.year == user.expiration_date.year else SINGLE_DATE_FORMAT_WITH_YEAR text = "%d ваших %s действуют до %s. В Швейном Мире вы можете оплатить бонусами до 20%% от стоимости покупки! https://%s" % ( user.expiring_bonuses, rupluralize(user.expiring_bonuses, "бонус,бонуса,бонусов"), date_format(user.expiration_date, format=base_format), sw_default_site.domain) result = send_sms(user.phone, text) try: return result['descr'] except Exception: return result
def notify_abandoned_basket(self, basket_id, email, phone): basket = Basket.objects.get(id=basket_id) reload_maybe() owner_info = getattr(settings, 'SHOP_OWNER_INFO', {}) signer = signing.Signer() restore_url = 'https://{}{}'.format( sw_default_site.domain, reverse('shop:restore', args=[ ','.join( map(lambda i: '%s*%s' % (i.product.id, i.quantity), basket.items.all())) ])) clear_url = 'https://{}{}'.format( sw_default_site.domain, reverse('shop:clear', args=[signer.sign(basket.id)])) unisender = Unisender(api_key=settings.UNISENDER_KEY) if email: context = { 'owner_info': owner_info, 'basket': basket, 'restore_url': restore_url, 'clear_url': clear_url } result = unisender.sendEmail( email, owner_info.get('short_name', ''), config.sw_email_unisender, 'Вы забыли оформить заказ', render_to_string('mail/shop/basket_abandoned.html', context), settings.UNISENDER_ABANDONED_BASKET_LIST) # https://www.unisender.com/ru/support/api/common/api-errors/ if unisender.errorMessage: if unisender.errorCode in [ 'retry_later', 'api_call_limit_exceeded_for_api_key', 'api_call_limit_exceeded_for_ip' ]: raise self.retry(countdown=60 * 60 * 2, max_retries=5, exc=Exception( unisender.errorMessage)) # 2 hours if unisender.errorCode == 'not_enough_money': raise self.retry(countdown=60 * 60 * 24, max_retries=5, exc=Exception( unisender.errorMessage)) # 24 hours return unisender.errorMessage # recipient errors for r in result['result']: if 'index' in r and r['index'] == 0: if 'errors' in r: try: return r['errors'][0]['message'] except Exception: return str(r['errors']) else: return r['id'] elif phone: result = send_sms(phone, "Вы забыли оформить заказ: %s" % restore_url) try: return result['descr'] except Exception: return result
def notify_manager_sms(order_id, phone): return send_sms(phone, "Новый заказ №%s" % order_id)
def send_password(phone, password): return send_sms(phone, "Пароль для доступа на сайт: %s" % password)
def send_message(phone, message): return send_sms(phone, message)